From 2563a66d9ca321d6df4b5eb0d6c010fdf4f357ea Mon Sep 17 00:00:00 2001 From: Alexander Munch-Hansen Date: Tue, 5 Dec 2017 23:33:24 +0100 Subject: [PATCH] Fifth day --- searching_for_nil.rb | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 searching_for_nil.rb diff --git a/searching_for_nil.rb b/searching_for_nil.rb new file mode 100644 index 0000000..66ef6ce --- /dev/null +++ b/searching_for_nil.rb @@ -0,0 +1,26 @@ +input = File.read("input_lol").split("\n").map(&:to_i) + +i1 = 0 +res1 = 0 + +part1 = input.dup +while part1[i1] != nil do + curr1, part1[i1] =i1 + part1[i1], part1[i1] + 1 + i1, res1 = curr1, res1+1 +end + +puts res1 + +i2 = 0 +res2 = 0 + +part2 = input.dup +while part2[i2] != nil do + curr2, part2[i2] =i2 + part2[i2], part2[i2] + (if part2[i2] >= 3 then -1 else 1 end) + i2, res2 = curr2, res2+1 +end + +puts res2 + + +