Advent of Code 2021 — Day 5

https://adventofcode.com/2021/day/5

Part 1 — This is a day to make sure you know your multi-dimensional arrays in your programming language and can trace lines given two end points. I modeled this in two ways — with a filled NxN grid and with a sparse grid (Hash). In these examples, the NxN grid was almost an order of magnitude faster. For the NxN grid, also made the assumption that the grid was square, which is good enough for this problem.

Once we process the horizontal and vertical lines in the input, we count the grid squares that have more than one line overlapping it. I use the enumerable methods of count and sum to count the overlaps in the grid.

Part 2 — The only difference in part 2 is that we now process the whole input, including the diagonal lines.

Source on github

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Agile and child rearing intersecting on empowerment and intrinsic motivation

Merry Christmas from Medical Coding Academy

Uploading Data into the DRIVER Platform

Watch a video on how Actix Web’s drama went down

Solid: Go with the flow

UX Work: Woman's hands drawing a wireframe

Utilibill: Guiding Utilities to the Cloud through Digital Transformation

Combining Multiple CSV Files into One with Pandas

How to build an API with Slim PHP and RedBean ORM.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Gene Hsu

Gene Hsu

More from Medium

Visual Diagrams: Why Intelligent Flow Charts, Simple Imaging & Diagrams Are Important?

Rong but Reasonable-Part 1

Analog computers are coming back!

Four Classics Every Young Adult Should Read