Paste: aoc day 4

Author: jonenst
Mode: factor
Date: Tue, 4 Dec 2018 09:22:18
Plain Text |
"/tmp/input" ascii file-lines
[ "[]" split second ] sort-with
[ -1 -1 ] dip
[ dup "[] " split 4 swap nth {
  { "falls" [ "[ ]:" split fourth string>number nip f ] }
  { "wakes" [ "[ ]:" split fourth string>number [ 2dup ] dip 3array ] }
  { "Guard" [ "# " split 4 swap nth string>number -rot nip f ] }
} case ] map sift 2nip natural-sort
[ first ] group-by
[ 
  [ second [ 1 tail first2 swap - 1 - ] map-sum ] sort-with
  last
  [ first ] [ second  [ 1 tail first2 [a,b) ] map concat histogram
  dup values supremum swap value-at ] bi * .
]
[ [ [ 1 tail first2 [a,b) ] map concat histogram
  dup values supremum [ swap value-at ] keep 2array ] assoc-map
  >alist [ second second ] supremum-by [ first ] [ second first ] bi * .
] bi

New Annotation

Summary:
Author:
Mode:
Body: