diff options
author | Nguyễn Gia Phong <mcsinyx@disroot.org> | 2021-12-07 15:34:08 +0700 |
---|---|---|
committer | Nguyễn Gia Phong <mcsinyx@disroot.org> | 2021-12-07 15:34:08 +0700 |
commit | 3e6a252f664e43d0a34805d37e072c9be2c7af8e (patch) | |
tree | 5ead4b1e7d2c93d61dd080f4526c3caa037ca12b /aoc | |
parent | 231cd753962156adb2ba42e198b4b13f84fadfb4 (diff) | |
download | cp-3e6a252f664e43d0a34805d37e072c9be2c7af8e.tar.gz |
[aoc/2021] Add day 7
Diffstat (limited to 'aoc')
-rw-r--r-- | aoc/2021/07/part-one.raku | 3 | ||||
-rw-r--r-- | aoc/2021/07/part-two.raku | 4 |
2 files changed, 7 insertions, 0 deletions
diff --git a/aoc/2021/07/part-one.raku b/aoc/2021/07/part-one.raku new file mode 100644 index 0000000..81cb7d4 --- /dev/null +++ b/aoc/2021/07/part-one.raku @@ -0,0 +1,3 @@ +my @input = map +*, split ',', trim slurp 'input'; +sub cost($align) { [+] map { abs $align - $_ }, @input } +put min (cost $_ for (min @input)...(max @input)) diff --git a/aoc/2021/07/part-two.raku b/aoc/2021/07/part-two.raku new file mode 100644 index 0000000..d4934d9 --- /dev/null +++ b/aoc/2021/07/part-two.raku @@ -0,0 +1,4 @@ +my &cum = { $_ * ($_ + 1) div 2 }; +my @input = map +*, split ',', trim slurp 'input'; +sub cost($align) { [+] map { cum abs $align - $_ }, @input } +put min (cost $_ for (min @input)...(max @input)) |