-
were you saying my function was very C-like?
i've actually just re-written it and it's almost bang on the same as yours with enumerate - had seen a few people talking about that so tried to get that working. still not entirely sure what the :: does in grid[::d], apart from take every d'th y.
my function:
def findTrees2(funcdata, dx, dy): numTrees = 0 for i, line in enumerate(funcdata[::dy]): if line[(i*dx) % len(line)] == '#': numTrees += 1 return numTrees
edit: was also confused as to why you can't print an enumerate object until you put it into a list. but guess that's a conversation for data structures... i should really do a bit more formal learning
Last test of second part tripped me up because I had 'y' incrementing by 1 each step, rather than 'dy'.
Took me bloody ages to figure that out, not as bad as not reading the bloody question yesterday though.
https://github.com/lewfowls/AoC2020/blob/main/Day3code.py