From b5678cbd5f55e2f3f96a1d67cb07c3545a6c9ffe Mon Sep 17 00:00:00 2001 From: sterni Date: Thu, 16 Dec 2021 00:46:00 +0100 Subject: feat(sterni/aoc/2021): day 14 solution Change-Id: I8b6c0c5d1ced89eadaeea3fb619d37e77a439965 Reviewed-on: https://cl.tvl.fyi/c/depot/+/4349 Tested-by: BuildkiteCI Reviewed-by: sterni --- users/sterni/exercises/aoc/2021/solutions.bqn | 33 +++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'users/sterni/exercises/aoc') diff --git a/users/sterni/exercises/aoc/2021/solutions.bqn b/users/sterni/exercises/aoc/2021/solutions.bqn index 47e858cff588..f240e7dc2d11 100755 --- a/users/sterni/exercises/aoc/2021/solutions.bqn +++ b/users/sterni/exercises/aoc/2021/solutions.bqn @@ -245,3 +245,36 @@ DotMatrix ← { •Out "Day 13.2:" •Out •Fmt DotMatrix day13Folds PerformAllFolds day13Dots + +# +# 2021-12-14 +# + +day14Polymer ← ⊑ReadInput 14 +day14Mapping ← 2↓ReadInput 14 + +lp ← (2⊸↑)¨ day14Mapping +le ← ⍷∾lp + +# returns array as long as 𝕨 detailing how many times the element +# at any given index occurs in 𝕩. +Counts ← ((≠⊣)↑(/⁼)∘⊐) + +deltaPairs ← { + addedPairs ← ((-1)⊸⊑¨day14Mapping) (⌽⌾(0⊸⊑))∘(∾¨)¨ lp + removedPairs ← ⋈¨ (2⊸↑)¨ lp + addedPairs (-○(lp⊸Counts))¨ removedPairs +} + +pairCount ← lp Counts ⥊∘(⋈˘) 2↕day14Polymer + +PairInsert ← {𝕩 +´ 𝕩רdeltaPairs} + +pairElementCount ← (le⊸Counts)¨lp + +ElementRarityDiff ← { + ((-1)⊸⊑-⊑)∧ ⌈2÷˜ +´ pairElementCount×PairInsert⍟𝕩 pairCount +} + +•Out "Day 14.1: "∾•Fmt ElementRarityDiff 10 +•Out "Day 14.2: "∾•Fmt ElementRarityDiff 40 -- cgit 1.4.1