6.rb 300 B

12345678910111213141516
  1. require 'set'
  2. @input = File.read("6.input").split("\n")
  3. def part(window_size)
  4. @input[0].chars.each_with_index do |c, i|
  5. chunk = @input[0].chars[(i..i+(window_size-1))]
  6. if Set.new(chunk).length == window_size then
  7. puts i + window_size
  8. break
  9. end
  10. end
  11. end
  12. part(4)
  13. part(14)