advent-of-code-2025

Unnamed repository; edit this file 'description' to name the repository.
git clone git://git.alexwennerberg.com/advent-of-code-2025.git
Log | Files | Refs | README | LICENSE

01.f (713B)


      1 \ util
      2 4545 constant input-size 
      3 : tibs ( -- a u ) tib >limit @ tib - ;
      4 : s>n ( a u -- n ) 0 -rot 0 do dup r@ + c@ h# 30 - rot 10 * + swap loop drop ;
      5 : floor// ( n1 n2 -- n ) /mod swap 0< if 1- then ;
      6 
      7 \ solution
      8 variable password
      9 variable passwordB 
     10 : turn-val ( a u -- n ) over c@ [char] O - 3 / -rot 1 /string s>n * ;
     11 : wrap-100 ( n -- n ) dup 100 floor-mod 100 * - ;
     12 : turn ( old -- new ) dup query tibs turn-val >r r@ +
     13         ( old new )
     14         2dup r> 0< if 1- swap 1- then \ border fix
     15         100 floor// 100 floor// - abs passwordB +! 
     16         nip ( new ) wrap-100 dup 0= if 1 password +! then ;
     17 : solve ( -- ) 50 input-size 0 do turn loop drop
     18     password @ . cr 
     19     passwordB @ . cr bye ; 
     20 solve