Aaron's Page

This is where I post about what I'm working on.

--- Day 5: Hydrothermal Venture ---

or..

I've only watched episode one of Squid Game, no spoilers please...

one art please

Part 1

Python

I did this in the slowest way possible, using a list to store all of the coords as tuples that are generate by every vertical or horizontal line, then I created a set from that and every time a count of the list of coords of a value from the set was greater than one, I incremented my counter to produce the result.

Admittedly, I got tripped up with my greater than less than comparisons because I was comparing string representations of ints rather than ints, which produces improper results for the desired use case, as can be seen below:

>>> 10 > 2
True
>>> "10" > "2"
False
>>>

Once I corrected this error, and allowed for 350 seconds for my code to run, I got the right answer. When I do this in go, I'll use my lessons from part 2 to make it work properly.

Go

Finally completed this part on day 8 after helping my friend John try to work through his c# problems for this one. I am now getting just a little bit more accustomed to writing my own functions for things that would be trivial in python. This one also got me more comfortable working in nested maps.

Part 2

Python

Initially, I tried writing this the same was a part 1 so I could beat a friend on a private leaderboard, but I kept hitting memory errors, which I assumed was due to how I was storing coords in a giant list. This was incorrect.

I was only handling diagonals with increasing slopes...which meant that some of my while loops I was using to calculate those would never end. Oopsie.

The memory error did prompt me to refactor the way I was handling the coods into a dict of form:

d = { '0' : {
              '0' : 0,
              '1' : 0
            },
      '1' : {
              '0' : 0
            }
    }

I saw an example of someone pre-populating the keys with all values 0-1000, but I didn't care for that so I dynamically allocated the keys by looking for them first before writing them.

Go

I completed this using all of my logic from P1 and just adding in a function to check diagonals. Pretty straight forward with the lessons learned from my Python P2.

<< - Table of Contents - >>