Paste: Looping with sequences
Author: | Loryn Jenkins |
Mode: | factor |
Date: | Mon, 22 Apr 2013 13:27:16 |
Plain Text |
USING: kernel sequences sequences.extras combinators locals namespaces accessors
math math.functions math.ranges utils ;
IN: lamps
<PRIVATE
SYMBOLS: the-lamps ;
PRIVATE>
: >>the-lamps>>
the-lamps set
the-lamps get ;
: new-lamps
100 [1,b] [ drop t ] map ;
: lamps
the-lamps get [ new-lamps >>the-lamps>> ] unless* ;
: reset
f the-lamps set ;
: people
100 [1,b] [ ] map ;
: toggle
not ;
: toggle?
swap divisor? ;
: toggle-switches
lamps [ toggle? [ toggle ] when ] with map-index+! drop ;
: do-switching
people [ toggle-switches ] each ;
: execute
do-switching lamps reset ;
Author: | Loryn Jenkins |
Mode: | factor |
Date: | Mon, 22 Apr 2013 14:19:00 |
Plain Text |
USING: kernel math sequences ;
IN: utils
: map-index+ -- ... newseq )
'[ [ 1 + @ ] map-index ] call ; inline
: map-index+! -- ... seq )
'[ [ 1 + @ ] map-index! ] call ; inline
Author: | mrjbq7 |
Mode: | factor |
Date: | Mon, 22 Apr 2013 14:49:19 |
Plain Text |
USING: arrays fry kernel math math.functions math.ranges
sequences sequences.extras ;
IN: lamps
: <lamps>
100 t <array> ;
: <people>
100 [1,b] >array ;
: toggle
not ;
: toggle? ยท
1 + swap divisor? ;
: toggle-switches
[ toggle? [ toggle ] when ] with map-index! drop ;
: do-switching
<people> <lamps> [ '[ _ toggle-switches ] each ] keep ;
Author: | mrjbq7 |
Mode: | factor |
Date: | Mon, 22 Apr 2013 14:55:14 |
Plain Text |
2 18 2 <range> >array [ t <array> ] map
{ f } join { f } { f } surround
Author: | Loryn Jenkins |
Mode: | factor |
Date: | Mon, 22 Apr 2013 15:46:35 |
Plain Text |
USING: arrays math math.ranges math.primes.factors sequences ;
IN: lamps
: <people>
100 [1,b] >array ;
: calc-switching
<people> [ divisors length even? ] map ;
New Annotation