From 04e2349bd08f9ecd7ce93bf5b03e413fa6d51f96 Mon Sep 17 00:00:00 2001 From: Jacopo De Simoi Date: Sat, 20 Sep 2025 09:55:46 -0400 Subject: [PATCH] [p22] part 1 --- p22/p22.org | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 p22/p22.org 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