Advent of Code 2024 - Day 10 - Hoof It

  Рет қаралды 161

Daniel Persson (Kalaspuffar)

Daniel Persson (Kalaspuffar)

Күн бұрын

Пікірлер: 6
@yordiverkroost
@yordiverkroost 5 күн бұрын
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.
@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.
@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
Advent of Code 2024 - Day 15 - Warehouse Woes
1:05:36
Daniel Persson (Kalaspuffar)
Рет қаралды 12
Advent of Code 2024 - Day 9 - Disk Fragmenter
39:31
Daniel Persson (Kalaspuffar)
Рет қаралды 405
黑天使只对C罗有感觉#short #angel #clown
00:39
Super Beauty team
Рет қаралды 34 МЛН
小丑女COCO的审判。#天使 #小丑 #超人不会飞
00:53
超人不会飞
Рет қаралды 14 МЛН
Что-что Мурсдей говорит? 💭 #симбочка #симба #мурсдей
00:19
THE AMAZING DIGITAL CIRCUS - Ep 4: Fast Food Masquerade
23:20
GLITCH
Рет қаралды 26 МЛН
Advent of code 2024 - Day 6
49:33
Mr Gordon's maths universe
Рет қаралды 54
Sudden assault near Kursk / Putin's statement
13:04
NEXTA Live
Рет қаралды 1 МЛН
AI VOICE CHANGER 2024! EASY! [NEW BETTER]
11:24
Voice Changer
Рет қаралды 138
Advent of Code 2024 - Day 12 - Garden Groups
34:27
Daniel Persson (Kalaspuffar)
Рет қаралды 208
黑天使只对C罗有感觉#short #angel #clown
00:39
Super Beauty team
Рет қаралды 34 МЛН