Advent of Code 2024 - Day 10 - Hoof It

  Рет қаралды 162

Daniel Persson (Kalaspuffar)

Daniel Persson (Kalaspuffar)

Күн бұрын

Пікірлер: 6
@yordiverkroost
@yordiverkroost 4 күн бұрын
Funny thing: I got the exact same numeric solutions for both part one and part two as you. Great job on making these videos, I love to watch them every day after I solved the problem myself (and sometimes to get a little hint when I get stuck). I like your pace in solving the problem and the way you explain your thinking. Keep it up!
@aaronperl
@aaronperl Күн бұрын
I couldn't figure out why my solution for Part A was always so much larger than the goal. After taking a break for a couple of days (because of work and no free time), I re-read the description and realised I had misinterpreted what it was asking for. It turned out that I was solving Part B without knowing what Part B would be. Instead of checking each position on the map for a 0, I kept track of a list of starting positions while parsing the input. I felt like that should reduce the amount of processing effort, although with the size of the input I don't think that really ended up being too much of a concern. I was also worried about runaway recursion (ie, stack overflow) in Part B (before I got to Part B), so I was really hoping I wouldn't have to figure out an iterative version, since recursion works so well for this problem.
@WayneBagguley
@WayneBagguley 5 күн бұрын
For part 2 you just needed to change the Set to a List.
@shredder7304
@shredder7304 4 күн бұрын
Thank you for making these! I am a new programmer so this really helps :) I couldn't solve part 1, but accidentally solved part 2 in my attempt (wops!) public static void findStart(List map) { int result = 0; for (int i = 0; i < map.size(); i++) { int[] row = map.get(i); for (int j = 0; j < row.length; j++) { if (map.get(i)[j] == 0) { result += checkTrail(map, 0, i, j); } } } System.out.println(result); } public static int checkTrail(List map, int n, int row, int col) { int result = 0; if (n == 9) return 1; int width = map.get(0).length; int length = map.size(); // left if (col > 0) { if (map.get(row)[col - 1] == n + 1) { result += checkTrail(map, n + 1, row, col - 1); } } // right if (col < width - 1) { if (map.get(row)[col + 1] == n + 1) { result += checkTrail(map, n + 1, row, col + 1); } } // up if (row > 0) { if (map.get(row - 1)[col] == n + 1) { result += checkTrail(map, n + 1, row - 1, col); } } // down if (row < length - 1) { if (map.get(row + 1)[col] == n + 1) { result += checkTrail(map, n + 1, row + 1, col); } } return result; }
@aaronperl
@aaronperl Күн бұрын
The same happened to me. After I took a break and re-read the description with fresh eyes, I realised that for Part A you just have to count the number of unique "9"s you can get to from each "0", not each way of getting there
@WayneBagguley
@WayneBagguley 5 күн бұрын
One-liners are back today! Part 1: fun calc(input: List): Int = input.flatMapIndexed{y,l->l.mapIndexed{x,c->(x to y) to (c.digitToInt() to mutableSetOf())}} .associate{it}.also{p->p.entries.sortedBy{-it.value.first}.forEach{e->if(e.value.first==9)e.value.second.add(e.key) else(listOf(0 to -1,1 to 0,0 to 1,-1 to 0).mapNotNull{p[it.first+e.key.first to it.second+e.key.second]}).filter{ it.first==e.value.first+1}.forEach{e.value.second.addAll(it.second)}}}.entries.filter{it.value.first==0}.sumOf{it.value.second.size} Part 2: fun calc(input: List): Int = input.flatMapIndexed{y,l->l.mapIndexed{x,c->(x to y) to (c.digitToInt() to mutableListOf())}} .associate{it}.also{p->p.entries.sortedBy{-it.value.first}.forEach{e->if(e.value.first==9)e.value.second.add(e.key) else(listOf(0 to -1,1 to 0,0 to 1,-1 to 0).mapNotNull{p[it.first+e.key.first to it.second+e.key.second]}).filter{ it.first==e.value.first+1}.forEach{e.value.second.addAll(it.second)}}}.entries.filter{it.value.first==0}.sumOf{it.value.second.size} The only difference is the use of a Set in Part 1 and a List in part 2.
Advent of Code 2024 - Day 12 - Garden Groups
34:27
Daniel Persson (Kalaspuffar)
Рет қаралды 200
It works #beatbox #tiktok
00:34
BeatboxJCOP
Рет қаралды 9 МЛН
How Strong Is Tape?
00:24
Stokes Twins
Рет қаралды 24 МЛН
Don't lose data, a first look into Bacula backup solution
43:07
Daniel Persson (Kalaspuffar)
Рет қаралды 519
Keynote: Advent of Code, Behind the Scenes - Eric Wastl
46:01
Advent Of Code 2024 - Day 1
19:24
Wekoslav Stefanovski
Рет қаралды 366
Stop using std::vector wrong
23:14
The Cherno
Рет қаралды 156 М.
CAUTION: Google's Gemini 2 is ACTUALLY useful
11:52
Alex Ziskind
Рет қаралды 75 М.
Learning C# In A Week... Otherwise I Fail University
9:04
5 Things All C Programmers MUST Know (#5 is the Killer)
8:58
Code With Huw
Рет қаралды 10 М.
Advent of Code 2024 Day 12 - 16th Gold Star!
22:33
Neil Thistlethwaite
Рет қаралды 3 М.