Solved Day 10

main
s00ner 2022-07-16 14:10:44 -04:00
parent 43c9d56726
commit cb1283d990
3 changed files with 46 additions and 0 deletions

1
day10/input Normal file
View File

@ -0,0 +1 @@
3113322113

1
day10/input.testing Normal file
View File

@ -0,0 +1 @@
1

44
day10/solution.rb Normal file
View File

@ -0,0 +1,44 @@
#!/bin/env ruby
require 'pry'
input = File.read('./input').strip
# BADBADBAD takes sooooooo long at big numbers
# def look_and_say(sequence)
# sequence += 'E'
# result = ''
# sequence.chars.each_with_index do |num, i|
# next if result[-1] == num or num == 'E'
# n = i
# while sequence.chars[i..n].uniq.count == 1
# n += 1
# end
# result += (n - i).to_s
# result += num
# end
# result
# end
# Stole this :(
def look_and_say(number)
result = ''
i = 0
while i < number.length
c = number[i]
j = i
j += 1 while j < number.length && number[j] == c
result << "#{j - i}#{c}"
i = j
end
result
end
# Change to 40 times for part 1
sequences = [input]
50.times do |i|
puts "Run #{i} is #{sequences[-1].length}"
sequences.push(look_and_say(sequences[-1]))
end
puts "Part 2 Solution: #{sequences[-1].length}"
# binding.pry