advent_of_ruby 0.3.5 → 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.
Files changed (212) hide show
  1. checksums.yaml +4 -4
  2. data/data/solutions/github/ZogStriP/2024/01_1.yml +1 -0
  3. data/data/solutions/github/ZogStriP/2024/01_2.yml +7 -0
  4. data/data/solutions/github/ZogStriP/2024/02_1.yml +1 -0
  5. data/data/solutions/github/ZogStriP/2024/02_2.yml +9 -0
  6. data/data/solutions/github/ZogStriP/2024/03_1.yml +1 -0
  7. data/data/solutions/github/ZogStriP/2024/03_2.yml +7 -0
  8. data/data/solutions/github/ZogStriP/2024/04_1.yml +1 -0
  9. data/data/solutions/github/ZogStriP/2024/04_2.yml +15 -0
  10. data/data/solutions/github/ZogStriP/2024/05_1.yml +1 -0
  11. data/data/solutions/github/ZogStriP/2024/05_2.yml +16 -0
  12. data/data/solutions/github/ZogStriP/2024/06_1.yml +1 -0
  13. data/data/solutions/github/ZogStriP/2024/06_2.yml +38 -0
  14. data/data/solutions/github/ZogStriP/2024/07_1.yml +1 -0
  15. data/data/solutions/github/ZogStriP/2024/07_2.yml +9 -0
  16. data/data/solutions/github/ZogStriP/2024/08_1.yml +1 -0
  17. data/data/solutions/github/ZogStriP/2024/08_2.yml +27 -0
  18. data/data/solutions/github/ZogStriP/2024/09_1.yml +1 -0
  19. data/data/solutions/github/ZogStriP/2024/09_2.yml +1 -0
  20. data/data/solutions/github/ZogStriP/2024/10_1.yml +1 -0
  21. data/data/solutions/github/ZogStriP/2024/10_2.yml +1 -0
  22. data/data/solutions/github/ZogStriP/2024/11_1.yml +1 -0
  23. data/data/solutions/github/ZogStriP/2024/11_2.yml +1 -0
  24. data/data/solutions/github/ZogStriP/2024/12_1.yml +1 -0
  25. data/data/solutions/github/ZogStriP/2024/12_2.yml +1 -0
  26. data/data/solutions/github/ZogStriP/2024/13_1.yml +1 -0
  27. data/data/solutions/github/ZogStriP/2024/13_2.yml +1 -0
  28. data/data/solutions/github/ZogStriP/2024/14_1.yml +1 -0
  29. data/data/solutions/github/ZogStriP/2024/14_2.yml +1 -0
  30. data/data/solutions/github/ZogStriP/2024/15_1.yml +1 -0
  31. data/data/solutions/github/ZogStriP/2024/15_2.yml +1 -0
  32. data/data/solutions/github/ZogStriP/2024/16_1.yml +1 -0
  33. data/data/solutions/github/ZogStriP/2024/16_2.yml +1 -0
  34. data/data/solutions/github/ZogStriP/2024/17_1.yml +1 -0
  35. data/data/solutions/github/ZogStriP/2024/17_2.yml +1 -0
  36. data/data/solutions/github/ZogStriP/2024/18_1.yml +1 -0
  37. data/data/solutions/github/ZogStriP/2024/18_2.yml +1 -0
  38. data/data/solutions/github/ZogStriP/2024/19_1.yml +1 -0
  39. data/data/solutions/github/ZogStriP/2024/19_2.yml +1 -0
  40. data/data/solutions/github/ZogStriP/2024/20_1.yml +1 -0
  41. data/data/solutions/github/ZogStriP/2024/20_2.yml +1 -0
  42. data/data/solutions/github/ZogStriP/2024/21_1.yml +1 -0
  43. data/data/solutions/github/ZogStriP/2024/21_2.yml +1 -0
  44. data/data/solutions/github/ZogStriP/2024/22_1.yml +1 -0
  45. data/data/solutions/github/ZogStriP/2024/22_2.yml +1 -0
  46. data/data/solutions/github/ZogStriP/2024/23_1.yml +1 -0
  47. data/data/solutions/github/ZogStriP/2024/23_2.yml +1 -0
  48. data/data/solutions/github/ZogStriP/2024/24_1.yml +1 -0
  49. data/data/solutions/github/ZogStriP/2024/24_2.yml +1 -0
  50. data/data/solutions/github/ZogStriP/2024/25_1.yml +1 -0
  51. data/data/solutions/github/ZogStriP/2025/01_1.yml +1 -0
  52. data/data/solutions/github/ZogStriP/2025/01_2.yml +1 -0
  53. data/data/solutions/github/ZogStriP/2025/02_1.yml +1 -0
  54. data/data/solutions/github/ZogStriP/2025/02_2.yml +1 -0
  55. data/data/solutions/github/ZogStriP/2025/03_1.yml +1 -0
  56. data/data/solutions/github/ZogStriP/2025/03_2.yml +1 -0
  57. data/data/solutions/github/ZogStriP/2025/04_1.yml +1 -0
  58. data/data/solutions/github/ZogStriP/2025/04_2.yml +1 -0
  59. data/data/solutions/github/ZogStriP/2025/05_1.yml +1 -0
  60. data/data/solutions/github/ZogStriP/2025/05_2.yml +1 -0
  61. data/data/solutions/github/ZogStriP/2025/06_1.yml +1 -0
  62. data/data/solutions/github/ZogStriP/2025/06_2.yml +1 -0
  63. data/data/solutions/github/ZogStriP/2025/07_1.yml +1 -0
  64. data/data/solutions/github/ZogStriP/2025/07_2.yml +1 -0
  65. data/data/solutions/github/ZogStriP/2025/08_1.yml +1 -0
  66. data/data/solutions/github/ZogStriP/2025/08_2.yml +1 -0
  67. data/data/solutions/github/ZogStriP/2025/09_1.yml +1 -0
  68. data/data/solutions/github/ZogStriP/2025/09_2.yml +1 -0
  69. data/data/solutions/github/ZogStriP/2025/10_1.yml +1 -0
  70. data/data/solutions/github/ZogStriP/2025/10_2.yml +1 -0
  71. data/data/solutions/github/ZogStriP/2025/11_1.yml +1 -0
  72. data/data/solutions/github/ZogStriP/2025/11_2.yml +1 -0
  73. data/data/solutions/github/ZogStriP/2025/12_1.yml +1 -0
  74. data/data/solutions/github/ZogStriP/2025/12_2.yml +1 -0
  75. data/data/solutions/github/ahorner/2025/01_1.yml +1 -0
  76. data/data/solutions/github/ahorner/2025/01_2.yml +37 -0
  77. data/data/solutions/github/ahorner/2025/02_1.yml +1 -0
  78. data/data/solutions/github/ahorner/2025/02_2.yml +41 -0
  79. data/data/solutions/github/ahorner/2025/03_1.yml +1 -0
  80. data/data/solutions/github/ahorner/2025/03_2.yml +24 -0
  81. data/data/solutions/github/ahorner/2025/04_1.yml +1 -0
  82. data/data/solutions/github/ahorner/2025/04_2.yml +39 -0
  83. data/data/solutions/github/ahorner/2025/05_1.yml +1 -0
  84. data/data/solutions/github/ahorner/2025/05_2.yml +48 -0
  85. data/data/solutions/github/ahorner/2025/06_1.yml +1 -0
  86. data/data/solutions/github/ahorner/2025/06_2.yml +44 -0
  87. data/data/solutions/github/ahorner/2025/07_1.yml +1 -0
  88. data/data/solutions/github/ahorner/2025/07_2.yml +56 -0
  89. data/data/solutions/github/ahorner/2025/08_1.yml +1 -0
  90. data/data/solutions/github/ahorner/2025/08_2.yml +59 -0
  91. data/data/solutions/github/ahorner/2025/09_1.yml +1 -0
  92. data/data/solutions/github/ahorner/2025/09_2.yml +101 -0
  93. data/data/solutions/github/ahorner/2025/10_1.yml +1 -0
  94. data/data/solutions/github/ahorner/2025/10_2.yml +72 -0
  95. data/data/solutions/github/ahorner/2025/11_1.yml +1 -0
  96. data/data/solutions/github/ahorner/2025/11_2.yml +45 -0
  97. data/data/solutions/github/ahorner/2025/12_1.yml +1 -0
  98. data/data/solutions/github/eregon/2025/01_1.yml +17 -0
  99. data/data/solutions/github/eregon/2025/01_2.yml +14 -0
  100. data/data/solutions/github/eregon/2025/02_1.yml +22 -0
  101. data/data/solutions/github/eregon/2025/02_2.yml +58 -0
  102. data/data/solutions/github/eregon/2025/03_1.yml +13 -0
  103. data/data/solutions/github/eregon/2025/03_2.yml +13 -0
  104. data/data/solutions/github/eregon/2025/04_1.yml +14 -0
  105. data/data/solutions/github/eregon/2025/04_2.yml +16 -0
  106. data/data/solutions/github/eregon/2025/05_1.yml +1 -0
  107. data/data/solutions/github/eregon/2025/05_2.yml +1 -0
  108. data/data/solutions/github/eregon/2025/06_1.yml +1 -0
  109. data/data/solutions/github/eregon/2025/06_2.yml +1 -0
  110. data/data/solutions/github/eregon/2025/07_1.yml +1 -0
  111. data/data/solutions/github/eregon/2025/07_2.yml +1 -0
  112. data/data/solutions/github/eregon/2025/08_1.yml +1 -0
  113. data/data/solutions/github/eregon/2025/08_2.yml +1 -0
  114. data/data/solutions/github/eregon/2025/09_1.yml +1 -0
  115. data/data/solutions/github/eregon/2025/09_2.yml +1 -0
  116. data/data/solutions/github/eregon/2025/10_1.yml +1 -0
  117. data/data/solutions/github/eregon/2025/10_2.yml +1 -0
  118. data/data/solutions/github/eregon/2025/11_1.yml +1 -0
  119. data/data/solutions/github/eregon/2025/11_2.yml +1 -0
  120. data/data/solutions/github/eregon/2025/12_1.yml +1 -0
  121. data/data/solutions/github/erikw/2025/01_1.yml +1 -0
  122. data/data/solutions/github/erikw/2025/01_2.yml +1 -0
  123. data/data/solutions/github/erikw/2025/02_1.yml +1 -0
  124. data/data/solutions/github/erikw/2025/02_2.yml +1 -0
  125. data/data/solutions/github/erikw/2025/03_1.yml +1 -0
  126. data/data/solutions/github/erikw/2025/03_2.yml +1 -0
  127. data/data/solutions/github/erikw/2025/04_1.yml +1 -0
  128. data/data/solutions/github/erikw/2025/04_2.yml +1 -0
  129. data/data/solutions/github/erikw/2025/05_1.yml +1 -0
  130. data/data/solutions/github/erikw/2025/05_2.yml +1 -0
  131. data/data/solutions/github/erikw/2025/06_1.yml +1 -0
  132. data/data/solutions/github/erikw/2025/06_2.yml +1 -0
  133. data/data/solutions/github/erikw/2025/07_1.yml +1 -0
  134. data/data/solutions/github/erikw/2025/07_2.yml +1 -0
  135. data/data/solutions/github/erikw/2025/08_1.yml +1 -0
  136. data/data/solutions/github/erikw/2025/08_2.yml +1 -0
  137. data/data/solutions/github/erikw/2025/09_1.yml +1 -0
  138. data/data/solutions/github/erikw/2025/09_2.yml +1 -0
  139. data/data/solutions/github/erikw/2025/10_1.yml +1 -0
  140. data/data/solutions/github/erikw/2025/10_2.yml +1 -0
  141. data/data/solutions/github/erikw/2025/11_1.yml +1 -0
  142. data/data/solutions/github/erikw/2025/11_2.yml +1 -0
  143. data/data/solutions/github/erikw/2025/12_1.yml +1 -0
  144. data/data/solutions/github/erikw/2025/12_2.yml +1 -0
  145. data/data/solutions/github/gchan/2025/01_1.yml +25 -0
  146. data/data/solutions/github/gchan/2025/01_2.yml +32 -0
  147. data/data/solutions/github/gchan/2025/02_1.yml +18 -0
  148. data/data/solutions/github/gchan/2025/02_2.yml +21 -0
  149. data/data/solutions/github/gchan/2025/03_1.yml +15 -0
  150. data/data/solutions/github/gchan/2025/03_2.yml +23 -0
  151. data/data/solutions/github/gchan/2025/04_1.yml +27 -0
  152. data/data/solutions/github/gchan/2025/04_2.yml +40 -0
  153. data/data/solutions/github/gchan/2025/05_1.yml +20 -0
  154. data/data/solutions/github/gchan/2025/05_2.yml +36 -0
  155. data/data/solutions/github/gchan/2025/06_1.yml +11 -0
  156. data/data/solutions/github/gchan/2025/06_2.yml +28 -0
  157. data/data/solutions/github/gchan/2025/07_1.yml +33 -0
  158. data/data/solutions/github/gchan/2025/07_2.yml +29 -0
  159. data/data/solutions/github/gchan/2025/08_1.yml +48 -0
  160. data/data/solutions/github/gchan/2025/08_2.yml +48 -0
  161. data/data/solutions/github/gchan/2025/09_1.yml +16 -0
  162. data/data/solutions/github/gchan/2025/09_2.yml +60 -0
  163. data/data/solutions/github/gchan/2025/10_1.yml +49 -0
  164. data/data/solutions/github/gchan/2025/10_2.yml +154 -0
  165. data/data/solutions/github/gchan/2025/11_1.yml +43 -0
  166. data/data/solutions/github/gchan/2025/11_2.yml +33 -0
  167. data/data/solutions/github/gchan/2025/12_1.yml +51 -0
  168. data/data/solutions/reddit/ruby/2017/06.yml +0 -2
  169. data/data/solutions/reddit/ruby/2020/02.yml +0 -1
  170. data/data/solutions/reddit/ruby/2024/02.yml +0 -1
  171. data/data/solutions/reddit/ruby/2025/01.yml +187 -0
  172. data/data/solutions/reddit/ruby/2025/02.yml +185 -0
  173. data/data/solutions/reddit/ruby/2025/03.yml +369 -0
  174. data/data/solutions/reddit/ruby/2025/04.yml +217 -0
  175. data/data/solutions/reddit/ruby/2025/05.yml +324 -0
  176. data/data/solutions/reddit/ruby/2025/06.yml +246 -0
  177. data/data/solutions/reddit/ruby/2025/07.yml +213 -0
  178. data/data/solutions/reddit/ruby/2025/08.yml +73 -0
  179. data/data/solutions/reddit/ruby/2025/09.yml +26 -0
  180. data/data/solutions/reddit/ruby/2025/10.yml +73 -0
  181. data/data/solutions/reddit/ruby/2025/11.yml +69 -0
  182. data/data/solutions/reddit/ruby/2025/12.yml +1 -0
  183. data/lib/arb/arb.rb +0 -5
  184. data/lib/arb/cli/bootstrap.rb +1 -1
  185. data/lib/arb/cli/commit.rb +1 -1
  186. data/lib/arb/cli/progress.rb +4 -8
  187. data/lib/arb/cli/run.rb +1 -1
  188. data/lib/arb/cli/shared/git.rb +3 -4
  189. data/lib/arb/cli/shared/year_day_validator.rb +3 -8
  190. data/lib/arb/files/spec.rb +2 -2
  191. data/lib/arb/util.rb +58 -0
  192. data/lib/arb/version.rb +1 -1
  193. metadata +184 -23
  194. data/lib/download_solutions/api/github/repos.rb +0 -54
  195. data/lib/download_solutions/api/github.rb +0 -164
  196. data/lib/download_solutions/api/reddit/add_missing_replies.rb +0 -43
  197. data/lib/download_solutions/api/reddit/clean_bodies.rb +0 -64
  198. data/lib/download_solutions/api/reddit/filter_by_language.rb +0 -32
  199. data/lib/download_solutions/api/reddit/get_initial_response.rb +0 -30
  200. data/lib/download_solutions/api/reddit/get_serial_comments.rb +0 -145
  201. data/lib/download_solutions/api/reddit/megathread_ids.rb +0 -19
  202. data/lib/download_solutions/api/reddit/params.rb +0 -40
  203. data/lib/download_solutions/api/reddit/reject_unwanted_replies.rb +0 -31
  204. data/lib/download_solutions/api/reddit/remove_ids.rb +0 -26
  205. data/lib/download_solutions/api/reddit/remove_language_tags.rb +0 -29
  206. data/lib/download_solutions/api/reddit.rb +0 -101
  207. data/lib/download_solutions/cli/cli/shared.rb +0 -35
  208. data/lib/download_solutions/cli/github.rb +0 -107
  209. data/lib/download_solutions/cli/reddit.rb +0 -64
  210. data/lib/download_solutions/download_solutions.rb +0 -18
  211. data/lib/download_solutions/reverse_markdown/converters/br.rb +0 -15
  212. data/lib/download_solutions/reverse_markdown/converters/pre.rb +0 -46
