Change [0,b) usages to iota
parent
ce05955693
commit
ceba36bfeb
|
|
@ -70,7 +70,7 @@ MEMO: static-huffman-tables ( -- obj )
|
||||||
280 287 [a,b] length [ 8 ] replicate append
|
280 287 [a,b] length [ 8 ] replicate append
|
||||||
] append-outputs
|
] append-outputs
|
||||||
0 31 [a,b] length [ 5 ] replicate 2array
|
0 31 [a,b] length [ 5 ] replicate 2array
|
||||||
[ [ length>> [0,b) ] [ ] bi get-table ] map ;
|
[ [ length>> iota ] [ ] bi get-table ] map ;
|
||||||
|
|
||||||
CONSTANT: length-table
|
CONSTANT: length-table
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -137,7 +137,7 @@ TUPLE: jpeg-color-info
|
||||||
data>>
|
data>>
|
||||||
binary
|
binary
|
||||||
[
|
[
|
||||||
read1 [0,b)
|
read1 iota
|
||||||
[ drop
|
[ drop
|
||||||
read1 jpeg> color-info>> nth clone
|
read1 jpeg> color-info>> nth clone
|
||||||
read1 16 /mod [ >>dc-huff-table ] [ >>ac-huff-table ] bi*
|
read1 16 /mod [ >>dc-huff-table ] [ >>ac-huff-table ] bi*
|
||||||
|
|
@ -198,7 +198,7 @@ MEMO: yuv>bgr-matrix ( -- m )
|
||||||
{ 8 8 } coord-matrix [ { u v } [ wave ] 2map product ] map^2
|
{ 8 8 } coord-matrix [ { u v } [ wave ] 2map product ] map^2
|
||||||
1 u v [ 0 = [ 2 sqrt / ] when ] bi@ 4 / m*n ;
|
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 ;
|
: mb-dim ( component -- dim ) [ h>> ] [ v>> ] bi 2array ;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -120,7 +120,7 @@ ERROR: unimplemented-color-type image ;
|
||||||
prev width tail-slice :> b
|
prev width tail-slice :> b
|
||||||
curr :> a
|
curr :> a
|
||||||
curr width tail-slice :> x
|
curr width tail-slice :> x
|
||||||
x length [0,b)
|
x length iota
|
||||||
filter {
|
filter {
|
||||||
{ filter-none [ drop ] }
|
{ filter-none [ drop ] }
|
||||||
{ filter-sub [ [| n | n x nth n a nth + 256 wrap n x set-nth ] each ] }
|
{ filter-sub [ [| n | n x nth n a nth + 256 wrap n x set-nth ] each ] }
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ math.ranges math.vectors sequences sequences.deep fry ;
|
||||||
IN: images.processing
|
IN: images.processing
|
||||||
|
|
||||||
: coord-matrix ( dim -- m )
|
: coord-matrix ( dim -- m )
|
||||||
[ [0,b) ] map first2 [ [ 2array ] with map ] curry map ;
|
[ iota ] map first2 [ [ 2array ] with map ] curry map ;
|
||||||
|
|
||||||
: map^2 ( m quot -- m' ) '[ _ map ] map ; inline
|
: map^2 ( m quot -- m' ) '[ _ map ] map ; inline
|
||||||
: each^2 ( m quot -- m' ) '[ _ each ] each ; inline
|
: each^2 ( m quot -- m' ) '[ _ each ] each ; inline
|
||||||
|
|
|
||||||
|
|
@ -77,7 +77,7 @@ C: <combo> combo
|
||||||
dup 0 = [
|
dup 0 = [
|
||||||
drop 1 - nip
|
drop 1 - nip
|
||||||
] [
|
] [
|
||||||
[ [0,b) ] 2dip '[ _ nCk _ >=< ] search nip
|
[ iota ] 2dip '[ _ nCk _ >=< ] search nip
|
||||||
] if ;
|
] if ;
|
||||||
|
|
||||||
:: next-values ( a b x -- a' b' x' v )
|
:: next-values ( a b x -- a' b' x' v )
|
||||||
|
|
@ -104,7 +104,7 @@ C: <combo> combo
|
||||||
[ combination-indices ] keep seq>> nths ;
|
[ combination-indices ] keep seq>> nths ;
|
||||||
|
|
||||||
: combinations-quot ( seq k quot -- seq quot )
|
: combinations-quot ( seq k quot -- seq quot )
|
||||||
[ <combo> [ choose [0,b) ] keep ] dip
|
[ <combo> [ choose iota ] keep ] dip
|
||||||
'[ _ apply-combination @ ] ; inline
|
'[ _ apply-combination @ ] ; inline
|
||||||
|
|
||||||
PRIVATE>
|
PRIVATE>
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ USING: accessors arrays bit-arrays fry infix kernel layouts locals math
|
||||||
math.functions multiline sequences ;
|
math.functions multiline sequences ;
|
||||||
IN: bloom-filters
|
IN: bloom-filters
|
||||||
|
|
||||||
FROM: math.ranges => [1,b] [0,b) ;
|
FROM: math.ranges => [1,b] ;
|
||||||
FROM: math.intervals => (a,b) interval-contains? ;
|
FROM: math.intervals => (a,b) interval-contains? ;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -121,7 +121,7 @@ PRIVATE>
|
||||||
[infix hash0 + (index * hash1) + ((pow(index, 3) - index) / 6) infix] ;
|
[infix hash0 + (index * hash1) + ((pow(index, 3) - index) / 6) infix] ;
|
||||||
|
|
||||||
: enhanced-double-hashes ( hash0 hash1 n -- seq )
|
: enhanced-double-hashes ( hash0 hash1 n -- seq )
|
||||||
[0,b)
|
iota
|
||||||
[ '[ _ _ enhanced-double-hash ] ] dip
|
[ '[ _ _ enhanced-double-hash ] ] dip
|
||||||
swap map ;
|
swap map ;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -47,14 +47,14 @@ PRIVATE>
|
||||||
|
|
||||||
|
|
||||||
: euler001b ( -- answer )
|
: 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
|
! [ euler001b ] 100 ave-time
|
||||||
! 0 ms ave run time - 0.06 SD (100 trials)
|
! 0 ms ave run time - 0.06 SD (100 trials)
|
||||||
|
|
||||||
|
|
||||||
: euler001c ( -- answer )
|
: 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
|
! [ euler001c ] 100 ave-time
|
||||||
! 0 ms ave run time - 0.06 SD (100 trials)
|
! 0 ms ave run time - 0.06 SD (100 trials)
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ IN: project-euler.027
|
||||||
<PRIVATE
|
<PRIVATE
|
||||||
|
|
||||||
: source-027 ( -- seq )
|
: 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 ;
|
cartesian-product [ first2 < ] filter ;
|
||||||
|
|
||||||
: quadratic ( b a n -- m )
|
: quadratic ( b a n -- m )
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ IN: project-euler.030
|
||||||
PRIVATE>
|
PRIVATE>
|
||||||
|
|
||||||
: euler030 ( -- answer )
|
: 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
|
! [ euler030 ] 100 ave-time
|
||||||
! 1700 ms ave run time - 64.84 SD (100 trials)
|
! 1700 ms ave run time - 64.84 SD (100 trials)
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,7 @@ IN: project-euler.055
|
||||||
PRIVATE>
|
PRIVATE>
|
||||||
|
|
||||||
: euler055 ( -- answer )
|
: euler055 ( -- answer )
|
||||||
10000 [0,b) [ lychrel? ] count ;
|
10000 iota [ lychrel? ] count ;
|
||||||
|
|
||||||
! [ euler055 ] 100 ave-time
|
! [ euler055 ] 100 ave-time
|
||||||
! 478 ms ave run time - 30.63 SD (100 trials)
|
! 478 ms ave run time - 30.63 SD (100 trials)
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ IN: project-euler.057
|
||||||
>fraction [ number>string length ] bi@ > ; inline
|
>fraction [ number>string length ] bi@ > ; inline
|
||||||
|
|
||||||
: euler057 ( -- answer )
|
: 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
|
! [ euler057 ] 100 ave-time
|
||||||
! 1728 ms ave run time - 80.81 SD (100 trials)
|
! 1728 ms ave run time - 80.81 SD (100 trials)
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,7 @@ IN: project-euler.081
|
||||||
3dup minimal-path-sum-to '[ _ + ] change-matrix ;
|
3dup minimal-path-sum-to '[ _ + ] change-matrix ;
|
||||||
|
|
||||||
: (euler081) ( matrix -- n )
|
: (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
|
[ first2 pick update-minimal-path-sum ] each
|
||||||
last last ;
|
last last ;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue