From ff0d1bd0afcddd5a61cea8d7afe504abb9a1480c Mon Sep 17 00:00:00 2001 From: Aleteoryx Date: Tue, 2 Dec 2025 12:35:02 -0500 Subject: [PATCH] ascii math routines --- aoc/2025/02.1.tal | 143 +++++++++++++++++++++++++++++++++++++++++ aoc/2025/02.input.test | 1 + aoc/2025/mkfile | 4 +- 3 files changed, 147 insertions(+), 1 deletion(-) create mode 100644 aoc/2025/02.1.tal create mode 100644 aoc/2025/02.input.test diff --git a/aoc/2025/02.1.tal b/aoc/2025/02.1.tal new file mode 100644 index 0000000000000000000000000000000000000000..b4136083492ecbc466939c84094cc6a2a28d3f57 --- /dev/null +++ b/aoc/2025/02.1.tal @@ -0,0 +1,143 @@ +( advent of code 2025, day 2, first star ) + +%dbg { #010e DEO } + + +|00 +@Buffers/num $f &endnum $1 +@Buffers/end $f &endend $1 + +$1 @Buffers/read $f &endread $1 + +@Buffers/sum $1f &endsum $1 + + +|100 +@on-reset ( -> ) + banner + first-star + BRK + +@banner ( -- ) + ;/str !puts +@banner/str + "advent 20 "of 20 "code 20 "2025, 20 "day 20 "2, 20 "first 20 "star 0a 00 + + +( first star ) + +@astr $1 "89 &end "5 $1 +@bstr $1 "10 &end "9 $1 + +@first-star ( -- ) + ;astr/end ;bstr/end sumstrs + + ;astr puts endl + + ( Input/read ) + JMP2r + +@first-star/on-input ( b -- ) + JMP2r + + +( stdlib ) + +@endl ( n -- ) + #0a18 DEO JMP2r + +@puts ( str* -- ) + LDAk #18 DEO + INC2 LDAk ?puts + + POP2 JMP2r + +@putdec2 ( n* -- ) + [ LITr 00 ] + + &loop + #000a DIV2k STH2k + MUL2 SUB2 + [ LIT "0 ] ADD NIP + STH2r ROT STH + ORAk ?/loop + POP2 + + &loop2 + STHr #18 DEO + STHrk ?/loop2 + POPr JMP2r + +@incs ( n* -- ) + LDAk ?{ + [ LIT "1 ] + ROT ROT STA + JMP2r + } + + LDAk + [ LIT "9 ] NEQ ?{ + DUP2 + [ LIT "0 ] + ROT ROT STA + &subone + #0001 SUB2 !incs + } + LDAk INC + ROT ROT STA + JMP2r + +@findend ( p* -- p* ) + INC2 LDAk ?findend + JMP2r + +@sumstrs ( a* b* -- ) ( takes pointers to the last digits of each number ) + LDAk STH SWP2 LDAk STHr ( b* a* ac bc ) dbg + DUP ?{ POP2 POP2 POP2 JMP2r } ( we've reached the end of b ) + OVR ?{ NIP [ LIT "0 ] } ( if we're at the end of a, pad with 0s ) + [ LIT2 "00 ] SUB2 ADD ( b* a* a+b ) + DUP #0a LTH ?{ ( overflow ) + #0a SUB STH + DUP2 incs/subone ( carry ) + STHr + } + [ LIT "0 ] ADD ( convert back to ascii ) + ROTk ROT STA POP ( save digit ) + #0001 SUB2 + SWP2 #0001 SUB2 + !sumstrs ( loop! ) + + +( object lib ) + +@Input/filename "02.input.test 00 +@Input/read ( -- ) + #01ab DEO + ;/filename #a8 DEO2 + + &loop + ;/byte #ac DEO2 + #a3 DEI #00 EQU ?/endloop ( EOF ) + [ LIT &byte $1 ] + first-star/on-input + !/loop + + &endloop + POP2 JMP2r + + +@Number/one-byte ( b -- ) + #00 SWP + LIT "0 SUB + [ LIT2 &val 0000 ] + #000a MUL2 ADD2 + ,/val STR2 + JMP2r +@Number/get ( -- n* ) + ,/val LDR2 JMP2r +@Number/reset ( -- ) + #0000 ,/val STR2 JMP2r + + +( problem code ) + diff --git a/aoc/2025/02.input.test b/aoc/2025/02.input.test new file mode 100644 index 0000000000000000000000000000000000000000..a3f22ef5de6c26c9ee54949f7b4b8e65ffb183b8 --- /dev/null +++ b/aoc/2025/02.input.test @@ -0,0 +1 @@ +11-22,95-115,998-1012,1188511880-1188511890,222220-222224,1698522-1698528,446443-446449,38593856-38593862,565653-565659,824824821-824824827,2121212118-2121212124 diff --git a/aoc/2025/mkfile b/aoc/2025/mkfile index bf3e74f9f4f7af72f237a6887e3ecd341218689a..9ef7b7cb75965dd7d199f80a0ec0dae5b1b69258 100644 --- a/aoc/2025/mkfile +++ b/aoc/2025/mkfile @@ -1,4 +1,6 @@ -DAYS=01.1.rom 01.2.rom +DAYS=\ + 01.1.rom 01.2.rom\ + 02.1.rom all:VQ: $DAYS