;; // https://adventofcode.com/2022/day/21 ;; well, this seems like this could be done with (eval) ;; would it be possible for me to also translate ;; xxx + yyy into (call xxx) + (call yyy) ;; that would be neat (in-package :day-21) ;; so. have mashmap from symbol name into operation ;; and have (my-eval)? ;; it will take symbol name, and either return number directly from the map ;; or will wrap the names into my-eval and run operation on them? ;; is there a way to have less code and reuse existing lisp things? ;; if there's direct number, i could just run (defparameter lfqf 4) ;; and then execute root directly, i think ;; or what, i'd need to also define all the intermediate symbols, ;; (setq a (+ c d)) ; complains that C is unbound ;; how could this be a lazy eval? ;; well. hm ;; i could define all of these as macroses? (defmacro *test-monkey-hmdt* () 32) (+ 3 (*test-monkey-hmdt*)) ;; yup, i guess (defparameter *test-monkey-sllz* 4) (eval *test-monkey-sllz*) (defparameter *test-monkey-ljgn* 2) (defparameter *my-operation* '(+ *test-monkey-sllz* *test-monkey-ljgn*)) *my-operation* (eval *my-operation*) ; well, that works ok ;; so, read all of these things as parameters. ;; "root: pppw + sjmn " (mapcar #'intern (ppcre:split " " "root: pppw + sjmn ")) (mapcar #'parse-integer-or-symbol (ppcre:split " " "root: 44")) (ppcre:regex-replace ":" "root: pppw + sjmn " "") (line-to-quoted-operation "root: pppw + sjmn") (eval (line-to-quoted-operation "dbpl: 5")) ;; well, i'd want to put quoted expression into parameter? ;; and now i can remove quoting of the defparameter? ;; and actually define all of the parameters? (loop for line in (uiop:read-file-lines "day21-test.txt") for definition = (line-to-quoted-operation line) do (eval definition)) (eval root) ;; (load-file-defs "day21-test.txt") ;; (eval root) ;; (load-file-defs "day21-input.txt") ;; (print (eval root)) ;; now. things are different. ;; HUMN is my input ;; and ROOT is "comparison of two numbers" ;; and change in root can influence results in a significant way ;; so, how'd i do that? ;; ;; what could be done then? ;; i could potentially somehow modify the operations? ;; so that (eval humn) would return ;; ;; root: pppw + sjmn ;; so. root should mean ;; pppw == sjmn ;; don't know which has HUMN yet. ;; should i then just eval those that have HUMN into a operation? ;; and others into a number? ;; well, i suppose i'd need to do pass down somehow ;; eval both parts of the root. ;; and then what? ;; ;; let's skip for now? ;; or, alternatively. i could save HUMN num disregard ;; defparameter with HUMN to be used as HUMN = ;; and then what? root ;; but then i'd need to reverse all the other operations, hm ;; or, maybe i could join into flat expression? ;; and then what? i macroexpand? ;; ;; now. i had an idea. i could have additional symbols, ;; also pointing to quoted computations ;; but these would be `back-ptdq` ;; for line 'lgvd: ljgn * ptdq' ;; make two? for each ;; ;; ptdq: humn - dvpt ;; back-humn = ptdq + dvpt ;; but one of these wouldn't be possible to forward eval, so it would be back-ptdq + dvpt ;; and on ;; root: pppw + sjmn ;; two would be created back-pppw = - eval sjmn and vice versa ;; this should work? ;; sure, let's try? ;; so we'd do what? ;; same for forward eval? ;; and two for back-monkey (back-symbol 'hello) (intern (format nil "BACK-~a" 'yo)) ;; and i need reverse of the operands? (reverse-operation '+) (line-to-quoted-operation-2 "dbpl: 5") (line-to-quoted-operation-2 "pppw: cczh / lfqf") (line-to-quoted-operation-2 "lgvd: ljgn * ptdq") (line-to-quoted-operation-2 "drzm: hmdt - zczc") (line-to-quoted-operation-2 "cczh: sllz + lgvd") (line-to-quoted-operation-2 "root: pppw + sjmn") ;; i think it's done? let's try to eval all of this? ;; but i also need root back-computation. ;; for each operant that they are equal to forward calculation of another ;; (load-file-defs-2 "day21-test.txt") ;; (eval root) ;; (eval back-humn) ; 301. cool ;; (load-file-defs-2 "day21-input.txt") ;; (print (eval back-humn)) ;; 3715799488132