about summary refs log tree commit diff
path: root/users/sterni/exercises
diff options
context:
space:
mode:
authorsterni <sternenseemann@systemli.org>2021-12-07T09·08+0100
committersterni <sternenseemann@systemli.org>2021-12-13T20·58+0100
commitb3d43057005b3bae13e113288d59a0d0941c3ded (patch)
treece869c8372f490e86979026d5684e79ed5f1dca7 /users/sterni/exercises
parent4b38ba2d0a916309351ca06cb1f20b8bca417366 (diff)
refactor(sterni/aoc/2021): allow variable bases ≤ 10 for ReadInt r/3222
Change-Id: Ie035134a4b3d478ce836aa00016122e0f49a5a28
Diffstat (limited to 'users/sterni/exercises')
-rwxr-xr-xusers/sterni/exercises/aoc/2021/solutions.bqn7
1 files changed, 4 insertions, 3 deletions
diff --git a/users/sterni/exercises/aoc/2021/solutions.bqn b/users/sterni/exercises/aoc/2021/solutions.bqn
index 463b38543f04..3a3dc82ac05e 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¨𝕩}