tvl-depot/users/sterni/exercises/aoc/2021/solutions.bqn
sterni b3d4305700 refactor(sterni/aoc/2021): allow variable bases ≤ 10 for ReadInt
Change-Id: Ie035134a4b3d478ce836aa00016122e0f49a5a28
2021-12-13 21:58:15 +01:00

70 lines
1.5 KiB
BQN
Executable file
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env BQN
#
# Utilities
#
IsAsciiNum ('0''9')
ReadInt {(𝕨×+)´-'0'𝕩} # stolen from leah2
ReadDec 10ReadInt
ReadInput {•file.Lines •path"/input/day"(•Fmt 𝕩)}
#
# 2021-12-01
#
# part 1
day1ExampleData 199200208210200207240269260263
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
PositiveDeltaCount +´(<«)+˝˘
! 7 = 1 PositiveDeltaCount day1ExampleData
•Out "Day 1.1: "•Fmt 1 PositiveDeltaCount day1Input
# part 2
! 5 = 3 PositiveDeltaCount day1ExampleData
•Out "Day 1.2: "•Fmt 3 PositiveDeltaCount day1Input
#
# 2021-12-02
#
# part 1
day2ExampleData
"forward 5",
"down 5",
"forward 8",
"up 3",
"down 8",
"forward 2",
day2Input ReadInput 2
ParseSubmarineCommand (((2)((((-1))(2|))×(=((÷2))))("duf"))×ReadDec(IsAsciiNum/))
SubmarineDestProduct {×´+´ParseSubmarineCommand¨𝕩}
! 150 = SubmarineDestProduct day2ExampleData
•Out "Day 2.1: "•Fmt SubmarineDestProduct day2Input
# part 2
SubmarineAimedDestProduct {
×´+´((×´)(1)(1))¨ (<000) ((()+()))` ParseSubmarineCommand¨𝕩
}
! 900 = SubmarineAimedDestProduct day2ExampleData
•Out "Day 2.2: "•Fmt SubmarineAimedDestProduct day2Input