From b3d43057005b3bae13e113288d59a0d0941c3ded Mon Sep 17 00:00:00 2001 From: sterni Date: Tue, 7 Dec 2021 10:08:13 +0100 Subject: refactor(sterni/aoc/2021): allow variable bases ≤ 10 for ReadInt MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Ie035134a4b3d478ce836aa00016122e0f49a5a28 --- users/sterni/exercises/aoc/2021/solutions.bqn | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'users/sterni') diff --git a/users/sterni/exercises/aoc/2021/solutions.bqn b/users/sterni/exercises/aoc/2021/solutions.bqn index 463b38543f..3a3dc82ac0 100755 --- a/users/sterni/exercises/aoc/2021/solutions.bqn +++ b/users/sterni/exercises/aoc/2021/solutions.bqn @@ -6,7 +6,8 @@ IsAsciiNum ← ('0'⊸≤∧≤⟜'9') -ReadInt ← (10⊸×+⊣)´∘⌽-⟜'0' # stolen from leah2 +ReadInt ← {(𝕨⊸×+⊣)´∘⌽-⟜'0'𝕩} # stolen from leah2 +ReadDec ← 10⊸ReadInt ReadInput ← {•file.Lines ∾ •path‿"/input/day"‿(•Fmt 𝕩)} @@ -17,7 +18,7 @@ ReadInput ← {•file.Lines ∾ •path‿"/input/day"‿(•Fmt 𝕩)} # part 1 day1ExampleData ← 199‿200‿208‿210‿200‿207‿240‿269‿260‿263 -day1Input ← ReadInt¨ReadInput 1 +day1Input ← ReadDec¨ReadInput 1 # 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 @@ -50,7 +51,7 @@ day2ExampleData ← ⟨ day2Input ← ReadInput 2 -ParseSubmarineCommand ← (((↕2)⊸((((-1)⊸⋆)∘(2⊸|))×(=⟜(⌊∘(÷⟜2))))∘("duf"⊸⊐)∘⊑)×ReadInt∘(IsAsciiNum/⊢)) +ParseSubmarineCommand ← (((↕2)⊸((((-1)⊸⋆)∘(2⊸|))×(=⟜(⌊∘(÷⟜2))))∘("duf"⊸⊐)∘⊑)×ReadDec∘(IsAsciiNum/⊢)) SubmarineDestProduct ← {×´+´ParseSubmarineCommand¨𝕩} -- cgit 1.4.1