advent_of_ruby 0.3.4 → 0.3.6

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.

Potentially problematic release.


This version of advent_of_ruby might be problematic. Click here for more details.

Files changed (213) 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/formatters/rubocop.rb +18 -11
  192. data/lib/arb/util.rb +58 -0
  193. data/lib/arb/version.rb +1 -1
  194. metadata +184 -23
  195. data/lib/download_solutions/api/github/repos.rb +0 -54
  196. data/lib/download_solutions/api/github.rb +0 -164
  197. data/lib/download_solutions/api/reddit/add_missing_replies.rb +0 -43
  198. data/lib/download_solutions/api/reddit/clean_bodies.rb +0 -64
  199. data/lib/download_solutions/api/reddit/filter_by_language.rb +0 -32
  200. data/lib/download_solutions/api/reddit/get_initial_response.rb +0 -30
  201. data/lib/download_solutions/api/reddit/get_serial_comments.rb +0 -145
  202. data/lib/download_solutions/api/reddit/megathread_ids.rb +0 -19
  203. data/lib/download_solutions/api/reddit/params.rb +0 -40
  204. data/lib/download_solutions/api/reddit/reject_unwanted_replies.rb +0 -31
  205. data/lib/download_solutions/api/reddit/remove_ids.rb +0 -26
  206. data/lib/download_solutions/api/reddit/remove_language_tags.rb +0 -29
  207. data/lib/download_solutions/api/reddit.rb +0 -101
  208. data/lib/download_solutions/cli/cli/shared.rb +0 -35
  209. data/lib/download_solutions/cli/github.rb +0 -107
  210. data/lib/download_solutions/cli/reddit.rb +0 -64
  211. data/lib/download_solutions/download_solutions.rb +0 -18
  212. data/lib/download_solutions/reverse_markdown/converters/br.rb +0 -15
  213. data/lib/download_solutions/reverse_markdown/converters/pre.rb +0 -46
