[p1] better solution

master
Jacopo De Simoi 4 months ago
parent f6232959c2
commit f8f498fd25
  1. 34
      p1/p1.org

@ -23,31 +23,27 @@ number of 0's mod 100; that is what we need for part 1
#+RESULTS: #+RESULTS:
: 962 : 962
For part 2, This ain't pretty, but it works: For part 2, This works:
- we count the number of full turns that have been done in each - we count the number of full turns that have been done in each
rotation rotation. Since there are corner cases we need to average over two
- we add the number of times we landed at 0 by turning left and then offsets of ½
right immediately after; these have not been counted above
#+begin_src emacs-lisp #+begin_src emacs-lisp
(defun advent/consecutive-pairs (list) (defun advent/consecutive-pairs (list)
(-zip-pair list (cdr list))) (-zip-pair list (cdr list)))
(let ((number-list (-running-sum (append '(50) data)))) (defun average (li)
(+ (/ (-sum li) (length li)))
(-sum (--map (abs (- (car it) (cdr it)))
(advent/consecutive-pairs (let ((number-lists (--map (-running-sum (append (list it) data))
(--map (floor it 100) number-list)))) (list 50.5 49.5))))
(average (--map
(length (-sum (--map (abs (- (car it) (cdr it)))
(--filter (and (eq (car it) 0) (< (cdr it) 0)) (advent/consecutive-pairs
(-zip-pair (--map (floor it 100) it))))
(cdr (--map (mod it 100) number-list)) data))) number-lists)))
(* -1 (length
(--filter (and (eq (car it) 0) (< (cdr it) 0))
(-zip-pair
(cdr (--map (mod it 100) number-list)) (cdr data)))))))
#+end_src #+end_src
#+RESULTS: #+RESULTS:
: 5782 : 5782

Loading…
Cancel
Save