Paste: aoc9
Author: | jonenst |
Mode: | factor |
Date: | Sun, 9 Dec 2018 20:37:21 |
Plain Text |
: link ( node1 node2 -- ) [ prev<< ] [ swap next<< ] 2bi ;
: insert-normal ( node i -- node' )
f f <dlist-node> [
over next>> dupd
[ link ] 2bi@ ] keep ;
: unlink ( node -- )
[ [ prev>> ] [ next>> ] bi link ]
[ f >>prev f >>next drop ] bi ;
:: marble-score ( marbles players -- score )
0 :> player!
0 :> marble!
0 f f <dlist-node> dup >>next dup >>prev :> node!
H{ } clone :> scores
marbles [
marble 1 + marble!
player 1 + players mod player!
marble 23 mod zero? [
node 7 [ prev>> ] times :> tmpnode
tmpnode next>> node!
tmpnode node-value :> bonus
tmpnode unlink
marble bonus + player scores at+
] [
node next>> marble insert-normal node!
] if
] times
scores values supremum ;
New Annotation