From 72984202e1da518ee4b3201369ed50699bb840b0 Mon Sep 17 00:00:00 2001 From: Andinus Date: Wed, 1 Dec 2021 21:05:35 +0530 Subject: Add 2021/day-01 solution --- 2021/day-01/day-01.raku | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 2021/day-01/day-01.raku (limited to '2021/day-01/day-01.raku') diff --git a/2021/day-01/day-01.raku b/2021/day-01/day-01.raku new file mode 100644 index 0000000..ae77c28 --- /dev/null +++ b/2021/day-01/day-01.raku @@ -0,0 +1,23 @@ +#!/usr/bin/env raku + +my Int @inputs = "input".IO.lines>>.Int; + +{ + my Int $larger-than-previous = 0; + + for (^@inputs.elems).skip -> $idx { + $larger-than-previous++ if @inputs[$idx] > @inputs[$idx - 1]; + } + + put "Part 1: ", $larger-than-previous; +} + +{ + my Int $larger-than-previous = 0; + + for (^@inputs.elems).skip(3) -> $idx { + $larger-than-previous++ if @inputs[$idx - 2 .. $idx].sum > @inputs[$idx - 3 .. $idx - 1].sum; + } + + put "Part 2: ", $larger-than-previous; +} -- cgit 1.4.1-2-gfad0