This commit is contained in:
2025-12-06 06:19:55 -08:00
parent 064dc676cd
commit b6f0b50ca2
4 changed files with 87 additions and 5 deletions

30
2025/02.rb Normal file
View File

@@ -0,0 +1,30 @@
def valid(str, p2)
(1..str.size / 2).each do |i|
sub = str[0, i]
return false if str[i..] == sub
if p2 && str.size > 2
chunks = str[i..].chars.each_slice(sub.size).map(&:join)
puts chunks
end
end
true
end
input = File.read('input/test').split(',')
p1 = 0
p2 = 0
input.each do |line|
sp = line.split('-')
a = sp[0].to_i
b = sp[1].to_i
(a..b).each do |i|
p1 += i unless valid(i.to_s, false)
p2 += i unless valid(i.to_s, true)
end
end
puts p1
puts p2

1
2025/input/02 Normal file
View File

@@ -0,0 +1 @@
9191896883-9191940271,457499-518693,4952-6512,960-1219,882220-1039699,2694-3465,3818-4790,166124487-166225167,759713819-759869448,4821434-4881387,7271-9983,1182154-1266413,810784-881078,802-958,1288-1491,45169-59445,25035-29864,379542-433637,287-398,75872077-75913335,653953-689335,168872-217692,91-113,475-590,592-770,310876-346156,2214325-2229214,85977-112721,51466993-51620441,8838997-8982991,534003-610353,32397-42770,17-27,68666227-68701396,1826294188-1826476065,1649-2195,141065204-141208529,7437352-7611438,10216-13989,33-44,1-16,49-74,60646-73921,701379-808878