diff --git a/13.rb b/13.rb new file mode 100644 index 0000000..251ba2b --- /dev/null +++ b/13.rb @@ -0,0 +1,42 @@ +input = File.read('input_13.txt').gsub(" ","").split("\n").map do |x| x.split(":") end.to_h +#input = {0 => 3, 1 => 2, 4 => 4, 6 => 4} +input = input.map do |k, v| [k.to_i, v.to_i] end.to_h + +def round_trip a + (a*2)-2 +end + +def do_count input + input.keys.reduce(0) do |mem, time| + p "Time: " + time.to_s + p "Range: " + input[time].to_s + p "Calc: " + (time % (round_trip input[time])).to_s + if time % (round_trip input[time]) == 0 then + cost = time * (input[time]) + mem += cost + else mem + end + end +end + +def do_count_with_delay input + i = 0 + while true do + res = 0 + input.keys.each do |time| + if (time+i) % (round_trip input[time]) == 0 then + res = 1 + end + end + if res == 0 then + return i + end + i += 1 + end +end + + + +p do_count input +p do_count_with_delay input +