Our first lecture of the day was on debugging in ruby and some general thoughts around the process: from looking at the existing tests and adding additional ones, to puts’ing variables and using the ‘debugger’ gem.
The first challenge was ‘ruby racer’, which is basically a ruby implementation of this:
My pair and I started to implemented a ‘game’ array of ‘player’ arrays, which would allow each player object to move across the array representing their position on the track. However, we soon realised that we were overcomplicating things and it would make much more sense to just have a hash, with a key value pair of player:position. As an extension to the challenge, we added land mines which reset the player to the beginning when they land on them.
The second challenge of the morning was much simpler: we were given a bank account class and had to appropriately hide information using relevant accessors methods (e.g. allowing the class internals to access a full account number, but external calls returning a masked account number).
The afternoon lecture was on recursion – this was a great presentation that explained the core concepts in a way that was understandable, relatable, and pretty captivating.
After the lecture we continued on with the afternoon challenges, the first of which was to implement a ‘Boggle Board’ that contained lettered dice that would shuffle around the board when a ‘shake’ method was called. The second part of this challenge was much harder: we had to implement a method which would take a word and return true if the word was on the board according to the rules of Boggle, i.e.
- Word is >= 3 letters
- Letters must be adjacent on board (up, down, left, right)
- Can’t use the same letter twice
My pair and I spent a long time brainstorming different ways to tackle this, including depth-first search and tracked pathing around the board. In the end, I was able to implement a recursive method that would break down the word and search for letters on the board, building a ‘path’ array of checked coordinates, using that to ensure that the same letter wasn’t used twice and that subsequent letters neighbored previous ones. While my solution probably wasn’t the optimal one, I was very happy with the result and felt that I learned a lot about recursion.