Here's a shorter version, but with repetitions,
i.e. some calls to random are discarded.
toss2=: 4 : 0"0
y=. ((>.x^.y) # x) #: y-1 NB. y-1 in base x
for_i. i. n=. #r=. ? y+1 do.
if. (i{r) < i{y do.
r=. ((>:i){.r) , ? (n->:i) # x break. end.
end.
x#.r
)
/:~~.4 toss2 2000#1
0
/:~~.4 toss2 2000#2
0 1
/:~~.4 toss2 2000#3
0 1 2
/:~~.4 toss2 2000#4
0 1 2 3
/:~~.4 toss2 2000#5
0 1 2 3 4
/:~~.4 toss2 2000#6
0 1 2 3 4 5
/:~~.4 toss2 2000#7
0 1 2 3 4 5 6
/:~~.4 toss2 2000#9
0 1 2 3 4 5 6 7 8
/:~~.4 toss2 2000#10
0 1 2 3 4 5 6 7 8 9
(_1+2^31x) toss2 3#2^66x
60012806129269616711 37161153763356344874 73424420377124705775
----- Original Message ----
From: Oleg Kobchenko <[EMAIL PROTECTED]>
To: Beta forum <[email protected]>
Sent: Wednesday, June 14, 2006 12:40:06 AM
Subject: Re: [Jbeta] monadic '?'
I was jumping ahead of myself.
Here's a better version.
x is internal base, for domain of ?,
it's max positive int, i.e. _1+2^31.
toss=: 4 : 0"0
y=. ((>.x^.y) # x) #: y-1 NB. y-1 in base x
r=. ''
n=. #y
i=. 0
while. i<#y do.
if. 0 = p=. i{y do.
r=. r, 0
else.
r=. r, c=. ? p+1
if. c<p do. r=. r,? (n->:i) # x break. end.
end.
i=. i+1
end.
x#.r
)
4 toss 20#1
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
4 toss 20#2
1 0 0 1 0 0 0 0 0 1 0 0 0 1 0 1 0 1 1 0
4 toss 20#3
1 2 2 1 0 1 0 2 1 2 0 0 2 2 0 1 0 0 2 1
4 toss 20#4
1 3 2 1 1 1 1 0 3 0 2 3 3 2 0 3 1 1 2 2
4 toss 20#5
4 2 4 0 3 4 4 0 4 4 1 4 0 0 4 0 0 4 0 3
4 toss 20#6
5 1 4 2 0 3 5 4 5 5 4 3 2 1 1 4 1 5 0 5
4 toss 20#7
5 2 0 5 6 0 6 5 3 5 2 3 4 4 4 3 2 1 0 3
4 toss 20#8
3 3 5 7 0 7 7 0 4 1 0 3 3 6 6 1 7 1 3 5
4 toss 20#9
0 1 8 0 7 0 7 2 0 8 8 1 8 5 0 1 4 6 8 8
4 toss 20#10
8 1 0 7 6 3 3 0 6 3 1 6 6 6 4 5 3 9 3 3
4 toss 20#11
1 7 9 8 10 7 9 0 0 0 7 5 3 3 9 9 0 2 5 4
4 toss 20#12
9 10 2 1 2 2 9 7 4 0 3 3 7 4 1 11 5 1 7 10
4 toss 20#13
12 12 7 12 4 1 10 12 11 2 12 0 10 4 1 4 11 12 11 12
(_1+2^31x) toss 3#2^66x
67154428832921753283 478504324474035513 22035517552475936585
----- Original Message ----
From: Oleg Kobchenko <[EMAIL PROTECTED]>
To: Beta forum <[email protected]>
Sent: Tuesday, June 13, 2006 11:56:40 PM
Subject: Re: [Jbeta] monadic '?'
How about this:
toss=: 4 : 0"0
y=. ((>.x^.y) # x) #: y NB. y in base x
y=. y + x * 0=y NB. replace 0 with x
r=. ''
n=. #y
i=. 0
while. i<:#y do.
r=. r, c=. ? p=. i{y
if. c<p do. r=. r,? (n->:i) # x break. end.
end.
x#.r
)
2 toss 10#8
2 4 6 2 0 4 1 5 2 4
2 toss 10#8
4 5 7 0 4 3 6 2 3 6
2 toss 10#8
2 7 4 4 1 1 0 0 3 5
(_1+2^31x) toss 3#2^66x
54577901964967394924 34786398721677175033 4024345107907449541
----- Original Message ----
From: Andrew Nikitin <[EMAIL PROTECTED]>
To: [email protected]
Sent: Tuesday, June 13, 2006 8:05:52 PM
Subject: [Jbeta] monadic '?'
?10^100x
|domain error
| ?10^100
Or should it rather go to "suggestion" page?
I tried to implement ? equivalent for large extended numbers, but this is
such a pain. I would be happier if primitive could do it for me.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm