Questions corresponding to the script can be found here: Advent of Code 2019
Recursion does the trick.
intList = list(map(int, stringList))
to convert a list of string to list of int.- recursion does the trick again.
- Another thing to note is using
copy.deepcopy()
to create a copy of a list (reference type)2019/12/03 UPDATE
: duplicating list can also be done byl2 = l1[:]
There might be a better data structure for the paths - I chose to record every point that it crossed. The data size is not that big so performance was ok. I did encounter performance issue trying to find the common coordinates of the two paths. At first, I was using:
listOfCross = []
for point in firstCoordinates:
if point in secondCoordinates:
listOfCross.append(point)
It was slow. A bit of research and I found this thread on StackOverflow
listOfCross = list(set(firstCoordinates).intersection(secondCoordinates))
Neat.
Jonathan Paulson’s solution is really elegant.
This one was pretty straight-forward. Most of time was spent on understand the requirement of part 2.
Could have read in the number as string to get the digits.