Day 9
Today was nice! Mr. Gwilt was rather fast though...
Part 1 was another relatively simple challenge. The long if statement line is a favourite of mine to check if a specific neighbouring coordinate is actually valid! The main issue I had for part 1 was keeping track of the number of neighbouring cells that were below/above the cell in question (some cells had 2 neighbours whlist others had 4, for example). A simple fix would be to just assume it's True until it isn't! That is essentially what I did with l.
Part 2 was a little tougher. I thought of a BFS or DFS approach, but spent too much time worrying which would be better! I thought DFS would run faster because it's more memory efficient and the input was somewhat large. However, I settled with the BFS because I was faster at coding them - it ended up with an arguably faster runtime as well. The idea was that a '9' represents a boundary between different basins (this was the crucial thing to spot today), so going through each coordinate in the input meant I could expand out to find when I had reached a boundary, and hence work out the size of each basin and keep a list of it. From there, I sorted it to easily grab the largest three sizes. I quite like these grid type questions!
Today was great practice for BIO tomorrow though :D