1 Constant example
: num: ( c-) parse evaluate , ;
: pair: ( -) '=' parse 2drop ',' num: bl num: ;
: r: ( -) pair: pair: ;
: robots: ( -u) BEGIN refill WHILE r: REPEAT ;
here example [IF]
r: p=0,4 v=3,-3
r: p=6,3 v=-1,-3
r: p=10,3 v=-1,2
r: p=2,0 v=2,-1
r: p=0,0 v=1,3
r: p=3,0 v=-2,-2
r: p=7,6 v=-1,-3
r: p=3,0 v=-1,-2
r: p=9,3 v=2,3
r: p=7,3 v=-1,2
r: p=2,4 v=2,-3
r: p=9,5 v=-3,-3
[ELSE]
s" input" r/o bin open-file throw
dup ' robots: execute-parsing-file \ '
close-file throw
[THEN] here swap
2Constant robots
: @+ ( a-na) dup @ swap cell+ ;
: +mod! ( nna-) tuck @ + rot mod swap ! ;
: both ( nn-f) 0<> swap 0<> and ;
0 Field: x Field: y
Field: dx Field: dy Constant /robot
example [IF] 11 7 [ELSE] 101 103 [THEN]
Constant ny Constant nx
: seconds ( u-) robots DO
nx over i dx @ * i x +mod!
ny over i dy @ * i y +mod!
/robot +LOOP drop ;
Create quads 4 cells allot
: th-quad ( xy-a) 0> -2 * swap 0> -1 * +
cells quads + ;
: sum-quads ( -) quads 4 cells erase robots DO
i x @ nx 2/ - i y @ ny 2/ - 2dup both
IF th-quad 1 swap +! THEN /robot +LOOP ;
: safety-factor ( -n) sum-quads
quads @+ @+ @+ @ * * * ;
100 seconds safety-factor .
MSBDb25zdGFudCBleGFtcGxlCgo6IG51bTogKCBjLSkgcGFyc2UgZXZhbHVhdGUgLCA7CjogcGFpcjogKCAtKSAnPScgcGFyc2UgMmRyb3AgJywnIG51bTogYmwgbnVtOiA7CjogcjogKCAtKSBwYWlyOiBwYWlyOiA7Cjogcm9ib3RzOiAoIC11KSBCRUdJTiByZWZpbGwgV0hJTEUgcjogUkVQRUFUIDsKCmhlcmUgZXhhbXBsZSBbSUZdCiAgcjogcD0wLDQgdj0zLC0zCiAgcjogcD02LDMgdj0tMSwtMwogIHI6IHA9MTA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