You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
1.8 KiB
62 lines
1.8 KiB
#+title: Solution to p14 |
|
|
|
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") |
|
(goto-char (point-min)) |
|
(replace-regexp "^\\(#.*#\\)$" |
|
"(\"\\1\")") |
|
(goto-char (point-min)) |
|
(insert "(setq data '(") |
|
(goto-char (point-max)) |
|
(insert "))") |
|
#+end_src |
|
|
|
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-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-p it x)) |
|
newpos)) |
|
'((< <) (< >) (> <) (> >))))) |
|
#+end_src |
|
|
|
#+RESULTS: |
|
: 231852216 |
|
|
|
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"))))) |
|
|
|
(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 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))) |
|
#+end_src |
|
… and then grep in the folder for some pattern such as "xxxxxxxxxx"
|
|
|