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.
35 lines
789 B
35 lines
789 B
#+title: Solution to p9 |
|
|
|
#+begin_src emacs-lisp :results none |
|
(with-temp-buffer |
|
(insert-file-contents "input") |
|
(advent/replace-multiple-regex-buffer |
|
'(("," . " ") |
|
("^" . "(") |
|
("$" . ")"))) |
|
(goto-char (point-min)) |
|
(insert "(setq data '(") |
|
(goto-char (point-max)) |
|
(insert "))") |
|
(eval-buffer)) |
|
#+end_src |
|
|
|
Find max area |
|
#+begin_src emacs-lisp |
|
(defun area (el) |
|
(let ((a (car el)) |
|
(b (cdr el))) |
|
(abs (* (- (car a) (car b) -1) |
|
(- (cadr a) (cadr b) -1))))) |
|
|
|
(defun symmetric-pairs (list) |
|
(apply #'append (--map-indexed (-map (lambda (other) (cons it other)) |
|
(-drop (1+ it-index) list)) |
|
list))) |
|
|
|
(-max (-map 'area (symmetric-pairs data))) |
|
#+end_src |
|
|
|
#+RESULTS: |
|
: 4737096935 |
|
|
|
|