2022-12-05 21:47:30 -08:00
|
|
|
require "advent"
|
|
|
|
INPUT = input(2022, 6).lines[0].chars
|
|
|
|
|
|
|
|
def part1(input)
|
2022-12-08 22:20:55 -08:00
|
|
|
idx = 0
|
|
|
|
input.each_cons(4) do |x|
|
|
|
|
return idx + 4 if x.uniq.size == 4
|
|
|
|
idx += 1
|
2022-12-05 21:47:30 -08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def part2(input)
|
|
|
|
offset = 0
|
|
|
|
loop do
|
|
|
|
chars = input[offset..offset+13]
|
|
|
|
return offset + 14 if chars.uniq.size == 14
|
|
|
|
offset += 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
puts part1(INPUT.clone)
|
|
|
|
puts part2(INPUT.clone)
|