Paste: aoc22 p1

Author: jon
Mode: factor
Date: Wed, 2 Jan 2019 17:08:00
Plain Text |
DEFER: erosion-level

: (geologic-index) ( pos -- n )
{
  { [ dup second zero? ] [ first 16807 * ] }
  { [ dup first zero? ] [ second 48271 * ] }
  [ { -1 0 } { 0 -1 } [ v+ erosion-level ] bi-curry@ bi * ]
} cond ;
: geologic-index ( pos -- n )
{
 { {    0    0 } [ 0 ] }
 { { 5746 5746 } [ 0 ] }
 [ (geologic-index) ] 
} case ;
MEMO: erosion-level ( pos -- n ) geologic-index 4002 + 20183 mod ;
: danger ( pos -- n ) erosion-level 3 mod ;

0 5746 [a,b] dup cartesian-product concat [ danger ] map-sum 

New Annotation

Summary:
Author:
Mode:
Body: