I see your point. actually x?y (deal as in the vocabulary) doesn't
allow repetitions. An analogy is dealing a hand of cards where you will
never (legally) have 2 aces of spades . hence, with 2 cards 1 and 0, you
can't get 1 1 . If you have 2 cards each having a 1 and 0 you can get
your results but you will have to treat it as a set of 4 numbers where
odd numbers are equivalent to 0 and even are 1 .
1+(5#2)?4
2 4
1 4
3 1
1 4
4 1
these corresponds to 1 1, 0 1 , 0 0, 0 1 , 1 0
Don
On 2020-03-24 5:18 p.m., Julian Fondren wrote:
5 6 ?@$ 55
52 3 9 16 4 3
26 30 24 34 30 50
46 51 16 19 26 26
20 46 12 50 39 27
3 39 45 46 46 33
:)
This actually isn't the same result as your code, though.
(4#2) ? 2
0 1
0 1
0 1
1 0
1 1 i.~ (1e6#2) ? 2
1000000
0 0 i.~ (1e6#2) ? 2
1000000
There are never any 1 1 or 0 0 results.
4 2 ?@$ 2
0 0
0 1
1 0
0 0
There are such results.
On 2020-03-24 19:02, Don Kelly wrote:
(5#6)?55
42 16 14 29 38 25
14 37 22 4 54 6
47 51 35 32 26 45
13 53 10 29 3 15
21 8 20 45 30 52
Don Kelly
On 2020-03-23 5:47 p.m., 'Jim Russell' via Programming wrote:
Who do I thank tor this? It is a particularly clear and helpful
exclamation. Thank you!
On Mar 13, 2020, at 3:56 AM, ethiejiesa via Programming
<programm...@jsoftware.com> wrote:
I'll contribute a little prose. Hopefully, it's helpful.
In this particular case, notice that > transforms your list of
boxes into a 5x6
table:
(6?55);(6?55);(6?55);(6?55);(6?55)
13 4 19 43 3 52
10 1 4 46 52 11
38 12 48 50 54 45
36 54 39 35 53 50
44 1 7 54 11 41
So, we should be able to easily "reverse" the above, meaning that
dealing with
a 5x6 array is pretty much the same as dealing with 5 boxes of
6-arrays. Let's
just keep this in mind for now, and first try to generate this 6x5
table.
The key point of ? is that it's monadic and dyadic ranks are all 0,
meaning
that it transforms an array of integers into a corresponding array
of random
numbers:
? 50 6 $ 55
...
produces a random 50x6 array of integers each in the range i.55.
This is not
quite what we want, but we first note that it can be more
idiomatically
written:
50 6 ?@$ 55
The utility of @ (and @:) become a lot more apparent when writing
tacit
expressions. In general, x u@v y is equivalent to u (x v y),
applying u "atop"
x v y, hence the mnemonic. (NB. The difference between u@v and u@:v
is that
they produce verbs of different rank.)
The dyad n?m produces n random numbers without replacement. Your
posed problem
is to generate 50 such lists, so conceptually we want to *reshape* the
arguments of ? into 50-lists:
(50$6) ? (50$55)
but, better yet, as lots of verbs to ? will automatically reshape
an atomic
argument to the shape of the other argument, so we can abbreviate
the above in
one of two ways:
6 ? (50$55) NB. or
(50$6) ? 55
In the first case, the parentheses are not necessary due to J
parsing rules, so
its more compact and idomatic to elide them
6 ? 50$55
These three previous options should produce the desired random
tables. Now,
putting things together, we just want to "redo" the boxing we did
in the
beginning example:
<"1 (6 ? 50$55)
Which should give the desired result. We need the
parenthesis to separate the 1 from the 6, otherwise J would
interpret this as
<"1 6. Another way to break up the list lexing is like this:
<"1 [ 6 ? 50 $ 55
Anyway, Hui's use of &. is even nicer. The key ideas is that u&.v
first runs v
on u's aguments and then *undoes* v on the result. The really neat
thing is
that > is a no-op on non-boxed atoms:
42
42
So the idea is to let > be a no-op on our input array of integers,
then let ?
do it's thing, and finally *undo* > on *each* result. And since
undoing > is
simply doing <, we get what we want.
6 ?&.> 50 $ 55
The "each result" part above is exactly why this form is slick.
?&.> has the
rank of >, i.e. 0 0 0. This means that it will box each list
produced by ? as
the integers are fed to it, which is exactly what we want in this
case.
Very cool stuff. Rank!
Skip Cave <s...@caveconsulting.com> wrote:
Wow! Two completely different ways to generate multiple sets of
random
integers. Roger used &. which I haven't really ever used or
understood. I
will definitely need to understand &. for the future. Devon used
@, which I
also haven't used very much. I need to find some practice and
training
examples to work on both concepts.
Skip Cave
Cave Consulting LLC
On Fri, Mar 13, 2020 at 12:04 AM Devon McCormick
<devon...@gmail.com> wrote:
6 5?@$55
Will give you a 6x5 table that is 6 independent rows of 5?55.
On Fri, Mar 13, 2020 at 12:52 AM Roger Hui
<rogerhui.can...@gmail.com>
wrote:
6 ?&.> 5 $ 55
┌────────────────┬─────────────────┬───────────────┬─────────────────┬───────────────┐
│47 28 45 25 8 36│22 40 23 20 11 49│15 16 42 38 4 5│50 45 38 37
13 28│42
4
36 7 23 49│
└────────────────┴─────────────────┴───────────────┴─────────────────┴───────────────┘
6 ?&.> 50 $ 55
...
On Thu, Mar 12, 2020 at 9:49 PM Skip Cave <s...@caveconsulting.com>
wrote:
How can I generate the following result extended 50 times, without
explicit
looping?
(6?55);(6?55);(6?55);(6?55);(6?55)
┌───────────────┬───────────────┬─────────────────┬─────────────────┬───────────────┐
│13 4 19 43 3 52│10 1 4 46 52 11│38 12 48 50 54 45│36 54 39 35
53 50│44
1 7
54 11 41│
└───────────────┴───────────────┴─────────────────┴─────────────────┴───────────────┘
Skip Cave
Cave Consulting LLC
----------------------------------------------------------------------
For information about J forums see
http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see
http://www.jsoftware.com/forums.htm
--
Devon McCormick, CFA
Quantitative Consultant
----------------------------------------------------------------------
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
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm