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.
 

1.8 KiB

Solution to p14

First parse with a regex to make into a list

  (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 "))")

Implement the flow on the torus

  (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))
                       '((< <) (< >) (> <) (> >)))))
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

  (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)))

… and then grep in the folder for some pattern such as "xxxxxxxxxx"