From 666a944c5933716a7d067786f837e4b509a1c086 Mon Sep 17 00:00:00 2001 From: sterni Date: Tue, 28 Dec 2021 17:07:12 +0100 Subject: feat(sterni/aoc/2021): day 10 solution Change-Id: I5feb7187bd9aee45478aa5759e94df49e92565bf Reviewed-on: https://cl.tvl.fyi/c/depot/+/4734 Tested-by: BuildkiteCI Reviewed-by: sterni --- users/sterni/exercises/aoc/2021/solutions.bqn | 45 +++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'users/sterni') diff --git a/users/sterni/exercises/aoc/2021/solutions.bqn b/users/sterni/exercises/aoc/2021/solutions.bqn index 45dca6fd024e..4cedb567f9aa 100755 --- a/users/sterni/exercises/aoc/2021/solutions.bqn +++ b/users/sterni/exercises/aoc/2021/solutions.bqn @@ -222,6 +222,51 @@ LargestBasinsProduct ← {×´ 3↑ ∨ 1↓ ≠¨ ⊔⥊Basins 𝕩} •Out "Day 9.2: "∾•Fmt LargestBasinsProduct day9Input +# +# 2021-12-10 +# + +day10ExampleInput ← ⟨ + "[({(<(())[]>[[{[]{<()<>>", + "[(()[<>])]({[<{<<[]>>(", + "{([(<{}[<>[]}>{[]{[(<()>", + "(((({<>}<{<{<>}{[]{[]{}", + "[[<[([]))<([[{}[[()]]]", + "[{[{({}]{}}([{[{{{}}([]", + "{<[[]]>}<{[{[{[]{()[[[]", + "[<(<(<(<{}))><([]([]()", + "<{([([[(<>()){}]>(<<{{", + "<{([{{}}[<[[[<>{}]]]>[]]", +⟩ +day10Input ← ReadInput 10 + +# part 1 + +opp ← "([{<" +clp ← ")]}>" +SwapParen ← (opp∾⌽clp)⊸((⊑⊐)⊑(⌽⊣)) + +ParenStacks ← ((<⟨⟩)⊸(((⊑∊)⟜clp⊢)◶(∾˜⟜SwapParen)‿(1⊸↓⊣)`)) +LegalParens ← ((1⊸↑)¨∘»∘ParenStacks ((∊⟜opp⊢)∨(≡⟜⋈)¨) ⊢) + +_ScoreFor_ ← {𝕗⊸(𝕘⊸⊐⊏⊣) 𝕩} + +SyntaxScore ← +´∘(0‿3‿57‿1197‿25137 _ScoreFor_ (" "∾clp))∘∾∘(1⊸↑∘(¬∘LegalParens/⊢)¨) + +! 26397 = SyntaxScore day10ExampleInput +•Out "Day 10.1: "∾•Fmt SyntaxScore day10Input + +# part 2 + +AutocompleteScore ← { + Score ← (5⊸×⊸+)˜´∘⌽∘((1+↕4) _ScoreFor_ clp) + # TODO(sterni): we compute ParenStacks twice here + ((⌊÷⟜2)∘≠⊑⊢) ∧ Score∘(⊑⌽)∘ParenStacks¨ (∧´∘LegalParens¨/⊢) 𝕩 +} + +! 288957 = AutocompleteScore day10ExampleInput +•Out "Day 10.2: "∾•Fmt AutocompleteScore day10Input + # # 2021-12-11 # -- cgit 1.4.1