Dusting Off Your Programming Fingers [Day 1]

,

What an obscure title. Well yeah, I didn’t really know what to call this project and that seemed the best suited in my opinion. Anyway, it’s been a while. When was the last post? Given I don’t really know, it shows how long it’s been since I legit sat and programmed and thought of a problem. That time off brought with its insecurity, and lack of confidence in my abilities, but someone kept telling me confidence is built with practice so lets practice! So for the next 30 days, I’ll take on a programming challenge. The point isn’t to provide the best solution but to think, analyze and try.

I started off with codewars [ a great site to practice programming challenges] Here’s a snapshot of the challenge

 

Okay, what needs to be done is:

  1. Get the date
  2. re-structure it [model it in a better way than a string]
  3. check it’s existence (if so)
    1. calculate the mean and variance
  4. Otherwise, return -1

Okay, doable. So I really didn’t like the way the data is modeled I chose to reformat it into an object, in my opinion, it seemed as a better way to generate or rather check if a town exists or not. And boy, I didn’t know it would take a while to figure it out and make the structure work. So Let’s start at the beginning. Let’s look at how the data look like shall we

Alright, so what do we know?

  • Each town is separated by an escape character “\n”
  • What separates a town from its data is a colon “:”
  • The rain data is recorded by months which in turn are separated by commas “,”
  • The rain data is written in “month number” so I want the number and it’s separated by a space ” “

Okay, awesome! [Side note: kudos Athoug that you’re thinking of the problem before just jumping to it *pat on the back*] So lets get to it! I know I’ll be slicing up this string quite a lot so here was my process:

1- Separate based on each town data “/n”

2- Separate based on town and rain data “:” Store town and the data. And then extract the rain data “,”

yay so we’re slowly structuring are data more neatly (again that’s my opinion) now, I want the numbers and I want them as floats. So space, and convert the data type aaaaaaand

woohoo [note did you notice a mistake? I didn’t at the time… moving on] So with all the data in hand lets get building that object!

well, you look at that pretty object we have. [totally aware that this might not be necessary but I’m starting to understand how the way your data is modeled really affects everything] okay so we’re done with point 1, and 2. it’s time to get with the logic and calculation. But before that let us check if the structured data works shall we.

Awesome it looks good so back to the logic [always test remember incremental development],  okay let us check if the town exists or not

Okay, awesome logic checked, we now do the math part! and…

 

Pretty proud of myself at this moment! it’s time to put this to the test and submit it to codewars!

 

 

Ummmm :'(

With just a click of a button that proud moment vanished. Okay, what’s going on? I looked it over and couldn’t really tell so I started reading the discussion on this form and this comment stood out

 

Oh! so it’s not only about if the town exists but also that the data points need to include all 12 months. okay, simple fix! [another side note: the wording in this kata was quite confusing] so let’s add that logical test and all should be smooth sailing right?

 

[cries in the corner] but why? what is going on? let us look at the data one more time! I’ll check if maybe their’s something iffy about my math. So I’ll compare what I got with a stat calculator and

Oh… so I wasn’t taking in all the data! makes sense my loop was missing a condition. [The power of debugging] alright let’s fix that and now it should work. SO lets test out one more time on codewars

 

… sigh, I made sure the math is right and when testing the data on my computer it works and returns the same test code in the challenge. I read through the thread and it seems I’m not the only one with the -1 issue. I thought about it, should I keep trying to pass it or just move on. The example wording is not that clear so if you ever encounter this kata and you happen to pass the test cases give me a hint 🙂

But this isn’t a bad start so let us keep this going, and build confidence athoug!

Happy coding to you all.

 

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *