! 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 ;