diff options
author | Andinus <andinus@nand.sh> | 2021-12-01 21:05:35 +0530 |
---|---|---|
committer | Andinus <andinus@nand.sh> | 2021-12-01 21:05:35 +0530 |
commit | 72984202e1da518ee4b3201369ed50699bb840b0 (patch) | |
tree | 44d04aceedd7ada8436a9db031fb22432a450270 /2021/day-01/day-01.raku | |
parent | 4fc55ef1d5526af3ee2f51fa545a25495328bb7c (diff) | |
download | aoc-72984202e1da518ee4b3201369ed50699bb840b0.tar.gz |
Add 2021/day-01 solution
Diffstat (limited to '2021/day-01/day-01.raku')
-rw-r--r-- | 2021/day-01/day-01.raku | 23 |
1 files changed, 23 insertions, 0 deletions
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; +} |