Paste: factor day1
Author: | Recruit |
Mode: | factor |
Date: | Thu, 2 Dec 2021 18:51:47 |
Plain Text |
USING: kernel shuffle io io.encodings.utf8 io.files prettyprint
math math.parser formatting arrays sequences splitting ;
IN: day1
: move2-infront ( x y z -- z x y )
2over [ 2drop ] 3dip
;
: get-nth-elems ( i seq -- elemI elemI+1 )
2dup
nth
move2-infront
[ 1 + ] dip
nth
;
: increase-count ( c i seq -- c+1 i seq )
rot 1 + -rot
;
: increase-idx ( c i seq -- c i+1 seq )
swap 1 + swap
;
: main ( -- )
"depths.txt" utf8 file-lines [ string>number ] map
dup length
1 - [ 0 0 ] 2dip [
2dup
get-nth-elems < [
increase-count
] [ ] if
increase-idx
] times
2drop
.
;
MAIN: main
New Annotation