Created
December 24, 2021 06:43
-
-
Save tdrhq/74a1c9100851066d1363d89872bbd4e1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun decompile (lines) | |
(let ((lines (mapcar (lambda (x) | |
(read-from-string (format nil "(~a)" x))) | |
lines))) | |
(let ((expr `(when (= z 0) | |
(return-from do-run choices))) | |
(inp 0)) | |
(loop for line in (reverse lines) do | |
(destructuring-bind (cmd a &optional b) line | |
(let ((decl `(declare (type fixnum ,a)))) | |
(setf expr | |
(ecase cmd | |
(add `(let ((,a (+ ,a ,b))) | |
,decl | |
,expr)) | |
(mul `(let ((,a (* ,a ,b))) | |
,decl | |
,expr)) | |
(eql `(let ((,a (if (eql ,a ,b) 1 0))) ,decl ,expr)) | |
(div `(let ((,a (floor ,a ,b))) ,decl ,expr)) | |
(mod `(let ((,a (mod ,a ,b))) ,decl ,expr)) | |
(inp | |
(incf inp) | |
`(with-input (lambda (,a) (declare (optimize (speed 3))) | |
,decl | |
#+nil | |
,(when (= 7 inp) | |
`(log:info "Current values: ~s, ~s, ~s" x y z)) | |
(symbol-macrolet ((key | |
(gethash (list ,inp | |
x y z | |
,a) | |
cache))) | |
(or key | |
(setf key | |
,expr))))))))) | |
(eval `(defun do-run () | |
(declare (optimize (speed 3) (safety 0) (debug 0))) | |
(let ((choices nil) | |
(cache (make-hash-table :test 'equal)) | |
(len 0)) | |
(declare (type fixnum divisor)) | |
(let ((x 0) (y 0) (w 0) (z 0)) | |
(flet ((with-input (fn) | |
(push nil choices) | |
(incf len) | |
(when (= 7 len) | |
(log:info "looking at: ~s" (cdr choices) )) | |
(loop for i from 1 to 9 do | |
(progn | |
(setf (car choices) i) | |
(funcall fn i))) | |
(decf len) | |
(pop choices))) | |
,expr))))) | |
(compile 'do-run) | |
))))) | |
(do-run) | |
(loop for i from (expt 9 14) 0 | |
for actual = (let ((i i)) | |
(loop while ))) | |
(test simple | |
(decompile (uiop:read-file-lines "~/builds/web/input")) | |
(pass)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment