Advent of Code 2021 - Day 2

preview_player
Показать описание
In this video series, I try to challenge myself with the Advent of Code trials. Each solution will be published to Github, and I hope you will learn something from my coding mistakes and perhaps send some code my way on how you have done these challenges. I know by reading code, so this is such an exciting thing for me.

GitHub repository:

Unlock unlimited opportunities with 50% off your first month of Coursera Plus

Get on the fast track to a career in cybersecurity. In this certificate program, you'll learn in-demand skills, and get AI training from Google experts. Learn at your own pace, no degree or experience required.

Join the channel to get access to more perks:

Or visit my blog at:

Outro music: Sanaas Scylla

#aoc2021 #advent #code
Рекомендации по теме
Комментарии
Автор

Thank you for these videos, this is great prep work for advent of code 2022 :D

TiMCoopr
Автор

I think I came up with the same solution for this problem. As you noted, it was surprisingly simple; I didn't expect I would be able to solve both parts before I needed to start work.

I'm trying a bit of a different approach this year, I'm putting all the input files into the resources directory, with standardized naming. Then I created a utility function that takes the day, part a/b, and whether I was "test" data or "final" data. It then returns a BufferedReader for the requested file from resources. That way my code to open the file each day feels less duplicated, and I can switch between the sample and real data by switching a flag:

public class Utility {
public static BufferedReader getInputFileBuffer(int day, String part, boolean testInput) {
String filename = String.format("day%02d%s_input_%s.txt", day, part, testInput ? "test" : "final");

return new BufferedReader(new
}
}

Eventually (perhaps later today), I want to make a master "execution class" that will let me build everything into a jar and I can choose which day/problem to run by passing command line arguments.

aaronperl