parent
b31274625b
commit
d987405a93
1 changed files with 35 additions and 0 deletions
@ -0,0 +1,35 @@ |
|||||||
|
#+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 |
||||||
|
|
||||||
Loading…
Reference in new issue