advent_of_ruby 0.3.4 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/data/solutions/github/ZogStriP/2024/01_1.yml +1 -0
- data/data/solutions/github/ZogStriP/2024/01_2.yml +7 -0
- data/data/solutions/github/ZogStriP/2024/02_1.yml +1 -0
- data/data/solutions/github/ZogStriP/2024/02_2.yml +9 -0
- data/data/solutions/github/ZogStriP/2024/03_1.yml +1 -0
- data/data/solutions/github/ZogStriP/2024/03_2.yml +7 -0
- data/data/solutions/github/ZogStriP/2024/04_1.yml +1 -0
- data/data/solutions/github/ZogStriP/2024/04_2.yml +15 -0
- data/data/solutions/github/ZogStriP/2024/05_1.yml +1 -0
- data/data/solutions/github/ZogStriP/2024/05_2.yml +16 -0
- data/data/solutions/github/ZogStriP/2024/06_1.yml +1 -0
- data/data/solutions/github/ZogStriP/2024/06_2.yml +38 -0
- data/data/solutions/github/ZogStriP/2024/07_1.yml +1 -0
- data/data/solutions/github/ZogStriP/2024/07_2.yml +9 -0
- data/data/solutions/github/ZogStriP/2024/08_1.yml +1 -0
- data/data/solutions/github/ZogStriP/2024/08_2.yml +27 -0
- data/data/solutions/github/ZogStriP/2024/09_1.yml +1 -0
- data/data/solutions/github/ZogStriP/2024/09_2.yml +1 -0
- data/data/solutions/github/ZogStriP/2024/10_1.yml +1 -0
- data/data/solutions/github/ZogStriP/2024/10_2.yml +1 -0
- data/data/solutions/github/ZogStriP/2024/11_1.yml +1 -0
- data/data/solutions/github/ZogStriP/2024/11_2.yml +1 -0
- data/data/solutions/github/ZogStriP/2024/12_1.yml +1 -0
- data/data/solutions/github/ZogStriP/2024/12_2.yml +1 -0
- data/data/solutions/github/ZogStriP/2024/13_1.yml +1 -0
- data/data/solutions/github/ZogStriP/2024/13_2.yml +1 -0
- data/data/solutions/github/ZogStriP/2024/14_1.yml +1 -0
- data/data/solutions/github/ZogStriP/2024/14_2.yml +1 -0
- data/data/solutions/github/ZogStriP/2024/15_1.yml +1 -0
- data/data/solutions/github/ZogStriP/2024/15_2.yml +1 -0
- data/data/solutions/github/ZogStriP/2024/16_1.yml +1 -0
- data/data/solutions/github/ZogStriP/2024/16_2.yml +1 -0
- data/data/solutions/github/ZogStriP/2024/17_1.yml +1 -0
- data/data/solutions/github/ZogStriP/2024/17_2.yml +1 -0
- data/data/solutions/github/ZogStriP/2024/18_1.yml +1 -0
- data/data/solutions/github/ZogStriP/2024/18_2.yml +1 -0
- data/data/solutions/github/ZogStriP/2024/19_1.yml +1 -0
- data/data/solutions/github/ZogStriP/2024/19_2.yml +1 -0
- data/data/solutions/github/ZogStriP/2024/20_1.yml +1 -0
- data/data/solutions/github/ZogStriP/2024/20_2.yml +1 -0
- data/data/solutions/github/ZogStriP/2024/21_1.yml +1 -0
- data/data/solutions/github/ZogStriP/2024/21_2.yml +1 -0
- data/data/solutions/github/ZogStriP/2024/22_1.yml +1 -0
- data/data/solutions/github/ZogStriP/2024/22_2.yml +1 -0
- data/data/solutions/github/ZogStriP/2024/23_1.yml +1 -0
- data/data/solutions/github/ZogStriP/2024/23_2.yml +1 -0
- data/data/solutions/github/ZogStriP/2024/24_1.yml +1 -0
- data/data/solutions/github/ZogStriP/2024/24_2.yml +1 -0
- data/data/solutions/github/ZogStriP/2024/25_1.yml +1 -0
- data/data/solutions/github/ZogStriP/2025/01_1.yml +1 -0
- data/data/solutions/github/ZogStriP/2025/01_2.yml +1 -0
- data/data/solutions/github/ZogStriP/2025/02_1.yml +1 -0
- data/data/solutions/github/ZogStriP/2025/02_2.yml +1 -0
- data/data/solutions/github/ZogStriP/2025/03_1.yml +1 -0
- data/data/solutions/github/ZogStriP/2025/03_2.yml +1 -0
- data/data/solutions/github/ZogStriP/2025/04_1.yml +1 -0
- data/data/solutions/github/ZogStriP/2025/04_2.yml +1 -0
- data/data/solutions/github/ZogStriP/2025/05_1.yml +1 -0
- data/data/solutions/github/ZogStriP/2025/05_2.yml +1 -0
- data/data/solutions/github/ZogStriP/2025/06_1.yml +1 -0
- data/data/solutions/github/ZogStriP/2025/06_2.yml +1 -0
- data/data/solutions/github/ZogStriP/2025/07_1.yml +1 -0
- data/data/solutions/github/ZogStriP/2025/07_2.yml +1 -0
- data/data/solutions/github/ZogStriP/2025/08_1.yml +1 -0
- data/data/solutions/github/ZogStriP/2025/08_2.yml +1 -0
- data/data/solutions/github/ZogStriP/2025/09_1.yml +1 -0
- data/data/solutions/github/ZogStriP/2025/09_2.yml +1 -0
- data/data/solutions/github/ZogStriP/2025/10_1.yml +1 -0
- data/data/solutions/github/ZogStriP/2025/10_2.yml +1 -0
- data/data/solutions/github/ZogStriP/2025/11_1.yml +1 -0
- data/data/solutions/github/ZogStriP/2025/11_2.yml +1 -0
- data/data/solutions/github/ZogStriP/2025/12_1.yml +1 -0
- data/data/solutions/github/ZogStriP/2025/12_2.yml +1 -0
- data/data/solutions/github/ahorner/2025/01_1.yml +1 -0
- data/data/solutions/github/ahorner/2025/01_2.yml +37 -0
- data/data/solutions/github/ahorner/2025/02_1.yml +1 -0
- data/data/solutions/github/ahorner/2025/02_2.yml +41 -0
- data/data/solutions/github/ahorner/2025/03_1.yml +1 -0
- data/data/solutions/github/ahorner/2025/03_2.yml +24 -0
- data/data/solutions/github/ahorner/2025/04_1.yml +1 -0
- data/data/solutions/github/ahorner/2025/04_2.yml +39 -0
- data/data/solutions/github/ahorner/2025/05_1.yml +1 -0
- data/data/solutions/github/ahorner/2025/05_2.yml +48 -0
- data/data/solutions/github/ahorner/2025/06_1.yml +1 -0
- data/data/solutions/github/ahorner/2025/06_2.yml +44 -0
- data/data/solutions/github/ahorner/2025/07_1.yml +1 -0
- data/data/solutions/github/ahorner/2025/07_2.yml +56 -0
- data/data/solutions/github/ahorner/2025/08_1.yml +1 -0
- data/data/solutions/github/ahorner/2025/08_2.yml +59 -0
- data/data/solutions/github/ahorner/2025/09_1.yml +1 -0
- data/data/solutions/github/ahorner/2025/09_2.yml +101 -0
- data/data/solutions/github/ahorner/2025/10_1.yml +1 -0
- data/data/solutions/github/ahorner/2025/10_2.yml +72 -0
- data/data/solutions/github/ahorner/2025/11_1.yml +1 -0
- data/data/solutions/github/ahorner/2025/11_2.yml +45 -0
- data/data/solutions/github/ahorner/2025/12_1.yml +1 -0
- data/data/solutions/github/eregon/2025/01_1.yml +17 -0
- data/data/solutions/github/eregon/2025/01_2.yml +14 -0
- data/data/solutions/github/eregon/2025/02_1.yml +22 -0
- data/data/solutions/github/eregon/2025/02_2.yml +58 -0
- data/data/solutions/github/eregon/2025/03_1.yml +13 -0
- data/data/solutions/github/eregon/2025/03_2.yml +13 -0
- data/data/solutions/github/eregon/2025/04_1.yml +14 -0
- data/data/solutions/github/eregon/2025/04_2.yml +16 -0
- data/data/solutions/github/eregon/2025/05_1.yml +1 -0
- data/data/solutions/github/eregon/2025/05_2.yml +1 -0
- data/data/solutions/github/eregon/2025/06_1.yml +1 -0
- data/data/solutions/github/eregon/2025/06_2.yml +1 -0
- data/data/solutions/github/eregon/2025/07_1.yml +1 -0
- data/data/solutions/github/eregon/2025/07_2.yml +1 -0
- data/data/solutions/github/eregon/2025/08_1.yml +1 -0
- data/data/solutions/github/eregon/2025/08_2.yml +1 -0
- data/data/solutions/github/eregon/2025/09_1.yml +1 -0
- data/data/solutions/github/eregon/2025/09_2.yml +1 -0
- data/data/solutions/github/eregon/2025/10_1.yml +1 -0
- data/data/solutions/github/eregon/2025/10_2.yml +1 -0
- data/data/solutions/github/eregon/2025/11_1.yml +1 -0
- data/data/solutions/github/eregon/2025/11_2.yml +1 -0
- data/data/solutions/github/eregon/2025/12_1.yml +1 -0
- data/data/solutions/github/erikw/2025/01_1.yml +1 -0
- data/data/solutions/github/erikw/2025/01_2.yml +1 -0
- data/data/solutions/github/erikw/2025/02_1.yml +1 -0
- data/data/solutions/github/erikw/2025/02_2.yml +1 -0
- data/data/solutions/github/erikw/2025/03_1.yml +1 -0
- data/data/solutions/github/erikw/2025/03_2.yml +1 -0
- data/data/solutions/github/erikw/2025/04_1.yml +1 -0
- data/data/solutions/github/erikw/2025/04_2.yml +1 -0
- data/data/solutions/github/erikw/2025/05_1.yml +1 -0
- data/data/solutions/github/erikw/2025/05_2.yml +1 -0
- data/data/solutions/github/erikw/2025/06_1.yml +1 -0
- data/data/solutions/github/erikw/2025/06_2.yml +1 -0
- data/data/solutions/github/erikw/2025/07_1.yml +1 -0
- data/data/solutions/github/erikw/2025/07_2.yml +1 -0
- data/data/solutions/github/erikw/2025/08_1.yml +1 -0
- data/data/solutions/github/erikw/2025/08_2.yml +1 -0
- data/data/solutions/github/erikw/2025/09_1.yml +1 -0
- data/data/solutions/github/erikw/2025/09_2.yml +1 -0
- data/data/solutions/github/erikw/2025/10_1.yml +1 -0
- data/data/solutions/github/erikw/2025/10_2.yml +1 -0
- data/data/solutions/github/erikw/2025/11_1.yml +1 -0
- data/data/solutions/github/erikw/2025/11_2.yml +1 -0
- data/data/solutions/github/erikw/2025/12_1.yml +1 -0
- data/data/solutions/github/erikw/2025/12_2.yml +1 -0
- data/data/solutions/github/gchan/2025/01_1.yml +25 -0
- data/data/solutions/github/gchan/2025/01_2.yml +32 -0
- data/data/solutions/github/gchan/2025/02_1.yml +18 -0
- data/data/solutions/github/gchan/2025/02_2.yml +21 -0
- data/data/solutions/github/gchan/2025/03_1.yml +15 -0
- data/data/solutions/github/gchan/2025/03_2.yml +23 -0
- data/data/solutions/github/gchan/2025/04_1.yml +27 -0
- data/data/solutions/github/gchan/2025/04_2.yml +40 -0
- data/data/solutions/github/gchan/2025/05_1.yml +20 -0
- data/data/solutions/github/gchan/2025/05_2.yml +36 -0
- data/data/solutions/github/gchan/2025/06_1.yml +11 -0
- data/data/solutions/github/gchan/2025/06_2.yml +28 -0
- data/data/solutions/github/gchan/2025/07_1.yml +33 -0
- data/data/solutions/github/gchan/2025/07_2.yml +29 -0
- data/data/solutions/github/gchan/2025/08_1.yml +48 -0
- data/data/solutions/github/gchan/2025/08_2.yml +48 -0
- data/data/solutions/github/gchan/2025/09_1.yml +16 -0
- data/data/solutions/github/gchan/2025/09_2.yml +60 -0
- data/data/solutions/github/gchan/2025/10_1.yml +49 -0
- data/data/solutions/github/gchan/2025/10_2.yml +154 -0
- data/data/solutions/github/gchan/2025/11_1.yml +43 -0
- data/data/solutions/github/gchan/2025/11_2.yml +33 -0
- data/data/solutions/github/gchan/2025/12_1.yml +51 -0
- data/data/solutions/reddit/ruby/2017/06.yml +0 -2
- data/data/solutions/reddit/ruby/2020/02.yml +0 -1
- data/data/solutions/reddit/ruby/2024/02.yml +0 -1
- data/data/solutions/reddit/ruby/2025/01.yml +187 -0
- data/data/solutions/reddit/ruby/2025/02.yml +185 -0
- data/data/solutions/reddit/ruby/2025/03.yml +369 -0
- data/data/solutions/reddit/ruby/2025/04.yml +217 -0
- data/data/solutions/reddit/ruby/2025/05.yml +324 -0
- data/data/solutions/reddit/ruby/2025/06.yml +246 -0
- data/data/solutions/reddit/ruby/2025/07.yml +213 -0
- data/data/solutions/reddit/ruby/2025/08.yml +73 -0
- data/data/solutions/reddit/ruby/2025/09.yml +26 -0
- data/data/solutions/reddit/ruby/2025/10.yml +73 -0
- data/data/solutions/reddit/ruby/2025/11.yml +69 -0
- data/data/solutions/reddit/ruby/2025/12.yml +1 -0
- data/lib/arb/arb.rb +0 -5
- data/lib/arb/cli/bootstrap.rb +1 -1
- data/lib/arb/cli/commit.rb +1 -1
- data/lib/arb/cli/progress.rb +4 -8
- data/lib/arb/cli/run.rb +1 -1
- data/lib/arb/cli/shared/git.rb +3 -4
- data/lib/arb/cli/shared/year_day_validator.rb +3 -8
- data/lib/arb/files/spec.rb +2 -2
- data/lib/arb/formatters/rubocop.rb +18 -11
- data/lib/arb/util.rb +58 -0
- data/lib/arb/version.rb +1 -1
- metadata +184 -23
- data/lib/download_solutions/api/github/repos.rb +0 -54
- data/lib/download_solutions/api/github.rb +0 -164
- data/lib/download_solutions/api/reddit/add_missing_replies.rb +0 -43
- data/lib/download_solutions/api/reddit/clean_bodies.rb +0 -64
- data/lib/download_solutions/api/reddit/filter_by_language.rb +0 -32
- data/lib/download_solutions/api/reddit/get_initial_response.rb +0 -30
- data/lib/download_solutions/api/reddit/get_serial_comments.rb +0 -145
- data/lib/download_solutions/api/reddit/megathread_ids.rb +0 -19
- data/lib/download_solutions/api/reddit/params.rb +0 -40
- data/lib/download_solutions/api/reddit/reject_unwanted_replies.rb +0 -31
- data/lib/download_solutions/api/reddit/remove_ids.rb +0 -26
- data/lib/download_solutions/api/reddit/remove_language_tags.rb +0 -29
- data/lib/download_solutions/api/reddit.rb +0 -101
- data/lib/download_solutions/cli/cli/shared.rb +0 -35
- data/lib/download_solutions/cli/github.rb +0 -107
- data/lib/download_solutions/cli/reddit.rb +0 -64
- data/lib/download_solutions/download_solutions.rb +0 -18
- data/lib/download_solutions/reverse_markdown/converters/br.rb +0 -15
- data/lib/download_solutions/reverse_markdown/converters/pre.rb +0 -46
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
---
|
|
2
|
+
- :author: thaadjarvis
|
|
3
|
+
:url: https://www.reddit.com/r/adventofcode/comments/1pg9w66/2025_day_7_solutions/ntdpc7f
|
|
4
|
+
:body: |-
|
|
5
|
+
[solution](https://github.com/mtking2/aoc-ruby/blob/main/lib/solutions/year2025/day07.rb)
|
|
6
|
+
|
|
7
|
+
Part 1 just iterating and counting splits
|
|
8
|
+
|
|
9
|
+
Part 2 using \>!recursion and memoization!\<
|
|
10
|
+
:replies: []
|
|
11
|
+
- :author: SleepingInsomniac
|
|
12
|
+
:url: https://www.reddit.com/r/adventofcode/comments/1pg9w66/2025_day_7_solutions/nsv51ep
|
|
13
|
+
:body: |-
|
|
14
|
+
https://asciinema.org/a/sabtPpvg27FtpvZ27zS4VxaIH
|
|
15
|
+
|
|
16
|
+
https://github.com/SleepingInsomniac/adventofcode/tree/master/2025-12-07
|
|
17
|
+
:replies: []
|
|
18
|
+
- :author: srugh
|
|
19
|
+
:url: https://www.reddit.com/r/adventofcode/comments/1pg9w66/2025_day_7_solutions/nsum8ms
|
|
20
|
+
:body: |-
|
|
21
|
+
Solutions in Ruby for part 1 and part 2. No recursion, no dfs, etc.
|
|
22
|
+
|
|
23
|
+
[GitHub Day 7 part 1 and part 2](https://github.com/srugh/AdventOfCode/blob/main/2025/day-07.rb)
|
|
24
|
+
:replies: []
|
|
25
|
+
- :author: Intelligent_Net_9057
|
|
26
|
+
:url: https://www.reddit.com/r/adventofcode/comments/1pg9w66/2025_day_7_solutions/nsucl6w
|
|
27
|
+
:body: |-
|
|
28
|
+
```ruby
|
|
29
|
+
tree = File.readlines('test_input', chomp: true)
|
|
30
|
+
beams = [0] * tree[0].length
|
|
31
|
+
beams[tree.shift.chars.find_index('S')] = 1
|
|
32
|
+
splits = 0
|
|
33
|
+
|
|
34
|
+
tree.each do |line|
|
|
35
|
+
line.chars.each_with_index do |c, i|
|
|
36
|
+
if c == '^' && beams[i] > 0
|
|
37
|
+
splits += 1
|
|
38
|
+
beams[i-1] += beams[i]
|
|
39
|
+
beams[i+1] += beams[i]
|
|
40
|
+
beams[i] = 0
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
puts "Part 1 : #{splits}"
|
|
46
|
+
puts "Part 2 : #{beams.sum}"
|
|
47
|
+
```
|
|
48
|
+
:replies: []
|
|
49
|
+
- :author: Mahedros
|
|
50
|
+
:url: https://www.reddit.com/r/adventofcode/comments/1pg9w66/2025_day_7_solutions/nsszky8
|
|
51
|
+
:body: |-
|
|
52
|
+
For once I've managed to overcome my stubbornness and actually go back to make something efficient rather than just let the brute force code run for 12 hours
|
|
53
|
+
|
|
54
|
+
[Code Link](https://topaz.github.io/paste/#XQAAAQAKCAAAAAAAAAARiEJHiiMzw3cPM/1Vl+2nyBa63n8KxkURAq1MNsPbt6HX6Vl9MUBsAFA2fZ7UeLBp9rfMabILJJXIO9G6n2aBBUDc2ZX4vbyOrCXe0HqHl8HWoSGrxseDo04/PSV3b/iXlpH6vER64cio881Jqa+7Mhqt9elIwPY8GahLlfkZIIaL4QJx643qKHkXkwxIWgqSrhbNsSkbtQhIyu+ErfQxFBjRynZlErvYWVeCiG1cdx5D42vfNkk8CRuzZK9j6biojXeKy67X0c8AKYf9j5OSZaMS1DckVOmRl7fjoThUccEXAMSxAr9cAx/fUcBcwUMeUR7IuSRoyW06f1cJNdRfcsrDjX689srtYHcC+TfFLZQ//bsifDqKRVpJ4Oo0cpd/gru/5FS03FFTlblHnA7hD84FAQ477KBnX+U1Wgw9Dwpz2HF7CUo5lJ51Kk5maRcib6QIUuYq+/v1HxayxJ00soKfcTb8DfCBmoBED5FSWuev2Sg8tz0v2lfOFbMzLfVE2+PFW/ddx2zu35BHAw7l+5jZtLrzcPno7KLYV/efeNpwSvz5i0lRPltYPZXfygAMnTop0TDazKLgl1xTgoutd/+wQ5AGz+rp14Niq8LUe3NLKL1jLoA6GbR+LvIc/IG5Nachqoe+5G78SOmdt/gFTIeaSvWT6L0v9dbwRAyP/sD8K+dv+xcjpSkw5vrylVPuxLloOVLObw5GqnKaAkX/ISwhRNYm6iXW2QisDNkrbHgphpmLhRF6U4q+UgpNbdtJEC5o1IAOLtX4mU3y7eb7TZzowRkq3/JGtPM+chw2TI70g0LmJCbMsMp+ksXoqG9MHXhK1F6CQHNCOU7Ep25E3YafvHf/iV8FEg==)
|
|
55
|
+
:replies: []
|
|
56
|
+
- :author: riffraff
|
|
57
|
+
:url: https://www.reddit.com/r/adventofcode/comments/1pg9w66/2025_day_7_solutions/nsq8fmy
|
|
58
|
+
:body: |-
|
|
59
|
+
ugly, but it works. Somehow I got tripped when doing part 2 using the same way I was doing part 1, probably order of updates or something, so had to change that
|
|
60
|
+
|
|
61
|
+
```ruby
|
|
62
|
+
def solve_easy(grid)
|
|
63
|
+
split = 0
|
|
64
|
+
grid.rows.each_with_index do |row, nrow|
|
|
65
|
+
0.upto(row.length - 1) do |ncol|
|
|
66
|
+
if ["|", "S"].include?(grid.rows[nrow - 1][ncol])
|
|
67
|
+
if row[ncol] == "^"
|
|
68
|
+
row[ncol - 1] = "|"
|
|
69
|
+
row[ncol + 1] = "|"
|
|
70
|
+
split += 1
|
|
71
|
+
elsif row[ncol] == "."
|
|
72
|
+
row[ncol] = "|"
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
split
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def solve_hard(grid)
|
|
81
|
+
timelines = Hash.new(0)
|
|
82
|
+
grid.rows.size.times do |nrow|
|
|
83
|
+
row = grid.rows[nrow]
|
|
84
|
+
row.size.times do |ncol|
|
|
85
|
+
if row[ncol] == "S"
|
|
86
|
+
timelines[[nrow + 1, ncol]] += 1
|
|
87
|
+
elsif row[ncol] == "^"
|
|
88
|
+
timelines[[nrow + 1, ncol - 1]] += timelines[[nrow, ncol]]
|
|
89
|
+
timelines[[nrow + 1, ncol + 1]] += timelines[[nrow, ncol]]
|
|
90
|
+
else
|
|
91
|
+
timelines[[nrow + 1, ncol]] += timelines[[nrow, ncol]]
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
timelines.keys.select { |nrow, _| nrow == grid.rows.size }.sum { |k| timelines[k] }
|
|
96
|
+
end
|
|
97
|
+
```
|
|
98
|
+
:replies: []
|
|
99
|
+
- :author: xr51z
|
|
100
|
+
:url: https://www.reddit.com/r/adventofcode/comments/1pg9w66/2025_day_7_solutions/nsr8zk1
|
|
101
|
+
:body: |-
|
|
102
|
+
\
|
|
103
|
+
|
|
104
|
+
```ruby
|
|
105
|
+
# Note: this won't work with '^^' but the input doesn't include any
|
|
106
|
+
|
|
107
|
+
input = File
|
|
108
|
+
.readlines("07_input.txt", chomp: true)
|
|
109
|
+
.map { |x| x.split("") }
|
|
110
|
+
|
|
111
|
+
def splitter(x) x == "^" end
|
|
112
|
+
def beam(x) x == "|" end
|
|
113
|
+
def int(x) x.is_a? Integer end
|
|
114
|
+
|
|
115
|
+
# Part 1
|
|
116
|
+
|
|
117
|
+
result = 0
|
|
118
|
+
|
|
119
|
+
start = input[0].index("S")
|
|
120
|
+
input[1][start] = "|"
|
|
121
|
+
|
|
122
|
+
input.each_with_index do |row, x|
|
|
123
|
+
row.each_with_index do |col, y|
|
|
124
|
+
if splitter(col) and beam(input[x-1][y])
|
|
125
|
+
row[y-1] = row[y+1] = "|" # split beam
|
|
126
|
+
input[x+1][y-1] = input[x+1][y+1] = "|" # continue beam
|
|
127
|
+
result += 1
|
|
128
|
+
elsif !splitter(col) and beam(input[x-1][y])
|
|
129
|
+
row[y] = "|"
|
|
130
|
+
end
|
|
131
|
+
end
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
puts "Part 1: ", result
|
|
135
|
+
|
|
136
|
+
# Part 2
|
|
137
|
+
|
|
138
|
+
input[1][start] = 1 # initial beam
|
|
139
|
+
|
|
140
|
+
input.each_with_index do |row, x|
|
|
141
|
+
row.prepend(0); row.append(0) # to avoid issues near the end
|
|
142
|
+
row.each_with_index do |col, y|
|
|
143
|
+
if col == "." then row[y] = 0 end
|
|
144
|
+
if beam(col)
|
|
145
|
+
if splitter(row[y-1]) and splitter(row[y+1])
|
|
146
|
+
row[y] = input[x-1][y-1].to_i + input[x-1][y+1].to_i + input[x-1][y]
|
|
147
|
+
# last one doesn't need to_i as it is always 0 or an int
|
|
148
|
+
elsif splitter(row[y-1]) and !splitter(row[y+1])
|
|
149
|
+
row[y] = input[x-1][y-1] + input[x-1][y]
|
|
150
|
+
elsif !splitter(row[y-1]) and splitter(row[y+1])
|
|
151
|
+
row[y] = input[x-1][y+1] + input[x-1][y]
|
|
152
|
+
elsif int(input[x-1][y])
|
|
153
|
+
row[y] = input[x-1][y]
|
|
154
|
+
end
|
|
155
|
+
end
|
|
156
|
+
end
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
puts "Part 2: ", input[-1].inject(:+)
|
|
160
|
+
```
|
|
161
|
+
:replies:
|
|
162
|
+
- :author: xr51z
|
|
163
|
+
:url: https://www.reddit.com/r/adventofcode/comments/1pg9w66/2025_day_7_solutions/nsr9qhw
|
|
164
|
+
:body: Admittedly [this post](https://www.reddit.com/r/adventofcode/comments/1pgbg8a/2025_day_7_part_2_visualization_for_the_sample/) helped me a lot to visualize the problem in my head.
|
|
165
|
+
:replies: []
|
|
166
|
+
- :author: _tfa
|
|
167
|
+
:url: https://www.reddit.com/r/adventofcode/comments/1pg9w66/2025_day_7_solutions/nsrk303
|
|
168
|
+
:body: |-
|
|
169
|
+
Part 1
|
|
170
|
+
|
|
171
|
+
```ruby
|
|
172
|
+
GRID = File.readlines("input.txt").map(&:chars)
|
|
173
|
+
start = Complex(GRID[0].index(?S), 0)
|
|
174
|
+
|
|
175
|
+
beams = [start]
|
|
176
|
+
count = 0
|
|
177
|
+
|
|
178
|
+
(GRID.size-1).times do |o|
|
|
179
|
+
nextBeams = []
|
|
180
|
+
beams.each do |pos|
|
|
181
|
+
if GRID[pos.imag+1][pos.real] == ?^
|
|
182
|
+
nextBeams << pos + 1+1i
|
|
183
|
+
nextBeams << pos - 1+1i
|
|
184
|
+
count += 1
|
|
185
|
+
else
|
|
186
|
+
nextBeams << pos + 0+1i
|
|
187
|
+
end
|
|
188
|
+
end
|
|
189
|
+
nextBeams.uniq!
|
|
190
|
+
beams = nextBeams
|
|
191
|
+
end
|
|
192
|
+
puts count
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
Part 2
|
|
196
|
+
|
|
197
|
+
```ruby
|
|
198
|
+
GRID = File.readlines("input.txt").map(&:chars)
|
|
199
|
+
start = Complex(GRID[0].index(?S), 0)
|
|
200
|
+
MEM = {}
|
|
201
|
+
|
|
202
|
+
def solve(pos) =
|
|
203
|
+
MEM[pos] ||= case
|
|
204
|
+
when pos.imag == GRID.size - 1
|
|
205
|
+
1
|
|
206
|
+
when GRID[pos.imag+1][pos.real] == ?^
|
|
207
|
+
solve(pos + 1+1i) + solve(pos - 1+1i)
|
|
208
|
+
else
|
|
209
|
+
solve(pos + 0+1i)
|
|
210
|
+
end
|
|
211
|
+
puts solve(start)
|
|
212
|
+
```
|
|
213
|
+
:replies: []
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
---
|
|
2
|
+
- :author: srugh
|
|
3
|
+
:url: https://www.reddit.com/r/adventofcode/comments/1ph3tfc/2025_day_8_solutions/nt09027
|
|
4
|
+
:body: |-
|
|
5
|
+
Used DSU / Union find for this one.
|
|
6
|
+
|
|
7
|
+
[GitHub solution for both part 1 and part 2 using Ruby](https://github.com/srugh/AdventOfCode/blob/main/2025/day-08.rb)
|
|
8
|
+
:replies: []
|
|
9
|
+
- :author: xr51z
|
|
10
|
+
:url: https://www.reddit.com/r/adventofcode/comments/1ph3tfc/2025_day_8_solutions/nszpat1
|
|
11
|
+
:body: "[LINK](https://topaz.github.io/paste/#XQAAAQAtBgAAAAAAAAA5GUqKNoFH6SMqoVC09YUYdlQd9lvuD0yaWfOoUhdmwU3iFZtA1EYdUcBXWSpoi3hN8NnYO0x/Gu4Ryyma/PBexBnUS4FSGlRH8HAStpcRgm4VvwdrQdaBGB+6KVd8QOY7UPjNJxP1WsqcmlgaBVZQ2HykpWjforhlkvJiD2qbkXYLiWa0bge05ExU8bfy5Xc0AoYMf2oFnd+90vCDPAmQN7YirC9kgdpv2UjP2d9XDdQSzl0x6tIHI6IHEl/MIiYC6XsRGKujfG55OigVsKVuZuhHRhm/reIjNLL2rADiZsux3zmVUC5a6M7TiAqcDFpS1ksMa4ViXvUqnBkxQibgTG6eAKLrPmAY47kP4amjXQkPm3yr8VErm27Cfyw4xBVdp37qYmj95Jm4eivZk7xNqZDq7t2tpFJtWIncfaWejMuyFRMDErAS2R8GioxnlxRdXQ0mdsiP9qrPt5oG2ufepAx8A6jmhNv2ZoQMBkNvNDnJSJatu/e3/r8DYqiCJ89WciuLR0+imr0KEqPgffryUtgSlLKtmBzF0fzyNl3Tp1teEJKtH7w5v1yWWIcjXNlnPEoRpNLUXczWa7E5Z0i1mg5KmPNuwj0VkfT1RZ8UeYG6LLAKy99k5Sj2xuaU3NvAN7a0qCR6chCG+iXAwhLSa2AfiVv6M3s+9FJwB8BMZ/dnypZ2JEbWnHD8J2MoYpwOr/EMmlnIvb/ItdDfEU0HoxGQez19ND1iujQfxMtTmKBf/X3X4EwIzWa6H+eQEd6eO7blL0Ih2ISpKUOCUdKXt3DAAALqysSG+TRrt+lBlwtvi/aVTVNXq7pUmOdvFqDLmuYei7bxBxUhAqC+y5o++gEbyZh2rU9Dao6r6DPwkHv/0k8fhw==)"
|
|
12
|
+
:replies: []
|
|
13
|
+
- :author: el_daniero
|
|
14
|
+
:url: https://www.reddit.com/r/adventofcode/comments/1ph3tfc/2025_day_8_solutions/nswfxdm
|
|
15
|
+
:body: |-
|
|
16
|
+
```ruby
|
|
17
|
+
N = 1000
|
|
18
|
+
input = File.readlines('input08.txt').map { it.scan(/\d+/).map(&:to_i) }
|
|
19
|
+
|
|
20
|
+
circuits = input.to_h { [it,Set[it]] }
|
|
21
|
+
by_distance = input.combination(2).sort_by { |a,b| Math.sqrt(a.zip(b).sum { |ai,bi| (ai-bi)**2 }) }
|
|
22
|
+
|
|
23
|
+
print "Part 1: "
|
|
24
|
+
by_distance.take(N).each do |a,b|
|
|
25
|
+
ca,cb = circuits.values_at a,b
|
|
26
|
+
next if ca == cb
|
|
27
|
+
|
|
28
|
+
ca.merge cb
|
|
29
|
+
cb.each { circuits[it] = ca }
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
puts circuits.values.uniq.map(&:size).max(3).reduce(:*)
|
|
33
|
+
|
|
34
|
+
print "Part 2: "
|
|
35
|
+
by_distance.drop(N).each do |a,b|
|
|
36
|
+
ca,cb = circuits.values_at a,b
|
|
37
|
+
next if ca == cb
|
|
38
|
+
|
|
39
|
+
ca.merge cb
|
|
40
|
+
cb.each { circuits[it] = ca }
|
|
41
|
+
|
|
42
|
+
if circuits.values.uniq.size == 1
|
|
43
|
+
puts a[0]*b[0]
|
|
44
|
+
break
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
```
|
|
48
|
+
:replies: []
|
|
49
|
+
- :author: _tfa
|
|
50
|
+
:url: https://www.reddit.com/r/adventofcode/comments/1ph3tfc/2025_day_8_solutions/nswnuat
|
|
51
|
+
:body: |-
|
|
52
|
+
Part 1: [paste](https://topaz.github.io/paste/#XQAAAQBbAwAAAAAAAAAxmwhIY/U8uRGJe0wm8TD4UT8WFHJqY/veL97LoU6Dy/WfRDFYXlfX6PjMyFZoF8VZun3D1xbCBR5/xZWxa8nYpneP1J6Urt17E/nNd2krWX/S+KjyBuHsfryhXtVCu/TnNa/avwE2Yd65Kbjwwjienr5idmOgnAvTMZxWJSfOuLcl1Xg00guFCtB3eNN0xrXviKSbTlLxgMVpUrLIMWD8C2Hc1mCyDjetNVM501wtP/v3A8fVC9WvWolqt485zm9FMi/2Nsk5HOcCDCrMXykV/gzbL3mcvf0bV3dSRS6lTpFRhL1PASsYp8OHHFCFrJUGqyJb7BcqJS29RbLEeLZ7v+qjvIcc1fdeYcmrkyeOt2F2INUIBH95nWxItt2s1pNEUnFAsCPC6lBOGxh1rAFBwUrM/vxk6sditaCmCz8bTu3a26qje11ipUYkpdbVutFu4bqIoWgyZzCIg8BtDhv9lNmlzicNOp48ysOBjI1ZikOHb+aJ9ltB/GU5JV5gsscCUCAI2sQJR/pc0EJnIPJvKwEgE/Vg/5QNa8N3br4DfE+jWLQyyAFPXlNABv8/mXnjiLvalBLlXjrmUi6senq90iigWzz74q2wAnIRUl8lfbX+cdd0TVytbLeNtNIFB/wz/3+1SwA=)
|
|
53
|
+
|
|
54
|
+
Part 2 (easier than part 1 today):
|
|
55
|
+
|
|
56
|
+
```ruby
|
|
57
|
+
def dist(x,y) = x.zip(y).map{it.reduce(&:-)}.sum{it**2}
|
|
58
|
+
circuit = Set.new
|
|
59
|
+
|
|
60
|
+
File.readlines("08/input.txt")
|
|
61
|
+
.map{ it.split(?,).map(&:to_i) }
|
|
62
|
+
.combination(2)
|
|
63
|
+
.sort_by{ dist *it }
|
|
64
|
+
.each do |a,b|
|
|
65
|
+
circuit << a << b
|
|
66
|
+
(puts a[0] * b[0]; break) if circuit.size == 1000
|
|
67
|
+
end
|
|
68
|
+
```
|
|
69
|
+
:replies:
|
|
70
|
+
- :author: xr51z
|
|
71
|
+
:url: https://www.reddit.com/r/adventofcode/comments/1ph3tfc/2025_day_8_solutions/nszqlqq
|
|
72
|
+
:body: I also do AoC in Ruby and I love seeing how efficiently you do this (and previous entries). It's like we have the exact same idea but your code is a third of my amount of lines. Learning a lot! Thank you!
|
|
73
|
+
:replies: []
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
---
|
|
2
|
+
- :author: _tfa
|
|
3
|
+
:url: https://www.reddit.com/r/adventofcode/comments/1phywvn/2025_day_9_solutions/nu6tir3
|
|
4
|
+
:body: |-
|
|
5
|
+
I got inspired by the _Coordinate System Compression_ approach.
|
|
6
|
+
|
|
7
|
+
[Paste](https://topaz.github.io/paste/#XQAAAQB0BwAAAAAAAAA3G8iwV4Qppo79/Ujg+7qaomHJcVmcDMXaCHzF/szaCN1B3OQWh7s2tQ+43K8lY7nmb4hhnibJfso5Wp2gdiVwWpld8FvJMlogqHwXRsgKiG4gk5i1GhO18WRb2sZTD5UhPgnsJMZhH/uE9rJ/aLju1p65CuS37k9jNTquS0mpBEck6DeQvTOdrZtxojQmmHm9OTfHtOllBF8aMRTksb0giU3KTyDv8gw0p1irAzaVLw9CzWN0nSThmhndqHysOQGdnMkE+3g+5sNnflIk0wqEc5njuru8L0EMNpa5rJ3O5h/TkpnJqftNERqIjScxvd7fgn3edpy2MhgZq3WEXwNoiE1XpI4JGI4wGB8bsk/22v21PMtyrVXN0oIwrVT+jMq4iT7vfCifWR9aqh+JmRXkOZvwI89QpRr+Eq2SDlxR7niZqUIJepcBa9Hx1fcMyf7NKswJRi/6rM5+voiFEOV3M8awwM7weBXv7jJMUpM2ZO9Gy72gTBeFvgL7HODU06uZfj/Rfz4VqMVhF8sQ3p22sZ1rjkyaghzV2BVzK6G5/37H3qvzrrsW604oWAijGFkcOp6fduK7wV2AW+/qMkHyfeVzP1829Lvdjxoe7OjoN4aLnygfkEcZiNyNDuCfG/aOAEgxeTR5GXVEPI3Nwk/yDm/wxrdCBAspp+6Z+PiS4Phq6mqsUN9q8IBc67ET/USi8uT05elS/Kh4pHnTGCHqgdexUOYOmH2jVshG3LUeyCZa9Agohl5MkxwLjdjvWJDu0XfdaHIESqCaocskhTCFYymIlM3LkoTfWjHOJfedmM88GuK/MJOU/0fK35rIV2hmzIeXRZG1kxjR8xz3RmJECiWIiBoyBr+5oQpLW+UOoG34eWT2jFM97BjR1RlQ4tq7QYCJay346itBZxn7bkHf29WrBqypVTz2x2tgss8FOOUBOmRL/A5X1/9W7Ht0flaVodT68Qj4ekba/QF3DV6rA1M6zCUnCnMKa5UBlBnoPRQKbOhyqfTTKfHcYGnzTdpIrs9JoEw7Ff7RyJnaxA20w/G02pP3tdTZ0USYDtCaUk80w+3/0NLZzAnS2tM3YIGUKDnzekwCb0FWeEGpYjUAsDAJ1AlJy/rjcdo3t6rtss/SQtTJ60uIwSOXt7aXtPY4Yuax6X3r/LDjKg==)
|
|
8
|
+
:replies:
|
|
9
|
+
- :author: craigontour
|
|
10
|
+
:url: https://www.reddit.com/r/adventofcode/comments/1phywvn/2025_day_9_solutions/nw082oo
|
|
11
|
+
:body: |-
|
|
12
|
+
Struggled with part2, so looked at your solution for tips, but when I run I get "undefined local variable or method 'it'". What do you do different for 'it' to work?
|
|
13
|
+
|
|
14
|
+
[Edit] It see it's supported in 3.4.
|
|
15
|
+
:replies:
|
|
16
|
+
- :author: _tfa
|
|
17
|
+
:url: https://www.reddit.com/r/adventofcode/comments/1phywvn/2025_day_9_solutions/nw0e9ft
|
|
18
|
+
:body: That's right. You have to update Ruby.
|
|
19
|
+
:replies: []
|
|
20
|
+
- :author: xr51z
|
|
21
|
+
:url: https://www.reddit.com/r/adventofcode/comments/1phywvn/2025_day_9_solutions/nt7uca8
|
|
22
|
+
:body: |-
|
|
23
|
+
[Link](https://topaz.github.io/paste/#XQAAAQDOCQAAAAAAAAA5GUqKNoFH6SMqoVC09YUYoyM0HaPFXythHlAP4pnJzZ/mGYNycp42xxVNhQ0tL4RBJLGPO5bk+V0PGuI9TwnUwUp1Z/rgB5cXuK6002ovOWs3hT/F3Xi18HNzcrRtXCNQbXSr0Nr9o9OhD1grYOkQbPSDkUpFxHF/rIA2YhN2zmcsbxJ4E6mXXdWTACvNlSAp1hhbSbcWfkbKwkUT++y62UfIJ26s2pgajxJE7yDUb56tSqH/F/VCGFJ5ps6Pxnwr1+7/JtBNGW15Ru/gLfk+8oKJnUaH6NHv9jAHo1mwVWoPnHy4PKDAQ1Uey+pM8Q3LSiWWGuvUaPZ8LDiO73DhamUylLxCo7kZKPt0EDl/fGlsoLsxMhm4BkQY9izQmVVYlo8vqsYLkznXDaKmgqJq4bAhEm2pu1xUy7GaHtTBdgIG4yb7lCZzLj/Bxp35YpxyP64glLpEWR2fY0reypQGY1o989ghmxXKbFvfBuuKWTnOg8KouNO10TiRUxkgkHje02hq7IqDU7Za7yQvvvUElxXsGRB1dnK5F80O1f/xrLlHJWIVLCYPJIZIx6+axxSLMjiD2GvBvznqVb+3YdDddXvrS7KnoJBSqRuHcHjUW7UcJMxKQx1yQE97mJHBFZJjFsCQYyw+cpD0ak3KQoj/YT0qIVBXDRSacDTjEb995fPlCAOok0cFWpuQu1KMeSG+BGoHUJcRqilkqncmlQ/gROU/mISTNuh0uczMwwVgBT0uFMzXFMGZvwxssm21HJ5Mpm8JM+kbawMRxp5Kw8JCZN+3dOoXWflshvBclC4ene1xpOrm9jQ+fW7vKwnN/e5sTFE21j5MEo3RENT6fUB+ecg5uSqxqcIrMWo+ulnGlvIfuDGbqPp6JLV4b3Ztap+2mOWoUpjQEGykJJCn6y1S2FLNs/IYV6JGZrNjVKZKHcJs3hqlGbvVmp1mczI4uhTEHwH02SvpAlOUCJefRu2KHC93W1d9dKTEHrbtpN/yQNz6kOftUW5zNHiHZwWpBqNxen5W1wS2YNl9jiHANPGe8eUdGiXjcO5uRwv/thXWEDFb6bs2tmlheTNZFReCnRJXHTmAjXbKsQG1ZHp+Fo7+cP1wXGUyoEv/qDs7Lg==)
|
|
24
|
+
|
|
25
|
+
Definitely hardest one so far. Part 1 was super easy, part 2 kept me up until 3AM. At least I got a script that shouldn't take over 30 minutes to find the solution, ahem. Good night.
|
|
26
|
+
:replies: []
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
---
|
|
2
|
+
- :author: _tfa
|
|
3
|
+
:url: https://www.reddit.com/r/adventofcode/comments/1pity70/2025_day_10_solutions/nudj3n0
|
|
4
|
+
:body: |-
|
|
5
|
+
Part 1:
|
|
6
|
+
|
|
7
|
+
```ruby
|
|
8
|
+
input = File.readlines("input.txt")
|
|
9
|
+
.map{ it.scan(/\[(.+)\] ([()\d,]+)/)}
|
|
10
|
+
.flatten(1)
|
|
11
|
+
.map{ |l,b|
|
|
12
|
+
[
|
|
13
|
+
l.reverse.gsub(?.,?0).gsub(?#,?1).to_i(2),
|
|
14
|
+
b.scan(/\((.+?)\)/).flatten.map{ it.split(?,).map{1 << it.to_i}.reduce(&:|)}
|
|
15
|
+
]
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
puts input.sum {|z,b| 1.upto(b.size).find{|c| b.combination(c).any?{ it.reduce(&:^) == z}} }
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Part 2:
|
|
22
|
+
|
|
23
|
+
That was a tough one. I got inspired by [this thread](https://www.reddit.com/r/adventofcode/comments/1pk87hl/2025_day_10_part_2_bifurcate_your_way_to_victory/): [Paste](https://topaz.github.io/paste/#XQAAAQBuBwAAAAAAAAA0m4poOBCMftdkRQiciXYGFBdLcr8czW9TNbult1FTw8hi7RjuG3N7nWSKl+Ojw06rUyBOmI9nnOAUVyMm5QlJapUyR9NlpWwZzKsITW+HqmGVBBpKCGEi39GLox2a7Q2is/by5448BGD5LaYgscEy76hSq2fSfZNLSCqj1b2rFlLwTcx4s+R9zyHBaTUGS5CuL4vPbxRBmK9TSXz4CrYBsjGJ6q19eJZyWCOqKUAWS5SFPahQUQsYY2OWLBFQUCD5QJOsfhbn8KaypJQWP3X6QQEWfLWjWt3y/bulu9coB1hORtBAsN3p556Ibi2/Flrzpk29Ku1diBrfIG3Pv4GmP7QGBgfhNhXMorUeni+zHGgsRNzeNuDiaR4A/2ZAXc79BgQWYov+u0Mg7+j3WUYwtWBkV0f+5czVTchDZr9uAytgZ8pURAM91yYxLcZdpQ/So/oup3Hwvsuj/JmN2esbuAh64l5hzqhgiBW4DLJbAgutb46rq+LXodg00A4Ze5RvaMQUPthJWJeCkhTT312nJsZV3yMIi3ZHxYRVa/7kwyo2OdXQZJVc3w8Wz1KmbVdOdWpfplcftf68nXBkgC63SSAktBtF+6tIgV2fwHBcfnlVOwEIZ4MxxdN2dC+2Eowf7wBr7CaWV+QQCptGgUM6woqi6xE9RmBuk+rfBELDrcxkoy7MZlHoUPHjWm8HnHoQ9oEUMMyCUktfjBwApikIPUQbbeXtonl/LbSV24mJ9BAtNiZJtV9lxXQCgXd2eoKogoe2aQz8p1+CN8nCEZg4MWbXe3cQMVr6d1jZEyJDlk5y8ZudZ3MBmIh0D7LpUF9DBtKvBkAYN/peVQAmmSw8rBiSSwyhnIi1ig/w4YCjxE3CaPsiUCCOw1tRjMMZWYIBMbqpyIRFZFgAhMgg6jmy1U/lTgZ4s7LO7Bdsc+rY70TkynHUOjweCgVdLWOCOy266g+TrZAUaBci/uKJO3kfD37TUT00ceL/xiss5FvDGZlFOEZlAbEY9Gu+JQJKzukIh/xHLe4=)
|
|
24
|
+
:replies: []
|
|
25
|
+
- :author: xr51z
|
|
26
|
+
:url: https://www.reddit.com/r/adventofcode/comments/1pity70/2025_day_10_solutions/ntctd7p
|
|
27
|
+
:body: |-
|
|
28
|
+
[LINK](https://topaz.github.io/paste/#XQAAAQBnBAAAAAAAAAA0m4poOBCMftdkRQicgxqzrJtesqtO5HNoJyV8IUlraV1wGhmrxaU8vq+N/svmLBfE4aEwMN6Edw7/eQI/cYcwlyLfkogF0+1QwXfgUz3OzIQ6fs4vW8poF3IpWH3gZFRPWy7CKBQx0mPB8cZZZvaYtPl3PPtdL//aSIAbg0OGUir3CbK+c8PpiJ5gaGEzHVRblYJVc5LF+bq9LwL9Hcq8v6C+JwHoUCcIdJoYRT0RkNpo1jbEJ+SKS14FMm3HYzsNF0D0KMt3U5Z7d4w2gIX+lJP/iEZx2eU16l+bL3LbmCQOrW1nK0OV52u2YR0u0xlRtoVK2WsAxFiklno+kZBEjpOyTqjos+v7P86Fm6C+c1qx1CFvhfUFDlD0yGABl/Xu91UufiSOUbkKE8VEnN9xk6nUq+tR4YUPLZmrIV/hU6nOGtasWbv/SNhV2G0juL8aS6O7v0PXeXc2TxPA0IFrvPB/XfWxq3eScswOxw+dkXhpnSk1Ud8L8jj6g0litGuZ2Otx9t3zdr8QCqsxBSBaTkQv5vUx823pXxh6oRan9LUtGWZNBhWapixYFVn2GW2S0yWvq8SaVxpGS/lFJcfhTgOmTm2Zi1pg6jOujLXwV9mIgYjA0gxWO1xBow9xP5r5psahBZ4Anqvw7nqnr/3WhWo=) (part 1 only)
|
|
29
|
+
|
|
30
|
+
I am not a programmer, just a 30s-something guy who decide to learn coding earlier this year, and today I am defeated for the first time this AoC.
|
|
31
|
+
|
|
32
|
+
Part 1 went really well, I had the solution after about 20 minutes. However, I've been chewing on part 2 for hours now and I've decided to give up. I wanted to write my own algorithm (lol) but failed, then investigated this (to me unbeknownst) Z3 thing everyone's talking about, but decided to call it a day. You win, elves!
|
|
33
|
+
:replies:
|
|
34
|
+
- :author: flwyd
|
|
35
|
+
:url: https://www.reddit.com/r/adventofcode/comments/1pity70/2025_day_10_solutions/nwj1dec
|
|
36
|
+
:body: If it makes you feel any better, I _am_ a professional programmer and it took me two weeks to fully solve part 2.
|
|
37
|
+
:replies: []
|
|
38
|
+
- :author: ChupeDeJaiba
|
|
39
|
+
:url: https://www.reddit.com/r/adventofcode/comments/1pity70/2025_day_10_solutions/ntdfawe
|
|
40
|
+
:body: |-
|
|
41
|
+
I loled at the `puts "Part 2: ", "ERROR: brain too small"`
|
|
42
|
+
|
|
43
|
+
A few suggestions from a fellow ruby enthusiast (?)
|
|
44
|
+
|
|
45
|
+
Since only the min amount of button presses is needed, I think that changing `buttons.length.downto(1)` to `1.upto(buttons.length)` will allow you to exit as soon as a sequence reaches the end state instead of going trough all combinations. Something like `Enumerable#find`
|
|
46
|
+
|
|
47
|
+
To avoid being `#hacky` you can use `Float::INFINITY` as an initial minpresses value
|
|
48
|
+
|
|
49
|
+
Look into `String#scan` and some REGEX for input parsing, is pretty useful for AoC
|
|
50
|
+
:replies: []
|
|
51
|
+
- :author: Sharparam
|
|
52
|
+
:url: https://www.reddit.com/r/adventofcode/comments/1pity70/2025_day_10_solutions/nt9vc46
|
|
53
|
+
:body: |-
|
|
54
|
+
[LANGUAGE: Python]
|
|
55
|
+
|
|
56
|
+
[Did part 1 in Ruby](https://github.com/Sharparam/advent-of-code/blob/main/src/y2025/d10/solve.rb), and then had to admit defeat and [use Python and Z3 for part 2](https://github.com/Sharparam/advent-of-code/blob/main/src/y2025/d10/sandbox.ipynb).
|
|
57
|
+
|
|
58
|
+
Makes me wish there were Z3 bindings for Ruby that are not in ["very early stages of development"](https://github.com/taw/z3).
|
|
59
|
+
:replies:
|
|
60
|
+
- :author: firetech_SE
|
|
61
|
+
:url: https://www.reddit.com/r/adventofcode/comments/1pity70/2025_day_10_solutions/ntawa5m
|
|
62
|
+
:body: |-
|
|
63
|
+
They might be in early stages, but they are still [perfectly usable](https://github.com/firetech/advent-of-code/blob/0fb1c0178b4b6250487f0a6fbf0191e4331471e4/2025/10/factory_z3.rb). ;)
|
|
64
|
+
|
|
65
|
+
My first instance of using it was three years ago, in 2022, and I've never had any issues (except that just `require 'z3'` slows down general Ruby a bit due to [some hacks](https://github.com/taw/z3/blob/master/lib/z3/hacks.rb)).
|
|
66
|
+
:replies:
|
|
67
|
+
- :author: Sharparam
|
|
68
|
+
:url: https://www.reddit.com/r/adventofcode/comments/1pity70/2025_day_10_solutions/ntbxsc5
|
|
69
|
+
:body: |-
|
|
70
|
+
Oh that is some good news, thank you for pointing it out!
|
|
71
|
+
|
|
72
|
+
One less thing to need Python for :)
|
|
73
|
+
:replies: []
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
---
|
|
2
|
+
- :author: _tfa
|
|
3
|
+
:url: https://www.reddit.com/r/adventofcode/comments/1pjp1rm/2025_day_11_solutions/nuhk3ir
|
|
4
|
+
:body: |-
|
|
5
|
+
Part 1:
|
|
6
|
+
|
|
7
|
+
```ruby
|
|
8
|
+
TREE = File.readlines("input.txt").map{ it.scan(/(...): (.*)/)}
|
|
9
|
+
.flatten(1)
|
|
10
|
+
.map{|node, neighbours| [node, neighbours.split]}
|
|
11
|
+
.to_h
|
|
12
|
+
|
|
13
|
+
def solve(node, target)
|
|
14
|
+
return 1 if node == target
|
|
15
|
+
TREE[node].map{solve(it, target)}.sum
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
puts solve("you", "out")
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Part 2: [Paste](https://topaz.github.io/paste/#XQAAAQCOBAAAAAAAAAAjlIQlg38G5hKsB77A1DF67Y2pXyBxCQxuOlWiLUsdIzsv54a3zV6twiVZqW2FXkkywX+ffAsHE8J3i577QRXKM41LIbMWodpfzMUo4t9RF0MC9/m3xRkqkvdZSIinGyZ6W2o1DRGBIqjxIxSWj1wrgJSqVePXJ72kVvxtShjBDheqGFW9MJIFxoN+hCbSoxWHOSXDN/B7fLfBt2m5z36Pnyqw6xXNUtYjpafCmRrsMiT/wuuhLeOsl77OwEEwGc8E49VpTjDYdQI2/Ob8VxU0xrz5G8UP3EKRd3Njg6Mqlk9+zA/Eoobn1P3k2Wh3pnFkjVRm0L/dY/LZx9QxjyjfIWVzY6wX/KqCWUPUdYZZFmYP/yR8SemlPO0TAlZarFK1DwD9s6xIrL+9JeVXhf8RKSQpQkVR1UuohNiGQpeEX3/7lrrYYqiCjh/ulhfupd+wcZyxNAabEM7wNosTX5uf5zwmvj4H42qOA6y36+UzvlCHNVjKIVzFGlGynfqTVnltRkZDFHsu6I8gyMBZJ+T0mOgsFfJ8LvfrhPVCfBh0HX2DKCtdi6Zx8j51HnvwSnOB+VXAxmiGyi+CsPLmQ1AglO3dDeSTyX2Xq+IiSGoxptLHBD6vmCGIKxfakjirmo3WU7AVHv7DLzlQ6Z2CRZ7MPzTY5iMk3tuxQfwAisEw/rKk3ZNKaorv68obMOXW84/9uw+EoeX/3YN+4w==)
|
|
22
|
+
:replies: []
|
|
23
|
+
- :author: srugh
|
|
24
|
+
:url: https://www.reddit.com/r/adventofcode/comments/1pjp1rm/2025_day_11_solutions/nti5say
|
|
25
|
+
:body: |-
|
|
26
|
+
Part 1 - basic recursive dfs counting paths, nothing fancy at all.
|
|
27
|
+
|
|
28
|
+
Part 2 - DP on a DAG using memo and filters.
|
|
29
|
+
|
|
30
|
+
[GitHub for both part 1 and part 2](https://github.com/srugh/AdventOfCode/blob/main/2025/day-11.rb)
|
|
31
|
+
:replies: []
|
|
32
|
+
- :author: notathrowaway0983
|
|
33
|
+
:url: https://www.reddit.com/r/adventofcode/comments/1pjp1rm/2025_day_11_solutions/ntgbu1d
|
|
34
|
+
:body: |-
|
|
35
|
+
Pretty happy with my 100ms, given I only know about graphs that they have nodes and you can kinda move from one to another. Here I assume no cycles, but `fft` and `dac` can be an any order. Also works good when there are more nodes to visit, found solutions (or lack of them, output contains separate counts for all possible paths) for 30 nodes in 12 seconds.
|
|
36
|
+
|
|
37
|
+
```ruby
|
|
38
|
+
require "set"
|
|
39
|
+
|
|
40
|
+
$nodes = input.lines.to_h do |l|
|
|
41
|
+
from, *to = l.chomp.split(" ")
|
|
42
|
+
[from[0..-2], to]
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
$memory = Hash.new
|
|
46
|
+
$to_visit = ["fft", "dac"].to_set
|
|
47
|
+
$nothing = Set.new
|
|
48
|
+
|
|
49
|
+
def count_paths(node)
|
|
50
|
+
return { $nothing => 1 } if node == "out"
|
|
51
|
+
return $memory[node] if $memory[node]
|
|
52
|
+
|
|
53
|
+
child_counts = $nodes[node]
|
|
54
|
+
.map { |n| count_paths(n) }
|
|
55
|
+
.reduce do |s, e|
|
|
56
|
+
s.merge(e) { |_, a, b| a + b }
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
if $to_visit.include? node
|
|
60
|
+
child_counts = child_counts.to_h { |k,v| [k + [node], v]}
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
$memory[node] = child_counts
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
pp count_paths("you")
|
|
67
|
+
pp count_paths("svr")
|
|
68
|
+
```
|
|
69
|
+
:replies: []
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
--- []
|
data/lib/arb/arb.rb
CHANGED
data/lib/arb/cli/bootstrap.rb
CHANGED
|
@@ -5,7 +5,7 @@ module Arb
|
|
|
5
5
|
def self.bootstrap(year: nil, day: nil)
|
|
6
6
|
WorkingDirectory.prepare!
|
|
7
7
|
|
|
8
|
-
year, day = YearDayValidator.
|
|
8
|
+
year, day = YearDayValidator.validate_and_fill_in_year_and_day(year:, day:)
|
|
9
9
|
|
|
10
10
|
instructions_path = Files::Instructions.download(year:, day:)
|
|
11
11
|
others_1_path, others_2_path = Files::OtherSolutions.download(year:, day:)
|
data/lib/arb/cli/commit.rb
CHANGED
|
@@ -26,7 +26,7 @@ module Arb
|
|
|
26
26
|
Git.commit!(filenames:, message:)
|
|
27
27
|
|
|
28
28
|
# TODO less naive check: ensure prev. days are finished too
|
|
29
|
-
if !files_modified && day == "
|
|
29
|
+
if !files_modified && day == Util.max_day(year:).to_s.rjust(2, "0")
|
|
30
30
|
puts
|
|
31
31
|
puts "🎉 You've finished #{year}!"
|
|
32
32
|
puts
|
data/lib/arb/cli/progress.rb
CHANGED
|
@@ -7,6 +7,7 @@ module Arb
|
|
|
7
7
|
|
|
8
8
|
total_count = committed.values.sum(&:count)
|
|
9
9
|
my_counts_by_year = committed
|
|
10
|
+
.transform_keys(&:to_i)
|
|
10
11
|
.transform_values { it.values.count(&:itself) }
|
|
11
12
|
.reject { |k, v| v.zero? }
|
|
12
13
|
my_total_count = my_counts_by_year.values.sum
|
|
@@ -20,16 +21,11 @@ module Arb
|
|
|
20
21
|
puts
|
|
21
22
|
|
|
22
23
|
my_counts_by_year.each do |year, my_count|
|
|
23
|
-
|
|
24
|
-
if year.to_i == Date.today.year
|
|
25
|
-
this_year_count
|
|
26
|
-
else
|
|
27
|
-
25
|
|
28
|
-
end
|
|
24
|
+
max_day = Util.years_and_max_days[year]
|
|
29
25
|
|
|
30
|
-
year_percent = (my_count.to_f /
|
|
26
|
+
year_percent = (my_count.to_f / max_day * 100).round
|
|
31
27
|
|
|
32
|
-
puts "#{PASTEL.blue("#{year}:")}\t#{year_percent}%\t#{my_count}/#{
|
|
28
|
+
puts "#{PASTEL.blue("#{year}:")}\t#{year_percent}%\t#{my_count}/#{max_day}"
|
|
33
29
|
end
|
|
34
30
|
end
|
|
35
31
|
end
|
data/lib/arb/cli/run.rb
CHANGED
|
@@ -10,7 +10,7 @@ module Arb
|
|
|
10
10
|
raise InputError, "Don't use --spec (-s) with --one (-o) or --two (-t)"
|
|
11
11
|
end
|
|
12
12
|
|
|
13
|
-
year, day = YearDayValidator.
|
|
13
|
+
year, day = YearDayValidator.validate_and_fill_in_year_and_day(year:, day:, default_to_untracked_or_last_committed: true)
|
|
14
14
|
|
|
15
15
|
if Git.uncommitted_puzzles.empty? && !Git.last_committed_puzzle(year:)
|
|
16
16
|
bootstrap(year:, day:)
|
data/lib/arb/cli/shared/git.rb
CHANGED
|
@@ -52,10 +52,9 @@ module Arb
|
|
|
52
52
|
def self.committed_by_year
|
|
53
53
|
committed_solution_files = `git log --diff-filter=A --name-only --pretty=format: src`
|
|
54
54
|
|
|
55
|
-
previous_days =
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
end
|
|
55
|
+
previous_days = Util.years_and_max_days.transform_values { |max_day|
|
|
56
|
+
(1..max_day).to_a
|
|
57
|
+
}
|
|
59
58
|
|
|
60
59
|
committed_days = committed_solution_files
|
|
61
60
|
.split("\n")
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
module Arb
|
|
2
2
|
module Cli
|
|
3
3
|
class YearDayValidator
|
|
4
|
-
def self.
|
|
4
|
+
def self.validate_and_fill_in_year_and_day(year:, day:, default_to_untracked_or_last_committed: false)
|
|
5
5
|
year, day = year&.to_s, day&.to_s&.rjust(2, "0")
|
|
6
6
|
|
|
7
7
|
# The first two digits of the year may be omitted.
|
|
@@ -22,7 +22,7 @@ module Arb
|
|
|
22
22
|
|
|
23
23
|
if day && !default_to_untracked_or_last_committed
|
|
24
24
|
day =
|
|
25
|
-
if day == "
|
|
25
|
+
if day == Util.max_day(year:).to_s.rjust(2, "0")
|
|
26
26
|
:end
|
|
27
27
|
else
|
|
28
28
|
day.next
|
|
@@ -73,12 +73,7 @@ module Arb
|
|
|
73
73
|
year = Integer(year, exception: false) || (raise InputError, "Year must be a number.")
|
|
74
74
|
day = Integer(day.delete_prefix("0"), exception: false) || (raise InputError, "Day must be a number.")
|
|
75
75
|
|
|
76
|
-
|
|
77
|
-
raise InputError, "Year must be between 2015 and this year."
|
|
78
|
-
end
|
|
79
|
-
unless day.between?(1, 25) && Date.new(year, 12, day) <= Date.today
|
|
80
|
-
raise InputError, "Day must be between 1 and 25, and <= today."
|
|
81
|
-
end
|
|
76
|
+
Util.validate_year_and_day(year:, day:)
|
|
82
77
|
|
|
83
78
|
[year.to_s, day.to_s.rjust(2, "0")]
|
|
84
79
|
end
|
data/lib/arb/files/spec.rb
CHANGED
|
@@ -30,11 +30,11 @@ module Arb
|
|
|
30
30
|
end
|
|
31
31
|
|
|
32
32
|
it "solves Part One" do
|
|
33
|
-
expect(subject.part_1(input)).to eq
|
|
33
|
+
expect(subject.part_1(input)).to eq :todo
|
|
34
34
|
end
|
|
35
35
|
|
|
36
36
|
xit "solves Part Two" do
|
|
37
|
-
expect(subject.part_2(input)).to eq
|
|
37
|
+
expect(subject.part_2(input)).to eq :todo
|
|
38
38
|
end
|
|
39
39
|
end
|
|
40
40
|
END_OUTER
|
|
@@ -1,24 +1,31 @@
|
|
|
1
1
|
module Formatters
|
|
2
2
|
module RuboCop
|
|
3
3
|
# Formats newly created files using RuboCop if it is bundled at the top
|
|
4
|
-
# level
|
|
5
|
-
# isn't bundled or is just a dependency
|
|
4
|
+
# level (i.e. as `gem "rubocop"` in the Gemfile) or if a RuboCop config file
|
|
5
|
+
# is present. Does nothing if RuboCop isn't bundled or is just a dependency
|
|
6
|
+
# (e.g. of Standard), and if there is no RuboCop config file.
|
|
6
7
|
def self.format(file_path)
|
|
7
|
-
|
|
8
|
+
require "bundler"
|
|
9
|
+
require "rubocop"
|
|
10
|
+
return unless rubocop_bundled_at_top_level? || rubocop_config_exists?
|
|
8
11
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
# Do nothing if RuboCop is bundled but not actually installed.
|
|
14
|
-
end
|
|
12
|
+
::RuboCop::CLI.new.run(["-A", file_path, "--out", File::NULL])
|
|
13
|
+
rescue LoadError
|
|
14
|
+
# Do nothing if Bundler is not installed, or if RuboCop is bundled but not
|
|
15
|
+
# actually installed.
|
|
15
16
|
end
|
|
16
17
|
|
|
17
18
|
private_class_method def self.rubocop_bundled_at_top_level?
|
|
18
|
-
require "bundler"
|
|
19
19
|
Bundler.definition.dependencies.any? { it.name == "rubocop" }
|
|
20
|
-
rescue
|
|
20
|
+
rescue Bundler::GemfileNotFound
|
|
21
21
|
false
|
|
22
22
|
end
|
|
23
|
+
|
|
24
|
+
# A shorter approach would be simply `File.exist?(".rubocop.yml")`, but
|
|
25
|
+
# the approach below avoids directly reading a file.
|
|
26
|
+
private_class_method def self.rubocop_config_exists?
|
|
27
|
+
config_path = ::RuboCop::ConfigFinder.find_config_path(Dir.pwd)
|
|
28
|
+
config_path && !config_path.end_with?("config/default.yml")
|
|
29
|
+
end
|
|
23
30
|
end
|
|
24
31
|
end
|