My best logical game in Ruby so far

Last week was about keeping my “work – study – life” balance at risk. Nevertheless I have reached y goals. After I finished my last post a week ago, I went to DublinJS meetup, that was Tuesday. My goal was to meet some people, practice my socializing skills and … learn something new. There must have been over 100 people, 15 speakers, each of them giving a short talk for about 5 minutes – mainly about JavaScript. I will be honest here – there was a lot of stuff I didn’t understand… (I was possibly the only Ruby guy there). Some of the topics were: TypeScript, 3rd Party JS, Phaser.io, Web Scrapping, iframes, SVG Animation, feedback.js – the last two are the one I will add to my set of tools (more details here).

On the good side is that I met few people, some of whom, where in a very similar situation at the beginning of their road about a year ago. This was very uplifting to hear. Some of the further stages of their web dev road (where mastering socializing is first) was being one of the speakers that night. One of them that I met, wasn’t sure about the high level of her talk but was proud she got a courage to do it in front of the crowd. So overall, different people, on different learning stages with their very own challenges. Believe me, having identification with them makes more comfortable to be within this unfamiliar group (in a way). Having spoke about my situation and asking questions like “how did you start, what was your road” – trigger people to share more about them. This helps crumble the wall between me as the newcomer and the rest of the group (experienced perhaps). That day, I got home late – didn’t do much for the Viking course.

In the week, I have finished my Ruby warm up challenges. The project was to create small programs solving each of a given seven problems. The image below shows the outcome of one of them: a simple graph of occurrences of outcomes when rolling six dice about 100 times (i.e.,. 18 was a score in two rolls and 20 appeared four times). My repository.

screen-shot-2016-09-12-at-19-01-57

The other were to check what are the anagrams of the given word (at the moment my solution consists of a dictionary of few words as I haven’t implemented file input at this stage). Another interesting problem was to find two days in an array of values, which are indicating the greatest profit ( the difference between two values) – very useful to some “tape reading” activities (especially when looking at stock charts is providing too much information).

Screen Shot 2016-09-12 at 21.58.59.png

The above solution, I admit, is not the most efficient. This is to my records that at this day I can create this type of code. I believe I will get better and will be able to come back here and publish a better one in the near future! My goal is now to push as much as I can for the next two-three weeks before college starts. At this stage my code is tested with various edge scenarios and answeres exactly the question set in the challenge. However, if you have any suggestions – please DO write in the comments. I appreciate any way to learn more.

 

One of the new skills I’m working on is debugging. I was playing with the above code and puts “DBG: value_max = #{value_max.inspect}” in the middle of it – I used it to unbug the the program as it wasn’t working straightaway the way I wanted.

Another element binding.pry – belongs to Ruby debugger and Jim Wirich gave an excellent introduction to it. One of the things I owe to Jim also is this lovely Sublime snippet:

screen-shot-2016-09-12-at-22-19-06

after typing “dbg” and clicking tab, display on the screen DBG: value_max = #{value_max.inspect}” which I can instanly fill out with the variable I want to monitor.  Pry on the other hand is allowing to follow every frame of the working program and see what is going on up to the final result is given. It really helps a lot.

My great project this week is the game Tower of Hanoi. We have three rods and one of them is filled with disks (we can decide how many discs we want to use, so the more of them the more dififcult the game). I am happy I managed to create the whole program and provide output to the user in the grahical form. The example of that is presented below and in my github respository. This code is in a procedural style; classes are soon to come.

screen-shot-2016-09-12-at-23-12-11

I am learning now RSpec basics and already have a bunch of challenges to solve. This is hands on Test Driven Development. After that, I head to Object Oriented Programming.

My further road will be accompanied by this baby here (whenever I find time):

dsc_0645_crop_509x718

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s