Paste: advent01
Author: | jon |
Mode: | factor |
Date: | Fri, 1 Dec 2017 17:24:17 |
Plain Text |
USING: assocs kernel math math.parser sequences sequences.extras ;
IN: 2017.advent01
: p ( str n -- sum )
dupd rotate
zip [ first2 = ] filter
[ first digit> ] map-sum ;
: p1 ( str -- sum ) 1 p ;
: p2 ( str -- sum ) dup length 2 / p ;
USING: tools.test 2017.advent01 ;
IN: 2017.advent01.tests
{ 3 } [ "1122" p1 ] unit-test
{ 4 } [ "1111" p1 ] unit-test
{ 0 } [ "1234" p1 ] unit-test
{ 9 } [ "91212129" p1 ] unit-test
{ 6 } [ "1212" p2 ] unit-test
{ 0 } [ "1221" p2 ] unit-test
{ 4 } [ "123425" p2 ] unit-test
{ 12 } [ "123123" p2 ] unit-test
{ 4 } [ "12131415" p2 ] unit-test
"2017.advent01" test
New Annotation