diff --git a/p22/p22.org b/p22/p22.org new file mode 100644 index 0000000..c08f9ed --- /dev/null +++ b/p22/p22.org @@ -0,0 +1,42 @@ +#+title: Solution to p22 + +#+begin_src emacs-lisp :results none + (require 'dash) + (with-temp-buffer + (insert-file-contents "input") + (goto-char (point-min)) + (insert "(setq data '(") + (goto-char (point-max)) + (insert "))") + (eval-buffer)) +#+end_src + +#+begin_src emacs-lisp :results none + (defun mix (a b) + (logxor a b)) + + (defun prune (a) + (logand a 16777215)) + + (defun pseudo-next-1 (a) + (prune (mix a (ash a 6)))) + + (defun pseudo-next-2 (a) + (prune (mix a (ash a -5)))) + + (defun pseudo-next-3 (a) + (prune (mix a (ash a 11)))) + + (defun pseudo-next (a) + (pseudo-next-3 + (pseudo-next-2 + (pseudo-next-1 a))) + ) + #+end_src + +#+begin_src emacs-lisp + (apply #'+ (--map (-last-item (-iterate 'pseudo-next it 2001)) data)) +#+end_src + +#+RESULTS: +: 19241711734