input = File.read("day4.txt").chomp.split("-").map(&.to_i32) total = 0 (input[1] - input[0]).times do |i| invalid = false i = (input[0] + i).to_s i.chars.each_cons_pair do |c1,c2| invalid = c2 < c1 break if invalid end next if invalid # next unless i =~ /.*(.)\1.*/ past_char = nil past_count = 0 pasts = [] of Int32 i.each_char do |c| if c == past_char past_count += 1 else pasts << past_count past_count = 0 end past_char = c end pasts << past_count total += 1 if pasts.any? &.==(1) end puts total