Cleanup solution to p14

main
Jacopo De Simoi 11 months ago
parent c7204bf0b4
commit c50dd707ae
  1. 32
      p14/p14.org

@ -1,6 +1,7 @@
#+title: Solution to p14
First parse with regex to make into a list
#+begin_src emacs-lisp
First parse with a regex to make into a list
#+begin_src emacs-lisp :results none
(require 'dash)
(with-temp-buffer
(insert-file-contents "input-test")
@ -11,35 +12,32 @@ First parse with regex to make into a list
(insert "(setq data '(")
(goto-char (point-max))
(insert "))")
(write-file "tmp"))
#+end_src
#+RESULTS:
Implement the flow on the torus
#+begin_src emacs-lisp
(defun move (p v time)
(list (mod (+ (car p) (* time (car v))) w)
(mod (+ (cadr p) (* time (cadr v))) h)))
(setq newpos (--map (move (car it) (cadr it) 100) data))
(defun quadrant (comp p)
(defun quadrant-p (comp p)
(and (funcall (car comp) (car p) (floor (* w 0.5)))
(funcall (cadr comp) (cadr p) (floor (* h 0.5)))))
(-reduce '* (--map (length (-filter (lambda (x) (quadrant it x)) newpos)) '((< <) (< >) (> <) (> >)))))
(-reduce '* (--map (length (-filter (lambda (x) (quadrant-p it x))
newpos))
'((< <) (< >) (> <) (> >)))))
#+end_src
#+RESULTS:
: 231852216
the second part is... meh. try and filter frames and check them
by some properties
#+begin_src emacs-lisp :results none
(defun flip (p)
(list (- w (car p) 1) (cadr p)))
(defun symmetric-p (li)
(eq (length (-intersection li (-map #'flip li))) (length li)))
#+end_src
the second part is... meh. try and filter frames and check them by
some properties; for instance we could check for a long enough
horizontal line. Save the frames in plain text and then we can use
grep later
#+begin_src emacs-lisp
(defun make-bg ()
(insert (apply #'concat (-repeat h (concat (concat (-repeat w ?. )) "\n")))))

Loading…
Cancel
Save