@@ -0,0 +1,369 @@
1
+ ---
2
+ - :author: StillFast7545
3
+ :url: https://www.reddit.com/r/adventofcode/comments/1pcvaj4/2025_day_3_solutions/nskw3ne
4
+ :body: |-
5
+ Part 1: [https://github.com/MarioPerac/AdventOfCode2025/blob/main/day\_3/lobby\_part\_1.rb](https://github.com/MarioPerac/AdventOfCode2025/blob/main/day_3/lobby_part_1.rb)
6
+
7
+ Part 2: [https://github.com/MarioPerac/AdventOfCode2025/blob/main/day\_3/lobby\_part\_2.rb](https://github.com/MarioPerac/AdventOfCode2025/blob/main/day_3/lobby_part_2.rb)
8
+ :replies: []
9
+ - :author: _tfa
10
+ :url: https://www.reddit.com/r/adventofcode/comments/1pcvaj4/2025_day_3_solutions/ns7xmkh
11
+ :body: |-
12
+ ```ruby
13
+ input = File.readlines("input.txt", chomp: true)
14
+
15
+ def solve(source, digits, result="")
16
+ return result if result.length == digits
17
+
18
+ chunk = source[..result.length - digits]
19
+ i = chunk.index(chunk.chars.max)
20
+ solve(source[i+1..], digits, result+source[i])
21
+ end
22
+
23
+ puts input.sum{ solve(it, 2).to_i }
24
+ puts input.sum{ solve(it, 12).to_i }
25
+ ```
26
+ :replies: []
27
+ - :author: SleepingInsomniac
28
+ :url: https://www.reddit.com/r/adventofcode/comments/1pcvaj4/2025_day_3_solutions/ns6trgt
29
+ :body: |-
30
+ https://asciinema.org/a/vFZ0jkcQ4wAPhLVFvY3v391i9 https://github.com/SleepingInsomniac/adventofcode/blob/master/2025-12-03/
31
+
32
+ ```ruby
33
+ class Bank
34
+ def initialize(values, count)
35
+ @values = values.chars.map(&:to_i)
36
+ @pointers = ((@values.size - count)...@values.size).to_a
37
+ end
38
+
39
+ def count = @pointers.size
40
+ def pointer_value(i) = @values[@pointers[i]]
41
+ def bank_value(i) = @values[i]
42
+
43
+ def maximize
44
+ limit = 0
45
+ bi = @values.size - count - 1
46
+ pi = 0
47
+
48
+ until pi >= count
49
+ limit = (pi == 0 ? 0 : @pointers[pi - 1] + 1)
50
+
51
+ bi.downto(limit) do |i|
52
+ @pointers[pi] = i if bank_value(i) >= pointer_value(pi)
53
+ end
54
+
55
+ pi += 1
56
+ bi += 1
57
+ end
58
+
59
+ self
60
+ end
61
+
62
+ def joltage = @pointers.map.with_index { |p, i| @values[p] * (10 ** (count - i - 1)) }.sum
63
+ end
64
+
65
+ def solve(input, count)
66
+ total = 0
67
+ until input.eof?
68
+ total += Bank.new(input.gets.chomp, count).maximize.joltage
69
+ end
70
+ total
71
+ end
72
+
73
+ puts solve(input, 2)
74
+ puts solve(input, 12)
75
+ ```
76
+ :replies: []
77
+ - :author: Early_Guarantee57
78
+ :url: https://www.reddit.com/r/adventofcode/comments/1pcvaj4/2025_day_3_solutions/ns5ktdp
79
+ :body: |-
80
+ Day 3:
81
+
82
+ [Day 3](https://github.com/odrodriguezc/advent-of-code-2025/blob/main/lib/advent_of_code_2025/solvers/three.rb)
83
+ :replies: []
84
+ - :author: srugh
85
+ :url: https://www.reddit.com/r/adventofcode/comments/1pcvaj4/2025_day_3_solutions/ns4z90v
86
+ :body: |-
87
+ Shared parsing, otherwise part 1 (find largest value not at the end, then largest number from what remains) and part 2 (iterating through string with managing offsets)
88
+
89
+ [GitHub: Day-03 parts 1 and 2](https://github.com/srugh/AdventOfCode/blob/main/2025/day-03.rb)
90
+ :replies: []
91
+ - :author: Nnnes
92
+ :url: https://www.reddit.com/r/adventofcode/comments/1pcvaj4/2025_day_3_solutions/ns0zphu
93
+ :body: |-
94
+ This really seems like a day that'd be easy to fully fit into half a punchcard in plenty of different languages, but I don't see any here yet! (Honorable mention to the [x86\_64 asm solution](https://old.reddit.com/r/adventofcode/comments/1pcvaj4/2025_day_3_solutions/ns0ub0u/) that fits each part in half a punchcard.)
95
+
96
+ _edit: I think this can have a `[Red(dit) One]` label for being the first full half-punchcard solution_
97
+
98
+ ```ruby
99
+ lines = STDIN.read.split(?\n).map(&:chars)
100
+ puts [2, 12].map { |n| lines.sum { |b|
101
+ l, r = -1, -n
102
+ b.select { _1 == b[(l += 1)..r].max && r += 1 }.join.to_i
103
+ }}
104
+ ```
105
+
106
+ This uses the same simple greedy algorithm as many (most?) of the other solutions.
107
+
108
+ The right side bound is tracked by the negative index `r`. When we've `select`ed enough batteries, `r` is incremented to 0 and `b[(l += 1)..r]` always returns an empty array, effectively skipping the remainder of the elements (luckily, `[].max` is `nil` and not a bounds error).
109
+ :replies: []
110
+ - :author: justjarvo
111
+ :url: https://www.reddit.com/r/adventofcode/comments/1pcvaj4/2025_day_3_solutions/ns172l7
112
+ :body: |-
113
+ ```ruby
114
+ def joltage(bank, battery_size:)
115
+ size = bank.size - battery_size
116
+ battery = []
117
+
118
+ bank.each_char.lazy.map(&:to_i).each do |n|
119
+ battery.pop && size -= 1 while size > 0 && battery[-1] && battery[-1] < n
120
+ battery << n
121
+ end
122
+
123
+ battery[0...battery_size].join.to_i
124
+ end
125
+
126
+ input = File.readlines("input/d03.txt", chomp: true)
127
+ p1, p2 = 0, 0
128
+ input.each do |bank|
129
+ p1 += joltage(bank, battery_size: 2)
130
+ p2 += joltage(bank, battery_size: 12)
131
+ end
132
+
133
+ p [p1, p2]
134
+ ```
135
+ :replies: []
136
+ - :author: xr51z
137
+ :url: https://www.reddit.com/r/adventofcode/comments/1pcvaj4/2025_day_3_solutions/ns24lw2
138
+ :body: |-
139
+ ```ruby
140
+ def aoc2503(batteries)
141
+ input = File.readlines("03_input.txt", chomp: true)
142
+ result = 0
143
+ input.each do |x|
144
+ joltage = ""
145
+ s_end = batteries
146
+ s_start = 0
147
+ batteries.times do |i|
148
+ y = x[s_start..-s_end]
149
+ 9.downto(0) do |j|
150
+ j = j.to_s
151
+ if y.index(j) != nil
152
+ joltage << j
153
+ s_start += y.index(j) + 1
154
+ s_end -= 1
155
+ break
156
+ end
157
+ end
158
+ end
159
+ result += joltage.to_i
160
+ end
161
+ return result
162
+ end
163
+
164
+ puts "Part 1: ", aoc2503(2)
165
+ puts "Part 2: ", aoc2503(12)
166
+ ```
167
+ :replies: []
168
+ - :author: riffraff
169
+ :url: https://www.reddit.com/r/adventofcode/comments/1pcvaj4/2025_day_3_solutions/ns1096p
170
+ :body: |-
171
+ I got a bit lost for some reason, but in the end the solution seems nice enough to me.
172
+
173
+ ```ruby
174
+ def max_bank(numbers, want:)
175
+ found = []
176
+ want.downto(1) do |need|
177
+ top, idx = max_bank_helper(numbers, need:)
178
+ found << top
179
+ numbers = numbers[(idx + 1)..]
180
+ end
181
+ found.reverse.map.with_index { |v, i| v * (10**i) }.sum
182
+ end
183
+
184
+ def max_bank_helper(numbers, need:)
185
+ numbers[..-need].each_with_index.max_by { |v, i| [v, -i] }
186
+ end
187
+
188
+ def solve_easy(lines)
189
+ lines.sum { |row| max_bank(row, want: 2) }
190
+ end
191
+
192
+ def solve_hard(lines)
193
+ lines.sum { |row| max_bank(row, want: 12) }
194
+ end
195
+ ```
196
+ :replies: []
197
+ - :author: bulinutza
198
+ :url: https://www.reddit.com/r/adventofcode/comments/1pcvaj4/2025_day_3_solutions/ns1n75z
199
+ :body: |-
200
+ I ended up with a function that works for both puzzle parts, taking the expected size as an argument.
201
+
202
+ ```ruby
203
+ def process_battery(battery_line, expected_size)
204
+ index = 0
205
+
206
+ expected_size.downto(1).collect do |size|
207
+ found_digit = 0
208
+
209
+ index.upto(battery_line.size - size).each do |i|
210
+ digit = battery_line[i].to_i
211
+
212
+ if digit > found_digit
213
+ found_digit = digit
214
+ index = i + 1
215
+ end
216
+ end
217
+
218
+ found_digit
219
+ end.join('')
220
+ end
221
+
222
+ input.split("\n").sum{ |battery_line| process_battery(battery_line, 12).to_i }
223
+ ```
224
+ :replies: []
225
+ - :author: pedantic_git
226
+ :url: https://www.reddit.com/r/adventofcode/comments/1pcvaj4/2025_day_3_solutions/ns1no9d
227
+ :body: |-
228
+ Thought I was being clever on part 1 by statically compiling all the possibilities as regexps (actually really fast!)
229
+
230
+ ```ruby
231
+ #!/usr/bin/env ruby
232
+
233
+ REGEXPS = 99.downto(11).to_h { [it.to_s.chars.then {Regexp.new("#{_1}.*#{_2}")}, it]}
234
+
235
+ def joltage(bank)
236
+ REGEXPS.find {|r,_| r.match?(bank)}.last
237
+ end
238
+
239
+ puts ARGF.inject(0) {|acc,bank| acc + joltage(bank)}
240
+ ```
241
+
242
+ Not so good for part 2, though! (I solved it the same way as many of you.)
243
+ :replies: []
244
+ - :author: systemnate
245
+ :url: https://www.reddit.com/r/adventofcode/comments/1pcvaj4/2025_day_3_solutions/ns2ofba
246
+ :body: |-
247
+ For part 1, I just used Array#combination, but this was too slow for N=12. For part 2, I used a [monotonic stack](https://www.geeksforgeeks.org/dsa/introduction-to-monotonic-stack-2/). Notice that the sample input is at the end of the file under "\_\_END\_\_" this is a not very well known Ruby trick where DATA will refer to the data underneath \_\_END\_\_ and treat it as a File. Pretty cool.
248
+
249
+ ```ruby
250
+ require_relative "../utils.rb"
251
+
252
+ # some custom logic I made to either read
253
+ # from the sample input or download the input
254
+ # from the website
255
+ raw = AOC::Input.resolve(ARGV, DATA)
256
+ data = AOC::Parser.line_numbers(raw)
257
+
258
+ class BatteryBank
259
+ attr_reader :banks
260
+
261
+ def initialize(banks)
262
+ @banks = banks
263
+ end
264
+
265
+ # first attempt, brute force
266
+ def joltage
267
+ banks.combination(2).max.map(&:to_s).join.to_i
268
+ end
269
+
270
+ # second attempt, monotonic stack
271
+ def joltage_fast(n = 12)
272
+ number_to_remove = banks.length - n
273
+
274
+ banks.each_with_object([]) do |digit, stack|
275
+ while number_to_remove > 0 && !stack.empty? && stack.last < digit
276
+ stack.pop
277
+
278
+ number_to_remove -= 1
279
+ end
280
+
281
+ stack << digit
282
+ end.first(n).map(&:to_s).join.to_i
283
+ end
284
+ end
285
+
286
+ # part 1
287
+ part_one = data.map { |banks| BatteryBank.new(banks).joltage }
288
+ puts part_one.sum
289
+
290
+ # part 2
291
+ part_two = data.map { |banks| BatteryBank.new(banks).joltage_fast }
292
+ puts part_two.sum
293
+
294
+ __END__
295
+ 987654321111111
296
+ 811111111111119
297
+ 234234234234278
298
+ 818181911112111
299
+ ```
300
+ :replies: []
301
+ - :author: Mahedros
302
+ :url: https://www.reddit.com/r/adventofcode/comments/1pcvaj4/2025_day_3_solutions/ns325ct
303
+ :body: |-
304
+ Decided to teach myself a new language starting today. Is this good Ruby? Probably not, but it's technically the best Ruby I've ever written
305
+
306
+ ```ruby
307
+ def part1
308
+ total = 0
309
+ File.foreach('input').each do |line|
310
+ line = line.strip()
311
+ first_digit = 0
312
+ second_digit = 0
313
+ for i in 0...line.length
314
+ digit = Integer(line[i])
315
+ if digit > first_digit && i != (line.length - 1)
316
+ first_digit = digit
317
+ second_digit = 0
318
+ next
319
+ end
320
+ if digit > second_digit
321
+ second_digit = digit
322
+ end
323
+ end
324
+ total += (first_digit * 10) + second_digit
325
+ end
326
+ puts total
327
+ end
328
+
329
+ def part2
330
+ total = 0
331
+ File.foreach('input').each do |line|
332
+ line = line.strip()
333
+ digits = [0] * 12
334
+ for i in 0...line.length
335
+ digit = Integer(line[i])
336
+ for j in 0...digits.length
337
+ digit_set = check_digit(line, digits, digit, i, j)
338
+ if digit_set
339
+ break
340
+ end
341
+ end
342
+ end
343
+ total += Integer(digits.join)
344
+ end
345
+ puts total
346
+ end
347
+
348
+ def check_digit(line, digits, digit, i, digit_pos)
349
+ if digit > digits[digit_pos] and i < (line.length - (digits.length - 1 - digit_pos))
350
+ digits[digit_pos] = digit
351
+ for j in (digit_pos + 1)...digits.length
352
+ digits[j] = 0
353
+ end
354
+ return true
355
+ end
356
+ return false
357
+ end
358
+
359
+ if __FILE__ == $PROGRAM_NAME
360
+ Dir.chdir(File.dirname( __FILE__ ))
361
+ part1
362
+ part2
363
+ end
364
+ ```
365
+ :replies: []
366
+ - :author: onyx_and_iris
367
+ :url: https://www.reddit.com/r/adventofcode/comments/1pcvaj4/2025_day_3_solutions/ns39fbu
368
+ :body: "[https://git.onyxandiris.online/onyx\\_online/aoc2025/src/branch/main/day\\_03](https://git.onyxandiris.online/onyx_online/aoc2025/src/branch/main/day_03)"
369
+ :replies: []
@@ -0,0 +1,217 @@
1
+ ---
2
+ - :author: StillFast7545
3
+ :url: https://www.reddit.com/r/adventofcode/comments/1pdr8x6/2025_day_4_solutions/nskwjkx
4
+ :body: |-
5
+ Part 1: [https://github.com/MarioPerac/AdventOfCode2025/blob/main/day\_4/part\_1.rb](https://github.com/MarioPerac/AdventOfCode2025/blob/main/day_4/part_1.rb)
6
+
7
+ Part 2: [https://github.com/MarioPerac/AdventOfCode2025/blob/main/day\_4/part\_2.rb](https://github.com/MarioPerac/AdventOfCode2025/blob/main/day_4/part_2.rb)
8
+ :replies: []
9
+ - :author: SleepingInsomniac
10
+ :url: https://www.reddit.com/r/adventofcode/comments/1pdr8x6/2025_day_4_solutions/nsbq4e6
11
+ :body: |-
12
+ https://asciinema.org/a/ZJUVtS4mkmD8bYUTUChU8xcGN
13
+
14
+ ## Both parts
15
+
16
+ ```ruby
17
+ class Grid
18
+ include Enumerable
19
+
20
+ def initialize(data, width, height)
21
+ @data, @width, @height = data, width, height
22
+ end
23
+
24
+ def neighbors(x, y)
25
+ [
26
+ [-1, -1], [0, -1], [1, -1],
27
+ [-1, 0], [1, 0],
28
+ [-1, 1], [0, 1], [1, 1],
29
+ ]
30
+ .map { |dx, dy| [x + dx, y + dy] }
31
+ .reject { |x, y| x < 0 || y < 0 || x >= @width || y >= @height }
32
+ end
33
+
34
+ def roll?(x, y) = self[x, y] != '.'
35
+ def count_neighbors(x, y) = neighbors(x, y).count { |x, y| roll?(x, y) }
36
+ def [](x, y) = @data[y * @width + x]
37
+
38
+ def []=(x, y, value)
39
+ @data[y * @width + x] = value
40
+ end
41
+
42
+ def accessible?(x, y) = count_neighbors(x, y) < 4
43
+ def each = 0.upto(@height - 1) { |y| 0.upto(@width - 1) { |x| yield x, y } }
44
+ def count_accessible = count { |x, y| roll?(x, y) && accessible?(x, y) }
45
+ def accessible_rolls = select { |x, y| roll?(x, y) && accessible?(x, y) }
46
+ def remove(rolls) = rolls.each { |x, y| self[x, y] = "." }
47
+ end
48
+
49
+ lines = input.readlines(chomp: true)
50
+ width, height = lines.first.size, lines.size
51
+ grid = Grid.new(lines.join.chars, width, height)
52
+
53
+ part_1 = grid.accessible_rolls.count
54
+ total = 0
55
+
56
+ loop do
57
+ removable = grid.accessible_rolls
58
+ break if removable.empty?
59
+ removable.each { |x, y| grid[x, y] = grid[x, y].colorize(:red) }
60
+ total += removable.count
61
+ grid.remove(removable)
62
+ end
63
+
64
+ part_2 = total
65
+ ```
66
+ :replies: []
67
+ - :author: srugh
68
+ :url: https://www.reddit.com/r/adventofcode/comments/1pdr8x6/2025_day_4_solutions/nsazos6
69
+ :body: |-
70
+ Each part shares parsing, otherwise each solved independently. Part 1 simple traverse the grid, Part 2 continue transversing the grid until 0 can be removed, updating/mutating the grid while scanning (since the final result is all that matters and not the count per iteration which may reduce total grid traversals needed).
71
+
72
+ [2025 Day-04 ruby solution for Part 1 and Part 2](https://github.com/srugh/AdventOfCode/blob/main/2025/day-04.rb)
73
+ :replies: []
74
+ - :author: Mahedros
75
+ :url: https://www.reddit.com/r/adventofcode/comments/1pdr8x6/2025_day_4_solutions/ns7aezz
76
+ :body: "[Link to Code](https://topaz.github.io/paste/#XQAAAQCtCAAAAAAAAAARiEJHiiMzw3cPM/1Vl+2nyBa63n8Kw6AjPxpQKi2L5b7FYOvRiQfnq6pZ3l8BSNmGYKISOzndSPcw7D2gplGGLncIWHEOAn7SbfQYcXKwBQIfezoST/lGr7XVS7qy18NnC/9ELffeJkT8m+KerUvQfHh8jY6mx3NjCloW+B5ywHAIbgocLq/m01dacocMWl9Mil55F8dV7gyRkGUk1GvigihDKrvFuMVS4MOUHF9yoouRBNLuS5ht3AJUkQbNn1GFXkUl3XVXJm106Z2WCqxngZjTo9mkVYQ1Bl/LvTgXaAPsOThyf3gzigQZGeK7hOYQ/z3OK56Es5IEpSYQQRUsayyNXuh/a7Q3dEdJeNEtIFMLyyBbWr6ePJ18SrWT51lzRj1PJSc0zTEFJHPCOMGz6t7dB8qZ2ACBu91G3gdqYxgdoiWccLar2qbA2GOlZsxap09U+vuK4DNRcZFpovEbzlREvRYunnP/Or2TjjH9WiqiOX2giLX91aYUW1jycEOpyOXVaSGmyx6AYOazMtjcdgZUFGUyfIWkc1k03xFxc/BW7uxAmx9ZqWD67Z2b8Zv9ClmpxpE9WXdBlTg6yEtvzjTuJ94u0XtOwxfnItHRgcrzeTduOhcdGnNVuVJ3MJ8BU0LLg/mpH05x0sgwSCU9/EnA9pjhJXYKLPD7OFH7fe8qmYGYK2YujZBtR7astJ9rA2fObPDJjpH8rJPE)"
77
+ :replies:
78
+ - :author: munchler
79
+ :url: https://www.reddit.com/r/adventofcode/comments/1pdr8x6/2025_day_4_solutions/ns7cap6
80
+ :body: 'Ruby: The OG vibe-coding language.'
81
+ :replies: []
82
+ - :author: pedantic_git
83
+ :url: https://www.reddit.com/r/adventofcode/comments/1pdr8x6/2025_day_4_solutions/ns7l9y7
84
+ :body: |-
85
+ Love it when I can solve a puzzle this far in within 45 minutes of my alarm going off in the morning. Thanks to my trusty `grid.rb` that has been growing over the years of solving AoC!
86
+
87
+ [https://github.com/pedantic-git/aoc2025/blob/main/04/04.rb](https://github.com/pedantic-git/aoc2025/blob/main/04/04.rb)
88
+
89
+ [https://github.com/pedantic-git/aoc2025/blob/main/utils/grid.rb](https://github.com/pedantic-git/aoc2025/blob/main/utils/grid.rb)
90
+ :replies: []
91
+ - :author: riffraff
92
+ :url: https://www.reddit.com/r/adventofcode/comments/1pdr8x6/2025_day_4_solutions/ns7ezro
93
+ :body: |-
94
+ look, I have a helper class, but it's trivial. horrible solutin but I can't believe I got it right, I always screw up these.
95
+
96
+ ```ruby
97
+ def solve_easy(grid)
98
+ count = 0
99
+ grid.each_with_position do |tile, i, j|
100
+ if tile.value == '@'
101
+ close_rolls = grid.neighbors8(tile).select { |t| t.value == '@' }
102
+ if close_rolls.size < 4
103
+ count += 1
104
+ end
105
+ end
106
+ end
107
+ count
108
+ end
109
+
110
+ def solve_hard(grid)
111
+ queue = grid.tiles_with_value('@')
112
+ removed = 0
113
+ loop do
114
+ break if queue.empty?
115
+ current = queue.shift
116
+ next if grid[current.i, current.j].value == '.'
117
+ close_rolls = grid.neighbors8(current).select { |t| t.value == '@' }
118
+ if close_rolls.size < 4
119
+ grid[current.i, current.j] = '.'
120
+ removed += 1
121
+ queue.concat(close_rolls)
122
+ end
123
+ end
124
+ removed
125
+ end
126
+ ```
127
+ :replies: []
128
+ - :author: _tfa
129
+ :url: https://www.reddit.com/r/adventofcode/comments/1pdr8x6/2025_day_4_solutions/ns81d1z
130
+ :body: |-
131
+ ```ruby
132
+ input = File.readlines("input.txt")
133
+
134
+ GRID = Set.new
135
+ input.each_with_index do |l, y|
136
+ l.chars.each_with_index do |c, x|
137
+ GRID << Complex(x,y) if c == ?@
138
+ end
139
+ end
140
+
141
+ ADJ = [-1-1i, -1+0i, -1+1i, 0-1i, 0+1i, +1-1i, +1+0i, +1+1i]
142
+
143
+ def accessible(grid) = grid.reject{ |i| ADJ.map{it+i}.count{ grid.include?(it)} >=4 }
144
+
145
+ acc = accessible(GRID)
146
+ puts acc.count
147
+
148
+ g = GRID.dup
149
+ until acc.empty?
150
+ g -= acc
151
+ acc = accessible(g)
152
+ end
153
+ puts GRID.count - g.count
154
+ ```
155
+ :replies: []
156
+ - :author: Nnnes
157
+ :url: https://www.reddit.com/r/adventofcode/comments/1pdr8x6/2025_day_4_solutions/ns7jzl2
158
+ :body: |-
159
+ The half punchcard is more cramped for today's problem, but still very achievable.
160
+
161
+ ```ruby
162
+ g = STDIN.read; g += ?\n * (w = g.index(?\n)) * 2
163
+ loop { g.tr! ?#, ?-; (h = g.chars).each_with_index { |c, i| next if c != ?@
164
+ g[i] = ?# if [*(-w-2..-w), -1, 1, *(w..w+2)].count{ h[i + _1] == ?@ } < 4 }
165
+ p g.count ?# if !g[?-]; break if !g[?#] }
166
+ p g.count ?-
167
+ ```
168
+
169
+ Despite calling my input `g` for "grid", it remains a one-dimensional string. Newline characters form "walls" so I don't run into trouble with wrapping across lines. I suspect there's some better way to enumerate adjacent indices but I can't think of one at the moment.
170
+
171
+ The removed rolls are marked with a `#`; then, at the beginning of each pass, all `#`s are replaced with `-`s. After a pass, if there are no `-`s then part 1 is done and if there are no `#`s then part 2 is done.
172
+
173
+ _Edit: the newline walls weren't big enough for all inputs (top left corner could "see" the bottom right corner). Added `* 2` to line 1 to fix._
174
+ :replies:
175
+ - :author: Nnnes
176
+ :url: https://www.reddit.com/r/adventofcode/comments/1pdr8x6/2025_day_4_solutions/ns7rcqt
177
+ :body: |-
178
+ > better way to enumerate adjacent indices
179
+
180
+ ```ruby
181
+ g = STDIN.read; g = ?. * (w = g.index(?\n)) + g + ?. * w
182
+ loop { g.tr! ?#, ?-; (h = g.chars).each_with_index { |c, i| next if c != ?@
183
+ g[i] = ?# if [-w - 2, -1, w].sum([]) { h[i + _1, 3] }.count(?@) <= 4 }
184
+ puts g.count ?# if !g[?-]; break if !g[?#] }
185
+ p g.count ?-
186
+ ```
187
+
188
+ Better? Not sure, but at least it's noticeably faster.
189
+ :replies: []
190
+ - :author: justjarvo
191
+ :url: https://www.reddit.com/r/adventofcode/comments/1pdr8x6/2025_day_4_solutions/ns7vvo3
192
+ :body: |-
193
+ ```ruby
194
+ require_relative "grid"
195
+
196
+ def remove_rolls(grid)
197
+ grid.each_cell
198
+ .filter_map { |x, y, c| [x, y] if c == "@" && grid.adjacent_values(x, y).count { _1 == "@" } < 4 }
199
+ .each { |x, y| grid[x, y] = "R" }
200
+ end
201
+
202
+ grid = Grid.parse(File.read("input/d04.txt"))
203
+ removed = remove_rolls(grid)
204
+ p1 = p2 = removed.size
205
+ p2 += removed.size while (removed = remove_rolls(grid)).any?
206
+
207
+ p [p1, p2]
208
+ ```
209
+
210
+ Grid code: [https://github.com/leejarvis/adventofcode/blob/master/2025/grid.rb](https://github.com/leejarvis/adventofcode/blob/master/2025/grid.rb)
211
+
212
+ Vacation for the next few days so no AoC for me, excited to get stuck into some challenges when I return.
213
+ :replies: []
214
+ - :author: onyx_and_iris
215
+ :url: https://www.reddit.com/r/adventofcode/comments/1pdr8x6/2025_day_4_solutions/ns7zt95
216
+ :body: "[https://git.onyxandiris.online/onyx\\_online/aoc2025/src/branch/main/day\\_04](https://git.onyxandiris.online/onyx_online/aoc2025/src/branch/main/day_04)"
217
+ :replies: []