diff options
author | sterni <sternenseemann@systemli.org> | 2021-12-01T12·04+0100 |
---|---|---|
committer | sterni <sternenseemann@systemli.org> | 2021-12-01T18·17+0000 |
commit | 9472bb6b043d5d425b9d1ec0d187155b1ac2b7cb (patch) | |
tree | d3a0b5845ce9641d6249278d9eab9505ca526d2b | |
parent | 236b2bcd74016c9cb655b5c466c8477c285d7238 (diff) |
feat(sterni/aoc/2021): day 1 solution r/3128
Change-Id: I0781b2aa3624df9a3158296edcbbbf2ee845102b
-rw-r--r-- | users/sterni/exercises/aoc/.gitignore | 1 | ||||
-rwxr-xr-x | users/sterni/exercises/aoc/2021/solutions.bqn | 31 |
2 files changed, 32 insertions, 0 deletions
diff --git a/users/sterni/exercises/aoc/.gitignore b/users/sterni/exercises/aoc/.gitignore new file mode 100644 index 000000000000..de53cfc531cb --- /dev/null +++ b/users/sterni/exercises/aoc/.gitignore @@ -0,0 +1 @@ +/*/input \ No newline at end of file diff --git a/users/sterni/exercises/aoc/2021/solutions.bqn b/users/sterni/exercises/aoc/2021/solutions.bqn new file mode 100755 index 000000000000..98d70f8f15cf --- /dev/null +++ b/users/sterni/exercises/aoc/2021/solutions.bqn @@ -0,0 +1,31 @@ +#!/usr/bin/env BQN + +# +# Utilities +# + +ReadInt ← (10⊸×+⊣)´∘⌽-⟜'0' # stolen from leah2 + +ReadInput ← {ReadInt¨•file.Lines ∾ •path‿"/input/day"‿(•Fmt 𝕩)} + +# +# 2021-12-01 +# + +# part 1 + +day1ExampleData ← 199‿200‿208‿210‿200‿207‿240‿269‿260‿263 + +# NB: Because distance from the ground is never smaller than zero, it's +# no problem that nudge inserts a zero at the end of the right list +PositiveDeltaCount ← +´∘(⊢<«)+˝˘∘↕ + +! 7 = 1 PositiveDeltaCount day1ExampleData + +•Out "Day 1.1: "∾•Fmt 1 PositiveDeltaCount ReadInput 1 + +# part 2 + +! 5 = 3 PositiveDeltaCount day1ExampleData + +•Out "Day 1.2: "∾•Fmt 3 PositiveDeltaCount ReadInput 1 |