Paste: aoc13

Author: jon
Mode: factor
Date: Thu, 14 Dec 2017 16:25:58
Plain Text |
! Copyright (C) 2017 Your name.
! See http://factorcode.org/license.txt for BSD license.
USING: arrays io.encodings.ascii io.files kernel math
math.parser sequences splitting ;
IN: aoc.2017.13

: p1 ( -- n )
    "/tmp/input" ascii file-lines [ 
      ": " split harvest first2
      [ string>number ] bi@
      2dup 1 - 2 * mod zero? [ * ] [ 2drop 0 ] if
    ] map-sum ;

: p2 ( -- n )
    "/tmp/input" ascii file-lines
    [ ": " split harvest first2
    [ string>number ] bi@ 2array ] map
    [ 0 ] dip [ [ 
      first2 [ dupd + ] [ 1 - 2 * ] bi* mod zero?
    ] any? ] curry [ 1 + ] while ;

New Annotation

Summary:
Author:
Mode:
Body: