From 1a4e272c774bd7d0984594b8c1d3d0af66e414d1 Mon Sep 17 00:00:00 2001 From: Dylan Donnell Date: Thu, 4 Dec 2025 15:02:39 +0000 Subject: [PATCH] 2025 days 1-4 --- 2025/01/.gitkeep | 0 2025/01/dy-tea.v | 50 +++++++++++++++++++++++++++++++ 2025/01/rotations.input | 10 +++++++ 2025/02/.gitkeep | 0 2025/02/dy-tea.v | 41 +++++++++++++++++++++++++ 2025/02/ids.input | 1 + 2025/03/.gitkeep | 0 2025/03/banks.input | 4 +++ 2025/03/dy-tea.v | 45 ++++++++++++++++++++++++++++ 2025/04/.gitkeep | 0 2025/04/department.input | 10 +++++++ 2025/04/dy-tea.v | 64 ++++++++++++++++++++++++++++++++++++++++ known/2025/01/dy-tea.out | 2 ++ known/2025/02/dy-tea.out | 2 ++ known/2025/03/dy-tea.out | 2 ++ known/2025/04/dy-tea.out | 2 ++ 16 files changed, 233 insertions(+) delete mode 100644 2025/01/.gitkeep create mode 100644 2025/01/dy-tea.v create mode 100644 2025/01/rotations.input delete mode 100644 2025/02/.gitkeep create mode 100644 2025/02/dy-tea.v create mode 100644 2025/02/ids.input delete mode 100644 2025/03/.gitkeep create mode 100644 2025/03/banks.input create mode 100644 2025/03/dy-tea.v delete mode 100644 2025/04/.gitkeep create mode 100644 2025/04/department.input create mode 100644 2025/04/dy-tea.v create mode 100644 known/2025/01/dy-tea.out create mode 100644 known/2025/02/dy-tea.out create mode 100644 known/2025/03/dy-tea.out create mode 100644 known/2025/04/dy-tea.out diff --git a/2025/01/.gitkeep b/2025/01/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/2025/01/dy-tea.v b/2025/01/dy-tea.v new file mode 100644 index 0000000..3659fa9 --- /dev/null +++ b/2025/01/dy-tea.v @@ -0,0 +1,50 @@ +import os +import math + +// part 1 +lines := os.read_lines('rotations.input')! +mut dial := 50 +mut count := 0 +for line in lines { + dir := line[0] + turns := line[1..].int() + dial += turns * if dir == `L` { -1 } else { 1 } + for dial > 99 { + dial -= 100 + } + for dial < 0 { + dial += 100 + } + if dial == 0 { + count++ + } +} +println(count) + +// part 2 +dial = 50 +count = 0 +for line in lines { + dir := line[0] + turns := line[1..].int() + delta := turns * if dir == `L` { -1 } else { 1 } + dial += delta + if delta < 0 { + if dial >= 0 { + if dial == 0 { + count++ + } + continue + } + if dial - delta != 0 { + count++ + } + dial = math.abs(dial) + count += dial / 100 + dial = (100 - dial % 100) % 100 + } else { + count += dial / 100 + dial %= 100 + } +} +println(count) diff --git a/2025/01/rotations.input b/2025/01/rotations.input new file mode 100644 index 0000000..53287c7 --- /dev/null +++ b/2025/01/rotations.input @@ -0,0 +1,10 @@ +L68 +L30 +R48 +L5 +R60 +L55 +L1 +L99 +R14 +L82 diff --git a/2025/02/.gitkeep b/2025/02/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/2025/02/dy-tea.v b/2025/02/dy-tea.v new file mode 100644 index 0000000..bc47159 --- /dev/null +++ b/2025/02/dy-tea.v @@ -0,0 +1,41 @@ +import os + +line := os.read_lines('ids.input')![0] +items := line.split(',') + +// part 1 +mut sum := u64(0) +for item in items { + left, right := item.split_once('-') or { panic('invalid input') } + start := left.u64() + end := right.u64() + for i in start .. end + 1 { + s := i.str() + if s.len % 2 == 0 { + if s[0..s.len / 2] == s[s.len / 2..s.len] { + sum += i + } + } + } +} +println(sum) + +// part 2 +sum = 0 +for item in items { + left, right := item.split_once('-') or { panic('invalid input') } + start := left.u64() + end := right.u64() + for i in start .. end + 1 { + s := i.str() + for x in 1 .. s.len / 2 + 1 { + if s.len % x == 0 { + if s[0..x].repeat(s.len / x) == s { + sum += i + break + } + } + } + } +} +println(sum) diff --git a/2025/02/ids.input b/2025/02/ids.input new file mode 100644 index 0000000..a3f22ef --- /dev/null +++ b/2025/02/ids.input @@ -0,0 +1 @@ +11-22,95-115,998-1012,1188511880-1188511890,222220-222224,1698522-1698528,446443-446449,38593856-38593862,565653-565659,824824821-824824827,2121212118-2121212124 diff --git a/2025/03/.gitkeep b/2025/03/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/2025/03/banks.input b/2025/03/banks.input new file mode 100644 index 0000000..7255fca --- /dev/null +++ b/2025/03/banks.input @@ -0,0 +1,4 @@ +987654321111111 +811111111111119 +234234234234278 +818181911112111 diff --git a/2025/03/dy-tea.v b/2025/03/dy-tea.v new file mode 100644 index 0000000..e1e97d8 --- /dev/null +++ b/2025/03/dy-tea.v @@ -0,0 +1,45 @@ +import os + +lines := os.read_lines('banks.input')! + +// part 1 +mut sum := u64(0) +for line in lines { + mut max := 0 + l := line.runes() + for i, x in l { + for y in l[i + 1..] { + dig := '${x}${y}'.int() + if dig > max { + max = dig + } + } + } + sum += u64(max) +} +println(sum) + +// part 2 +sum = 0 +for line in lines { + mut max := u64(0) + mut prev := 0 + l := line.runes() + for i in 0 .. 12 { + mut dig := 0 + for j in prev .. (l.len - 11 + i) { + c := l[j].str().int() + if dig >= c { + continue + } + dig = c + prev = j + 1 + if dig == 9 { + break + } + } + max = max * u64(10) + u64(dig) + } + sum += max +} +println(sum) diff --git a/2025/04/.gitkeep b/2025/04/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/2025/04/department.input b/2025/04/department.input new file mode 100644 index 0000000..8209399 --- /dev/null +++ b/2025/04/department.input @@ -0,0 +1,10 @@ +..@@.@@@@. +@@@.@.@.@@ +@@@@@.@.@@ +@.@@@@..@. +@@.@@@@.@@ +.@@@@@@@.@ +.@.@.@.@@@ +@.@@@.@@@@ +.@@@@@@@@. +@.@.@@@.@. diff --git a/2025/04/dy-tea.v b/2025/04/dy-tea.v new file mode 100644 index 0000000..e2e3655 --- /dev/null +++ b/2025/04/dy-tea.v @@ -0,0 +1,64 @@ +import os + +lines := os.read_lines('department.input')! +offsets := [[-1, -1], [0, -1], [-1, 0], [1, 1], [1, 0], [0, 1], + [1, -1], [-1, 1]] + +// part 1 +mut sum := 0 +for x, line in lines { + iter: for y, ch in line { + if ch == `.` { + continue + } + mut count := 0 + for pos in offsets { + nx := x + pos[0] + ny := y + pos[1] + if nx < 0 || nx >= line.len || ny < 0 || ny >= lines.len { + continue + } + if lines[nx][ny] == `@` { + count++ + } + if count > 3 { + continue iter + } + } + sum++ + } +} +println(sum) + +// part 2 +sum = 0 +mut grid := lines.map(|l| l.runes()) +mut removed := 1 +for removed != 0 { + removed = 0 + for x, row in grid { + loop: for y, ch in row { + if ch == `.` { + continue + } + mut count := 0 + for pos in offsets { + nx := x + pos[0] + ny := y + pos[1] + if nx < 0 || nx >= row.len || ny < 0 || ny >= grid.len { + continue + } + if grid[nx][ny] == `@` { + count++ + } + if count > 3 { + continue loop + } + } + grid[x][y] = `.` + removed++ + sum++ + } + } +} +println(sum) diff --git a/known/2025/01/dy-tea.out b/known/2025/01/dy-tea.out new file mode 100644 index 0000000..2559e5c --- /dev/null +++ b/known/2025/01/dy-tea.out @@ -0,0 +1,2 @@ +3 +6 diff --git a/known/2025/02/dy-tea.out b/known/2025/02/dy-tea.out new file mode 100644 index 0000000..0ab4cb7 --- /dev/null +++ b/known/2025/02/dy-tea.out @@ -0,0 +1,2 @@ +1227775554 +4174379265 diff --git a/known/2025/03/dy-tea.out b/known/2025/03/dy-tea.out new file mode 100644 index 0000000..8e49ff0 --- /dev/null +++ b/known/2025/03/dy-tea.out @@ -0,0 +1,2 @@ +357 +3121910778619 diff --git a/known/2025/04/dy-tea.out b/known/2025/04/dy-tea.out new file mode 100644 index 0000000..a6118ef --- /dev/null +++ b/known/2025/04/dy-tea.out @@ -0,0 +1,2 @@ +13 +43