280 287 [a,b] length [ 8 ] replicate append
] append-outputs
0 31 [a,b] length [ 5 ] replicate 2array
- [ [ length>> [0,b) ] [ ] bi get-table ] map ;
+ [ [ length>> iota ] [ ] bi get-table ] map ;
CONSTANT: length-table
{
data>>
binary
[
- read1 [0,b)
+ read1 iota
[ drop
read1 jpeg> color-info>> nth clone
read1 16 /mod [ >>dc-huff-table ] [ >>ac-huff-table ] bi*
{ 8 8 } coord-matrix [ { u v } [ wave ] 2map product ] map^2
1 u v [ 0 = [ 2 sqrt / ] when ] bi@ 4 / m*n ;
-MEMO: dct-matrix ( -- m ) 64 [0,b) [ 8 /mod dct-vect flatten ] map ;
+MEMO: dct-matrix ( -- m ) 64 iota [ 8 /mod dct-vect flatten ] map ;
: mb-dim ( component -- dim ) [ h>> ] [ v>> ] bi 2array ;
prev width tail-slice :> b
curr :> a
curr width tail-slice :> x
- x length [0,b)
+ x length iota
filter {
{ filter-none [ drop ] }
{ filter-sub [ [| n | n x nth n a nth + 256 wrap n x set-nth ] each ] }
IN: images.processing\r
\r
: coord-matrix ( dim -- m )\r
- [ [0,b) ] map first2 [ [ 2array ] with map ] curry map ;\r
+ [ iota ] map first2 [ [ 2array ] with map ] curry map ;\r
\r
: map^2 ( m quot -- m' ) '[ _ map ] map ; inline\r
: each^2 ( m quot -- m' ) '[ _ each ] each ; inline\r
dup 0 = [
drop 1 - nip
] [
- [ [0,b) ] 2dip '[ _ nCk _ >=< ] search nip
+ [ iota ] 2dip '[ _ nCk _ >=< ] search nip
] if ;
:: next-values ( a b x -- a' b' x' v )
[ combination-indices ] keep seq>> nths ;
: combinations-quot ( seq k quot -- seq quot )
- [ <combo> [ choose [0,b) ] keep ] dip
+ [ <combo> [ choose iota ] keep ] dip
'[ _ apply-combination @ ] ; inline
PRIVATE>
math.functions multiline sequences ;
IN: bloom-filters
-FROM: math.ranges => [1,b] [0,b) ;
+FROM: math.ranges => [1,b] ;
FROM: math.intervals => (a,b) interval-contains? ;
/*
[infix hash0 + (index * hash1) + ((pow(index, 3) - index) / 6) infix] ;
: enhanced-double-hashes ( hash0 hash1 n -- seq )
- [0,b)
+ iota
[ '[ _ _ enhanced-double-hash ] ] dip
swap map ;
: euler001b ( -- answer )
- 1000 [0,b) [ [ 5 mod ] [ 3 mod ] bi [ 0 = ] either? ] filter sum ;
+ 1000 iota [ [ 5 mod ] [ 3 mod ] bi [ 0 = ] either? ] filter sum ;
! [ euler001b ] 100 ave-time
! 0 ms ave run time - 0.06 SD (100 trials)
: euler001c ( -- answer )
- 1000 [0,b) [ { 3 5 } [ divisor? ] with any? ] filter sum ;
+ 1000 iota [ { 3 5 } [ divisor? ] with any? ] filter sum ;
! [ euler001c ] 100 ave-time
! 0 ms ave run time - 0.06 SD (100 trials)
<PRIVATE
: source-027 ( -- seq )
- 1000 [0,b) [ prime? ] filter [ dup [ neg ] map append ] keep
+ 1000 iota [ prime? ] filter [ dup [ neg ] map append ] keep
cartesian-product [ first2 < ] filter ;
: quadratic ( b a n -- m )
PRIVATE>
: euler030 ( -- answer )
- 325537 [0,b) [ dup sum-fifth-powers = ] filter sum 1 - ;
+ 325537 iota [ dup sum-fifth-powers = ] filter sum 1 - ;
! [ euler030 ] 100 ave-time
! 1700 ms ave run time - 64.84 SD (100 trials)
PRIVATE>
: euler055 ( -- answer )
- 10000 [0,b) [ lychrel? ] count ;
+ 10000 iota [ lychrel? ] count ;
! [ euler055 ] 100 ave-time
! 478 ms ave run time - 30.63 SD (100 trials)
>fraction [ number>string length ] bi@ > ; inline
: euler057 ( -- answer )
- 0 1000 [0,b) [ drop 2 + recip dup 1 + longer-numerator? ] count nip ;
+ 0 1000 iota [ drop 2 + recip dup 1 + longer-numerator? ] count nip ;
! [ euler057 ] 100 ave-time
! 1728 ms ave run time - 80.81 SD (100 trials)
3dup minimal-path-sum-to '[ _ + ] change-matrix ;
: (euler081) ( matrix -- n )
- dup first length [0,b) dup cartesian-product
+ dup first length iota dup cartesian-product
[ first2 pick update-minimal-path-sum ] each
last last ;