Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 3923

Teaching and learning resources • Re: Advent of Code 2024

$
0
0

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)))
Day 24 - Crossed Wires

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>
A bit of explanation is required here. As is obvious from the first few lines of code above, the wires to swap are hardcoded into this code. Part1 is the only real solution coded here. The Part2 is correct and accepted, but the code here does not actually find the answer, it only tests that it is correct.
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



Viewing all articles
Browse latest Browse all 3923

Trending Articles