Advent of Code 2020 - Day 3

preview_player
Показать описание
42nd on part 1; 15th on part 2. About 40 seconds behind this time.

This is a basic grid problem. I have a set of conventions I always use for grid problems; the dimensions are "rows" and "columns", indexed by variables named "r" and "c". The upper-left corner is (0,0). Rows increase down and columns increase to the right. Rows are always the first index. i.e. always G[r][c] never G[c][r].

I think it's helpful to have something like this in mind. It doesn't have to be the same as mine; another common choice is x and y with y increasing up. Otherwise you have to think through all these decisions, which costs time and increases the chance of mistakes. I was lucky in this case that my conventions lined up with the problem statement.
Рекомендации по теме
Комментарии
Автор

Honestly the 40s are coming from typing fileimport readlines boilerplate, most people have that already setup I would imagine. I get not every puzzle can use that but most conform to that pattern.

ryancastner
Автор

I love these videos. I am learning something useful all the time!

linlasj
Автор

Thanks for these videos and explanations

robinosolava
Автор

Thanks for the video and explanation. I like completing the puzzle and then comparing my solution to yours. I don't come from a competitive background so there are going to be obvious approaches I miss and in this case, I actually generated the arrays if I landed in a "chunk" which doesn't exist yet — trying to take a chapter from game chunk generation there 😅.

Pretty neat to see the '%' approach. Is the idea of a repeating pattern like this something you've seen in the past or did you realise on the fly that you could use a mod approach? Just curious because I'm keen to learn what patterns show up commonly in these kinds of puzzles :)

kiriappeee
Автор

i know you get the same list in the end, but you seem to prefer appending than doing a read().splitlines() for the input file. any reasoning or just your preference?

prestonnewton