|
|
|
|
@ -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,54 +12,51 @@ 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))) |
|
|
|
|
(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)) '((< <) (< >) (> <) (> >))))) |
|
|
|
|
(funcall (cadr comp) (cadr p) (floor (* h 0.5))))) |
|
|
|
|
|
|
|
|
|
(-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"))))) |
|
|
|
|
(insert (apply #'concat (-repeat h (concat (concat (-repeat w ?. )) "\n"))))) |
|
|
|
|
|
|
|
|
|
(defun plot (p) |
|
|
|
|
(goto-line (- (cadr p) 1)) |
|
|
|
|
(move-to-column (car p)) |
|
|
|
|
(insert "x") |
|
|
|
|
(delete-char 1)) |
|
|
|
|
(defun plot (p) |
|
|
|
|
(goto-line (- (cadr p) 1)) |
|
|
|
|
(move-to-column (car p)) |
|
|
|
|
(insert "x") |
|
|
|
|
(delete-char 1)) |
|
|
|
|
|
|
|
|
|
(defun plot-pos (li) |
|
|
|
|
(-map #'plot li)) |
|
|
|
|
(defun plot-pos (li) |
|
|
|
|
(-map #'plot li)) |
|
|
|
|
|
|
|
|
|
(defun save-pic (time) |
|
|
|
|
(with-temp-buffer |
|
|
|
|
(make-bg) |
|
|
|
|
(plot-pos (--map (move (car it) (cadr it) time) data)) |
|
|
|
|
(write-file (format "test-out-%d" time)))) |
|
|
|
|
(defun save-pic (time) |
|
|
|
|
(with-temp-buffer |
|
|
|
|
(make-bg) |
|
|
|
|
(plot-pos (--map (move (car it) (cadr it) time) data)) |
|
|
|
|
(write-file (format "test-out-%d" time)))) |
|
|
|
|
|
|
|
|
|
(-map #'save-pic (-iota (* w h))) |
|
|
|
|
(-map #'save-pic (-iota (* w h))) |
|
|
|
|
#+end_src |
|
|
|
|
… and then grep in the folder for some pattern such as "xxxxxxxxxx" |
|
|
|
|
|