@@ -0,0 +1,324 @@
1
+ ---
2
+ - :author: StillFast7545
3
+ :url: https://www.reddit.com/r/adventofcode/comments/1pemdwd/2025_day_5_solutions/nsl0mch
4
+ :body: |-
5
+ Part 1: [https://github.com/MarioPerac/AdventOfCode2025/blob/main/day\_5/part\_1.rb](https://github.com/MarioPerac/AdventOfCode2025/blob/main/day_5/part_1.rb)
6
+
7
+ Explanation: `id.between?(range.first, range.last)` this is how ruby solve it.
8
+
9
+ Part 2: [https://github.com/MarioPerac/AdventOfCode2025/blob/main/day\_5/part\_2.rb](https://github.com/MarioPerac/AdventOfCode2025/blob/main/day_5/part_2.rb)
10
+
11
+ Explanation: Sort + two while loops + one condition = done.
12
+ :replies: []
13
+ - :author: Basic_Ent
14
+ :url: https://www.reddit.com/r/adventofcode/comments/1pemdwd/2025_day_5_solutions/nsiegyo
15
+ :body: |-
16
+ [https://github.com/ceautery/advent2025/blob/main/app/day\_5.rb](https://github.com/ceautery/advent2025/blob/main/app/day_5.rb)
17
+
18
+ Nothing overly fancy. This puzzle exposes the dark side of a ruby feature: You can declare a range with ints as strings, and it behaves like you'd expect, but it can't do math to calculate size or to see if a number is in the range. So size is nil, and checking for members takes a full scan of the elements, and goes much slower.
19
+
20
+ TL;DR make sure you (&:to\_i) all the things.
21
+
22
+ ```ruby
23
+ ~ # pry
24
+ [1] pry(main)> r = ("11".."22")
25
+ => "11".."22"
26
+ [2] pry(main)> r.to_a
27
+ => ["11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22"]
28
+ [3] pry(main)> r.size
29
+ => nil
30
+ [4] pry(main)> (11..22).size
31
+ => 12
32
+ [5] pry(main)>
33
+ ```
34
+ :replies: []
35
+ - :author: srugh
36
+ :url: https://www.reddit.com/r/adventofcode/comments/1pemdwd/2025_day_5_solutions/nshjak9
37
+ :body: |-
38
+ The 'work' was just to condense the list of ranges down. From there using a Ruby block was trivial to solve (Part 1 counting ingredients in range, part 2 simply summing the ranges).
39
+
40
+ [GitHub link for solution to both Part 1 and Part 2](https://github.com/srugh/AdventOfCode/blob/main/2025/day-05.rb)
41
+ :replies: []
42
+ - :author: SleepingInsomniac
43
+ :url: https://www.reddit.com/r/adventofcode/comments/1pemdwd/2025_day_5_solutions/nshifiu
44
+ :body: |-
45
+ https://github.com/SleepingInsomniac/adventofcode/blob/master/2025-12-05/part\_2.rb
46
+
47
+ ```ruby
48
+ class FreshDB
49
+ def initialize
50
+ @ranges = []
51
+ end
52
+
53
+ def <<(range)
54
+ return if @ranges.any? { |r| r.cover?(range) }
55
+
56
+ @ranges.reject! { |r| range.cover?(r) }
57
+
58
+ if index = @ranges.index { |r| r.cover?(range.begin) }
59
+ updatable = @ranges.delete_at(index)
60
+ b = range.begin < updatable.begin ? range.begin : updatable.begin
61
+ self << (b..range.end)
62
+ elsif index = @ranges.index { |r| r.cover?(range.end) }
63
+ updatable = @ranges.delete_at(index)
64
+ e = range.end > updatable.end ? range.end : updatable.end
65
+ self << (range.begin..e)
66
+ else
67
+ @ranges << range
68
+ end
69
+ end
70
+
71
+ def fresh?(ingredient_id)
72
+ @ranges.any? { |range| range.cover?(ingredient_id) }
73
+ end
74
+
75
+ def fresh_total
76
+ @ranges.reduce(0) { |m, r| m + r.count }
77
+ end
78
+ end
79
+
80
+ # ..parse
81
+ db << range
82
+ ids.count { |id| db.fresh?(id) } # Part 1
83
+ db.fresh_total # Part 2
84
+ ```
85
+ :replies: []
86
+ - :author: Mahedros
87
+ :url: https://www.reddit.com/r/adventofcode/comments/1pemdwd/2025_day_5_solutions/nsffljv
88
+ :body: |-
89
+ Foolishly wasted my first attempt at part 2 by forgetting that Ruby's default sort doesn't sort in place. I was sorting and then immediately discarding the sorted list
90
+
91
+ [Code](https://topaz.github.io/paste/#XQAAAQDGBQAAAAAAAAARiEJHiiMzw3cPM/1Vl+2nyBa63n8Kw6AjPxsUgu9rdE7zg7+tZ3WD1ORhBz4OK9efDPXPJ0R3el67IYpr6wJJeO4USW2W5T4/K2vtXmBaNGBedkIQ6c2hdYcno4+KLsRmsFcq8x6kkG4aOWgylrI/hK21x8AKx701DRHi9Go3OKnY3JveVADxzWs/EsJLhTVE+wbKkuM1mAjJ2fKwNscGqqgU4BSsPfqKrxW0IRxHB4A+UXpyjHX48oY80g5sH+1N0ZONesiDUbt5XXGZnQCY33vrDqZyS57mazMMP/bJPCnbHeTw+soZsFxZIoZue93SrWrWBvP+2OqpgW4w/VR1hK7sZIQ8JSt+poGC7ZUTYaSOVYGsICKxVRHuCGzVtcT3l0qdiFJosHsSCGHqM2lIMXHw0jokQX3SW9LwYivIkofp0K4sm0dCkdOecgentnPasXeayl1ez2I4BiFlfj8x5YhZ9Kwo0ST1TW29HuuiAMrDmSPwe9B6zOfpqR+GhI94VFQao/g7WUPxXwm0llwCHLzvTPXx8Sh84a/K/oRbFmJBfDbFt2+EA8xYdgUbN+pmIkJJ+V5o9ZPE5EdyM0UA+TXp8sjLBZeV4bYfjuuS1S/Gg0IPK0y8p9hxOMxtcoO8UJSrtCr/lhKNR+5MrUP9niEK)
92
+ :replies: []
93
+ - :author: riffraff
94
+ :url: https://www.reddit.com/r/adventofcode/comments/1pemdwd/2025_day_5_solutions/nsdv36t
95
+ :body: |-
96
+ ```ruby
97
+ def solve_easy(input)
98
+ ranges, ids = input
99
+ ids.count do |id|
100
+ ranges.any? { |r| r.include?(id) }
101
+ end
102
+ end
103
+
104
+ def extend_range(a, b)
105
+ [a.begin, b.begin].min..[a.end, b.end].max
106
+ end
107
+
108
+ def solve_hard(input)
109
+ ranges, _ids = input
110
+ stack = ranges.sort_by(&:begin)
111
+ isolated = []
112
+
113
+ while stack.any?
114
+ left_range = stack.shift
115
+ if stack.empty?
116
+ isolated << left_range
117
+ break
118
+ end
119
+ stack.dup.each_with_index do |right_range, i|
120
+ if right_range.begin > left_range.end + 1
121
+ isolated << left_range
122
+ else
123
+ left_range = extend_range(left_range, right_range)
124
+ stack.delete_at(i)
125
+ stack.unshift(left_range)
126
+ end
127
+ break
128
+ end
129
+ end
130
+ isolated.sum(&:size)
131
+ end
132
+ ```
133
+ :replies: []
134
+ - :author: onyx_and_iris
135
+ :url: https://www.reddit.com/r/adventofcode/comments/1pemdwd/2025_day_5_solutions/nse3ksf
136
+ :body: "[https://git.onyxandiris.online/onyx\\_online/aoc2025/src/branch/main/day\\_05](https://git.onyxandiris.online/onyx_online/aoc2025/src/branch/main/day_05)"
137
+ :replies: []
138
+ - :author: pedantic_git
139
+ :url: https://www.reddit.com/r/adventofcode/comments/1pemdwd/2025_day_5_solutions/nse74m0
140
+ :body: |-
141
+ I find the `consolidate!` method to be quite clunky - if I hadn't just woken up in the morning I might have found a more higher-order way to do it. Still, the rest of this class is relatively cute and it runs quickly.
142
+
143
+ ```ruby
144
+ #!/usr/bin/env ruby
145
+
146
+ require 'set'
147
+
148
+ class Ims
149
+ attr_reader :ranges, :io
150
+
151
+ def initialize(io)
152
+ @io = io
153
+ @ranges = Set.new
154
+ until /^$/ =~ (l=io.readline)
155
+ add_range! l
156
+ end
157
+ consolidate!
158
+ end
159
+
160
+ def add_range!(s)
161
+ r = s.split('-').then {_1.to_i .. _2.to_i}
162
+ ranges << r
163
+ end
164
+
165
+ # Consolidate any ranges that overlap... could be more elegant I reckon
166
+ def consolidate!
167
+ ranges.dup.each do |r|
168
+ if overs = ranges.find_all {(it != r) && it.overlap?(r)}
169
+ to_delete = overs << r
170
+ to_delete.each {ranges.delete it}
171
+ ranges << (to_delete.map(&:min).min .. to_delete.map(&:max).max)
172
+ end
173
+ end
174
+ end
175
+
176
+ def fresh?(n)
177
+ ranges.any? {it.include? n.to_i}
178
+ end
179
+
180
+ def n_fresh
181
+ io.count {fresh? it}
182
+ end
183
+
184
+ def n_possible
185
+ ranges.sum(&:count)
186
+ end
187
+
188
+ end
189
+
190
+ i = Ims.new(ARGF)
191
+ p i.n_fresh
192
+ p i.n_possible
193
+ ```
194
+ :replies: []
195
+ - :author: im_sofi
196
+ :url: https://www.reddit.com/r/adventofcode/comments/1pemdwd/2025_day_5_solutions/nse9a1e
197
+ :body: |-
198
+ Another fun day. A classic advent of code range set theory question. Getting to use [my std++ library](https://codeberg.org/soupglasses/advent-of-code/src/commit/a8f20c537bd86b994df924601a28f2630ace7814/std++.rb#L68-L103) which implements a subset of set theory for the Range class in Ruby. Quite trivial once you have those functions implemented. :D
199
+
200
+ https://codeberg.org/soupglasses/advent-of-code/src/branch/main/2025/day\_05.rb
201
+ :replies: []
202
+ - :author: _tfa
203
+ :url: https://www.reddit.com/r/adventofcode/comments/1pemdwd/2025_day_5_solutions/nsed21x
204
+ :body: |-
205
+ Part 1
206
+
207
+ ```ruby
208
+ input = File.read("input.txt").split("\n\n")
209
+ ranges = input[0].lines.map{ it.split(?-).map(&:to_i)}.map{Range.new(*it)}
210
+ ing = input[1].lines.map(&:to_i)
211
+
212
+ puts ing.count{ |i| ranges.any?{ |r| r.include?(i)}}
213
+ ```
214
+
215
+ Part 2
216
+
217
+ ```ruby
218
+ class Range
219
+ def subtract(other)
220
+ return [] if (other.begin <= self.begin && other.max >= self.max)
221
+ return [self] if other.begin > self.end || other.end < self.begin
222
+ res = []
223
+ res << (self.begin..other.begin-1) if self.begin < other.begin
224
+ res << (other.max+1..self.max) if other.max < self.max
225
+ res
226
+ end
227
+ alias_method :-, :subtract
228
+ end
229
+
230
+ input = File.read("input.txt").split("\n\n")
231
+ ranges = input[0].lines.map{ it.split(?-).map(&:to_i)}.map{Range.new(*it)}
232
+
233
+ s = []
234
+
235
+ ranges.each do |r|
236
+ n = s.inject([r]){|a,i| a.map{it-i}.flatten}
237
+ n.each{ s << it }
238
+ end
239
+
240
+ puts s.sum(&:size)
241
+ ```
242
+ :replies: []
243
+ - :author: bulinutza
244
+ :url: https://www.reddit.com/r/adventofcode/comments/1pemdwd/2025_day_5_solutions/nseed5w
245
+ :body: |-
246
+ Part 2:
247
+
248
+ ```ruby
249
+ total_fresh = 0
250
+ previous_max = 0
251
+
252
+ input.
253
+ lines.
254
+ map { |line| line.split('-').map(&:to_i) }.
255
+ sort { |range1, range2| range1[0] <=> range2[0] }.
256
+ each do |range|
257
+ min = range[0]
258
+ min = previous_max + 1 if min <= previous_max
259
+
260
+ delta = range[1] - min + 1
261
+
262
+ if delta > 0
263
+ total_fresh += delta
264
+ previous_max = range[1]
265
+ end
266
+ end
267
+ ```
268
+ :replies: []
269
+ - :author: xr51z
270
+ :url: https://www.reddit.com/r/adventofcode/comments/1pemdwd/2025_day_5_solutions/nsgue98
271
+ :body: |-
272
+ \
273
+
274
+ ```ruby
275
+ require 'set'
276
+
277
+ input = File
278
+ .readlines("05_input.txt", chomp: true)
279
+ split = input
280
+ .find_index("")
281
+ ranges = input[0..split-1]
282
+ .map { |x| x.split("-")}
283
+ .map { |x| x.map(&:to_i) }
284
+ .sort_by { |min, max| [min, max] }
285
+ ids = input[1+split..-1]
286
+ .map(&:to_i)
287
+
288
+ # Part 1
289
+
290
+ fresh = Set.new
291
+
292
+ ids.each do |id|
293
+ ranges.each do |min, max|
294
+ if id.between?(min, max) then fresh.add(id) end
295
+ end
296
+ end
297
+
298
+ puts "Part 1: ", fresh.size
299
+
300
+ # Part 2
301
+
302
+ freshranges = 0
303
+
304
+ ranges.each_with_index do |x, idx|
305
+ next unless idx < ranges.length - 1
306
+ nextone = ranges[idx+1]
307
+
308
+ if nextone[0] <= x[1]
309
+ nextone[0] = x[0]
310
+ if nextone[1] <= x[1]
311
+ nextone[1] = x[1]
312
+ end
313
+ x[0] = 0; x[1] = 0
314
+ end
315
+ end
316
+
317
+ ranges.each do |min, max|
318
+ next unless min != 0 and max != 0
319
+ freshranges += (max - min) + 1
320
+ end
321
+
322
+ puts "Part 2: ", freshranges
323
+ ```
324
+ :replies: []
@@ -0,0 +1,246 @@
1
+ ---
2
+ - :author: SleepingInsomniac
3
+ :url: https://www.reddit.com/r/adventofcode/comments/1pfguxk/2025_day_6_solutions/nsodrwg
4
+ :body: |-
5
+ https://github.com/SleepingInsomniac/adventofcode/tree/master/2025-12-06
6
+
7
+ ```ruby
8
+ def part_1(input)
9
+ lines = input.readlines(chomp: true)
10
+ ops = lines.pop.split(/\s+/).map(&:to_sym)
11
+ numbers = lines.map { |l| l.strip.split(/\s+/).map(&:to_i) }
12
+ .transpose.map.with_index { |col, i| col.reduce(ops[i]) }.sum
13
+ end
14
+
15
+ def part_2(input)
16
+ lines = input.readlines(chomp: true)
17
+ ops = lines.pop.scan(/[^\s]\s+/)
18
+ start, stop = 0, 0
19
+ ranges = ops.map.with_index { |op, i| stop += op.size ; (start...(i == ops.size - 1 ? stop : stop - 1)).tap { start = stop } }
20
+ ops.map! { it.strip.to_sym }
21
+ lines.map { |l| ranges.map { |r| l[r].chars } }.transpose.map.with_index { |r, i| r.transpose.reverse.map { it.join.to_i }.reduce(ops[i]) }.sum
22
+ end
23
+ ```
24
+ :replies: []
25
+ - :author: onyx_and_iris
26
+ :url: https://www.reddit.com/r/adventofcode/comments/1pfguxk/2025_day_6_solutions/nsnzd8r
27
+ :body: "[https://git.onyxandiris.online/onyx\\_online/aoc2025/src/branch/main/day\\_06](https://git.onyxandiris.online/onyx_online/aoc2025/src/branch/main/day_06)"
28
+ :replies: []
29
+ - :author: StillFast7545
30
+ :url: https://www.reddit.com/r/adventofcode/comments/1pfguxk/2025_day_6_solutions/nsngua5
31
+ :body: |-
32
+ Part 1: [https://github.com/MarioPerac/AdventOfCode2025/blob/main/day\_6/part\_1.rb](https://github.com/MarioPerac/AdventOfCode2025/blob/main/day_6/part_1.rb)
33
+
34
+ Part 2: [https://github.com/MarioPerac/AdventOfCode2025/blob/main/day\_6/part\_2.rb](https://github.com/MarioPerac/AdventOfCode2025/blob/main/day_6/part_2.rb)
35
+ :replies: []
36
+ - :author: Mahedros
37
+ :url: https://www.reddit.com/r/adventofcode/comments/1pfguxk/2025_day_6_solutions/nsmks32
38
+ :body: |-
39
+ Ah, there's the difficulty jump we've been waiting for. The "eureka" moment for me was realizing the operators are always left-aligned, so I can parse that line first and use the widths of its splits to parse the value lines
40
+
41
+ [Code Link](https://topaz.github.io/paste/#XQAAAQAACgAAAAAAAAARiEJHiiMzw3cPM/1Vl+2nyBa63n8Kw6AjPxsUgu9rdE7zhPPHPyXwxOHK81zITg/yhxqdKmLQEniJYuRkLq8JUbpiJpEA6fYdDJgmkC1iyEhNq7J/hMXfeBM7NBbT67a1yG8RgnjkgUPVEYlNurj/c2JWc0WYvGqpfQEiA718N3V8PqQ1+koJpRieOv0eD6pvg2Sqzc4CM0ZV7bPPq5l5hWZcM5y6V4jbGdhnmt2WUdl9Elpt7/HSK6C7MXz/CO82zd/W1vQhH57EHKmSkUQKV9caoP8VawNvCwH0koI9gcNAkGd8b/99IpMHJ1wPxxQmA8FlD3sWsfv59PVngcrp+JshELiMGnHWqhFzGSwFr+R3vdAsqmwsGs8qjTPsAgq1IK8tKrCtWAs3TRwXIDBLSL64bxnB3iVQqaYdjP2uTad98KyPw3oFAPDYObtdLQCSGIrTWpU2D6NuK7tzamiOPl8ksDHiJjOf9AwgEod2ahqA/VAHq+hdRUMwG5G2hr9y3Q1CgAWv7OKKP5fDEBeX/ltOucJS3DXc61VSWT6Fud8W/xCkqJGtTefovvfthQc32ukCaqNvoKDLO3PNWntxh7KIdGOHiGr9GVGlY70eUhOxnMKEFWu9mJ/aNtH+ghrUXfiglUjT2LppJJmEUcxWa6BrbzH5k8Vfp+Lh7+hcNLPkt9Uqc+AH+AFCAwfZd4NoOdcr19GVa8SXIJvX+HKopi3hNKY2QhAM6y7IPRYvcvpBPiUdkbTOZJFLse1RKEZ5HMaSNpHYjqo2Hu87kisVwtqQxMmHyTBAmFEQj8oX0wcjN7Vg67unfzlFiEVT0Xx1ARIN214SS/LBZ1UHm+80ksBAFz5SMkuLcfFQCKef8TXMKU7nYetNvmCBD3cJYkKuk1tkY2geN14L+xM8yxEySEVxQTQxY5tn24cmRFL6zFDFfk7x10ZsZEGVf7R91D46E/T2x0pLuafqgiijQdwFywo92WEb04ZeOgqgh58Kb/R5IV/tBukaFhxL3I6XrlQXCqAUlI3QfCzs/I5sAaDBl8K1hmcTFxQ/muyPENPQpUs1FbNLwm4IJXlJNBTIZ/KqGisSa5gFC7gwhlsg4fqJd/cw8Aa+PJSZO/+Pw8ai)
42
+ :replies:
43
+ - :author: isaacfink
44
+ :url: https://www.reddit.com/r/adventofcode/comments/1pfguxk/2025_day_6_solutions/nsmmgqb
45
+ :body: I had the same realization, I was dreading having to parse each line character by character with a lookahead
46
+ :replies: []
47
+ - :author: systemnate
48
+ :url: https://www.reddit.com/r/adventofcode/comments/1pfguxk/2025_day_6_solutions/nslvhbm
49
+ :body: |-
50
+ Finished part 1 very quickly, but failed to read the "right-aligned" part and went down an approach where I was trying to add the ones, then tens, then hundreds, etc. of the number.
51
+
52
+ Fun fact: the problem mentions a "magnetically sealed garbage smasher", like in Star Wars: Episode IV. The solution to the sample input for part 2 is 3263827, which is the number of the trash compactor in Star Wars.
53
+
54
+ ```ruby
55
+ require "debug"
56
+ require_relative "../utils.rb"
57
+
58
+ raw = AOC::Input.resolve(ARGV, DATA)
59
+ data = AOC::Parser.raw_data(raw).split("\n")
60
+
61
+ part_one_data = data.map { _1.split(" ") }.transpose
62
+ part_two_data = data.map(&:chars).transpose.slice_before { _1.all?(" ") }
63
+
64
+ PartOne = Struct.new(:problems) do
65
+ def numbers
66
+ problems[0..-2].map(&:to_i)
67
+ end
68
+
69
+ def operand
70
+ problems[-1].to_sym
71
+ end
72
+
73
+ def solution
74
+ numbers.reduce(operand)
75
+ end
76
+ end
77
+
78
+ PartTwo = Struct.new(:problems) do
79
+ def numbers
80
+ problems.map { |arr| arr[..-2] }.map(&:join).map(&:to_i).reject(&:zero?)
81
+ end
82
+
83
+ def operand
84
+ problems.flatten.detect { |char| %w[* +].include?(char) }
85
+ end
86
+
87
+ def solution
88
+ numbers.reduce(operand)
89
+ end
90
+ end
91
+
92
+ part_one = part_one_data.map { PartOne.new(_1) }
93
+ part_two = part_two_data.map { PartTwo.new(_1) }
94
+
95
+ puts part_one.map { _1.solution }.sum
96
+ puts part_two.map { _1.solution }.sum
97
+ __END__
98
+ 123 328 51 64
99
+ 45 64 387 23
100
+ 6 98 215 314
101
+ * + * +
102
+ ```
103
+ :replies: []
104
+ - :author: Prior-Advice-5207
105
+ :url: https://www.reddit.com/r/adventofcode/comments/1pfguxk/2025_day_6_solutions/nskr8yo
106
+ :body: |-
107
+ Today I felt like revisiting a language I loved like a decade ago… `Array#transpose` was very handy for part 2!
108
+
109
+ https://github.com/diktomat/AdventOfCode/blob/main/2025/d06/d06.rb
110
+ :replies: []
111
+ - :author: _tfa
112
+ :url: https://www.reddit.com/r/adventofcode/comments/1pfguxk/2025_day_6_solutions/nsli9n2
113
+ :body: |-
114
+ Part 1
115
+
116
+ ```ruby
117
+ input = File.readlines("input.txt").map{it.split}
118
+ values = input[..-2].map{it.map(&:to_i)}
119
+ ops = input.last.map(&:to_sym)
120
+
121
+ puts values.first.zip(*values[1..]).each_with_index.sum{|l,i| l.reduce(ops[i])}
122
+ ```
123
+
124
+ Part 2
125
+
126
+ ```ruby
127
+ *values, ops = File.readlines("input.txt")
128
+ total = i = 0
129
+
130
+ while i < ops.size
131
+ j = ops.index(/[+*]/, i+1) || ops.size + 1
132
+ a = values.map{it[i...j-1].chars}
133
+ total += a.first.zip(*a[1..]).map{it.join.to_i}.reduce(ops[i].to_sym)
134
+ i = j
135
+ end
136
+ puts total
137
+ ```
138
+ :replies: []
139
+ - :author: pedantic_git
140
+ :url: https://www.reddit.com/r/adventofcode/comments/1pfguxk/2025_day_6_solutions/nsk4m2h
141
+ :body: |-
142
+ No time to do part 2 yet so haven't looked at other people's solutions. But I'm very happy with my one-liner for part 1!
143
+
144
+ ```ruby
145
+ #!/usr/bin/env ruby
146
+ p ARGF.readlines.map(&:split).transpose.map {|l| l.pop.then {l.map(&:to_i).reduce(it.to_sym)}}.sum
147
+ ```
148
+ :replies: []
149
+ - :author: riffraff
150
+ :url: https://www.reddit.com/r/adventofcode/comments/1pfguxk/2025_day_6_solutions/nsk95yt
151
+ :body: |-
152
+ not quite happy with the fact I'm parsing the data two different ways, but hey, it works
153
+
154
+ ```ruby
155
+ def solve_easy(text)
156
+ lines = text.lines.map(&:split)
157
+ last = lines.pop
158
+ matrix = lines.map { |l| l.map(&:to_i) }
159
+ matrix << last
160
+ matrix.transpose.sum { |col| col[..-2].inject(col.last) }
161
+ end
162
+
163
+ def solve_hard(text)
164
+ matrix = text.lines.map { |l| l.chars }.transpose
165
+ stack = []
166
+ results = 0
167
+ op = nil
168
+ while line = matrix.shift
169
+ if line.all? { _1 == ' ' } || matrix.empty?
170
+ results += stack.inject(op)
171
+ stack = []
172
+ op = nil
173
+ next
174
+ end
175
+ op ||= line.last
176
+ stack << line[..-2].join.to_i
177
+ end
178
+ results
179
+ end
180
+ ```
181
+ :replies: []
182
+ - :author: xr51z
183
+ :url: https://www.reddit.com/r/adventofcode/comments/1pfguxk/2025_day_6_solutions/nsl3rrd
184
+ :body: |-
185
+ If it works, it works...
186
+
187
+ ```ruby
188
+ # Part 1
189
+
190
+ input = File
191
+ .readlines("06_input.txt", chomp: true)
192
+ .map { |x| x.split(" ") }
193
+
194
+ input.each_with_index do |x, idx|
195
+ next unless idx < input.length - 1
196
+ x.map!(&:to_i)
197
+ end
198
+
199
+ result = 0
200
+
201
+ input.transpose.each do |x|
202
+ operator = x.length - 1
203
+ case x[operator]
204
+ when "*"
205
+ result += x[0..operator-1].inject(:*)
206
+ when "+"
207
+ result += x[0..operator-1].inject(:+)
208
+ end
209
+ end
210
+
211
+ puts "Part 1: ", result
212
+
213
+ # Part 2
214
+
215
+ input = File
216
+ .readlines("06_input.txt", chomp: true)
217
+ .map(&:chars)
218
+ .transpose
219
+ .map { |x| x.join.delete(" ") }
220
+
221
+ result = 0
222
+ input.delete("")
223
+ values = Array.new
224
+ operator = "+"
225
+
226
+ input.each_with_index do |x, idx|
227
+ if x.match?(/\+|\*/)
228
+ if values.length != 0
229
+ operator.include?("+") ? i = values.inject(:+) : i = values.inject(:*)
230
+ result += i
231
+ end
232
+ values.clear
233
+ values << x.chop.to_i
234
+ operator = x[-1]
235
+ else
236
+ values << x.to_i
237
+ end
238
+ end
239
+
240
+ # Ugly... but it gets the job done. Should've written a method.
241
+ operator.include?("+") ? i = values.inject(:+) : i = values.inject(:*)
242
+ result += i
243
+
244
+ puts "Part 2: ", result
245
+ ```
246
+ :replies: []