Code:
;;; Advent of code 2024 - day24, part1 & part2, on BPI-F3 RISC-V;;; Chez code(load "utils.so")(define table (make-hashtable string-hash string=? 256))(define swap-acc '(("z08" "ffj") ("dwp" "kfm") ("z22" "gjh") ("z31" "jdr")))(define *gatesf* '())(define (make-function lw fs rw) (let ((LF (case fs (("AND") logand) (("XOR") logxor) (else logor)))) (letrec ((func (lambda ()(let ((l (hashtable-ref table lw #f)) (r (hashtable-ref table rw #f))) (if (and (number? l) (number? r)) (LF l r) func))))) func)))
Code:
> (compile-file "day24-final.ss")compiling day24-final.ss with output to day24-final.so> (load "day24-final.so")> (time2 (lambda () (day24 "input.txt")))63168299811048"dwp,ffj,gjh,jdr,kfm,z08,z22,z31"#<time-duration 0.025898089>
Finding the answer for part2, involved first understanding how binary numbers are added (without using +), and then writing (mostly interactively - in running Scheme) dozens of small functions to inspect the gate-tree, as it evolved during the program execution. Finally after I had all this data, I decided myself which wires to swap.
Statistics: Posted by hrvoje064 — Wed Jan 15, 2025 4:20 am