Dev Bootcamp: Phase 1, Week 1, Day 7

I decided to have a day away from the DBC office today, but I still managed to get a fair amount done. I’ve been receiving emails from Heroku about too many rows in my LazyCexio rails database, so I started by clearing out any logging data over a month old.

I went back over my sudoku solver and was able to improve performance by around 300% by converting the 2D array to store FixNums rather than Strings, and getting a row from the 2D array by looping through each row, rather than transposing the array then getting accessing it. From this:

1
2
3
def is_in_column?(column,number)
  @board.transpose[column].include?(number)
end

To this:

1
2
3
4
def is_in_column?(column,number)
  @board.each { |row| return true if row[column] == number}
  false
end

The former is a lot cleaner, but for this challenge I’m just interested in raw speed.

Aside from reading a bit of POODR, my other challenge for myself was to review and refactor someone else’s code from a challenge from the week. I took it upon myself to go over another solution to Sudoku solver, which I found incredibly useful – it was great practice to dive into unknown code and try to make enough sense of it to be able to add to it or improve it in some way.

Leave a Reply

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

*