Solved Day 10
parent
43c9d56726
commit
cb1283d990
|
@ -0,0 +1 @@
|
|||
3113322113
|
|
@ -0,0 +1 @@
|
|||
1
|
|
@ -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
|
Loading…
Reference in New Issue