%%bpl
#| export_bpl: true
_u ← •load "../nbaocd/utils.bpl"
_c ← •load "../nbaocd/core.bpl"get
Load puzzles and submit answers from SolveIt and Jupyter.
Get a puzzle and submit an answer
%%bpl
#| export_bpl: true
_PATTERN_YEAR ← "201[5-9]|202[0-9]"
_PATTERN_DAY ← "2[0-5]|1[0-9]|[1-9]"
_aoc_est_now ← (["zone":_c.EST_OFFSET]↣•date⁻)∘•time
_recent_year ← ⊢.year - 12>⊢.month
_cur_day_dec ← ⊢.day ⌊ (2025>⊢.year)⍚[12 25]
_strip_part ← •replace↢["part.*$" ""]
_strip_year ← •replace↢[_PATTERN_YEAR ""]
_extract_yrs ← ∪∘(↑∘(1⊃•vfi)¨)∘(⊢.text)∘(•r↢_PATTERN_YEAR)
_extract_days ← ∪∘(⊢.text)∘(•r↢_PATTERN_DAY)∘_strip_year∘_strip_part∘_u.file_name
_is_rec ← { 0=≢ρω ? $f ; (•storage ι₀ω).kind ≡ "mixed" }
_opt_get ← {
[k d] ← ω
~_is_rec α ? d ;
(⊂k) ∊ ι₀α ? k⊃α ;
d
}%%bpl
#| export_bpl: true
_most_recent_year ← {
yr ← ⌊ₓ _recent_year _aoc_est_now 0
yr < 2015ₓ ? "Time travel not supported yet" •signal _u.AocdError ;
yr
}%%bpl
#| export_bpl: true
_current_day ← {
now ← _aoc_est_now 0
12ₓ = ⌊ₓnow.month ? ⌊ₓ _cur_day_dec now ;
1ₓ
}%%bpl
#| export_bpl: true
_get_solveit_path ← { _u.env_get "SOLVEIT_DIALOG" }%%bpl
#| export_bpl: true
_extract_day_year_from_path ← {
yrs ← _extract_yrs ω
1 < ≢yrs ? "Failed introspection of year" •signal _u.AocdError ;
yr ← (0<≢yrs) {α ? ⌊ₓ↑ω ; ⍬} yrs
days ← _extract_days ω
1 = ≢days ? [(⌊ₓ↑1⊃•vfi⁝↑days) yr] ;
"Failed introspection of day" •signal _u.AocdError
}%%bpl
#| export_bpl: true
get_puzzle ← {
is_rec ← _is_rec ω
session ← is_rec {α ? ω _opt_get ["session" ⍬] ; (3≤≢ω) {α ? ω₂ ; ⍬} ω} ω
day ← is_rec {α ? ω _opt_get ["day" ⍬] ; (2≤≢ω) {α ? ω₁ ; ⍬} ω} ω
year ← is_rec {α ? ω _opt_get ["year" ⍬] ; (2≤≢ω) {α ? ω₀ ; ⍬} ω} ω
dlg ← ((day≡⍬) ∨ (year≡⍬)) {α ? _get_solveit_path 0 ; ⍬} 0
[dlg_day dlg_year] ← (dlg≢⍬) {α ? _u.AocdError :: [⍬ ⍬] ◇ _extract_day_year_from_path ω ; [⍬ ⍬]} dlg
day ← (day≡⍬)⊃[day dlg_day]
year ← (year≡⍬)⊃[year dlg_year]
tok ← (session≡⍬) {α ? _c.default_token 0 ; _u.bstr session} 0
yr ← ⌊ₓ ((year≡⍬) {α ? _most_recent_year 0 ; year} 0)
dy ← ⌊ₓ ((day≡⍬) {α ? _current_day 0 ; day} 0)
_c.Puzzle [yr dy tok]
}%%bpl
#| export_bpl: true
submit ← {
α ← ⍬:⍬
p ← α _opt_get ["puzzle" ⍬]
p ← (p≡⍬) {α ? get_puzzle ⍬ ; p} 0
α p.submit ω
}%%bpl
_assert ← { ω ? $t ; "assertion failed" •signal "ASSERT" }
[d y] ← _extract_day_year_from_path "/aoc_2025/day1.ipynb"
_assert [d y] ≡ [1ₓ 2025ₓ]
_orig_dlg ← _get_solveit_path
_get_solveit_path ← { "/aoc_2025/day1.ipynb" }
p ← get_puzzle ["session":"test-token"]
_get_solveit_path ← _orig_dlg
_assert [p.day p.year] ≡ [1ₓ 2025ₓ]
_got ← ⍬
_target ← ["submit":{ _got ⊢← [α ω] ◇ "ok" }]
_ ← ["part":"b" "reopen":$f "quiet":$t "puzzle":_target] submit 42ₓ
_assert ((_got₀).part ≡ "b") ∧ ((_got₀).reopen ≡ $f) ∧ ((_got₀).quiet ≡ $t) ∧ (_got₁ ≡ 42ₓ)