Paste: aoc day 11 part 1

Author: Krenium
Mode: factor
Date: Tue, 11 Dec 2018 07:24:36
Plain Text |
: power-level ( x y serial# -- n )
    [ 10 + dup ] 2dip [ * ] dip + * [ 10 /mod drop ] twice 10
    mod 5 - ;

! Find the total power level of a 3x3 square.
:: 3x3-power ( x y serial# -- n )
    0 x y [ dup 2 + [a,b] ] bi@ [ serial# power-level + ]
    cartesian-each ;

! Build a hashtable where keys are coordinates from { 1 1 } to
! { 300 300 } and values are 3x3 power levels.
:: power-table ( serial# -- assoc )
    298 [1,b] dup [
        [ 2dup serial# 3x3-power [ 2array ] dip swap ,, ]
        cartesian-each
    ] H{ } make ;

: part1 ( -- )
    6042 ! My puzzle input
    power-table >alist [ second ] supremum-by first . ;

New Annotation

Summary:
Author:
Mode:
Body: