Re: [Jprogramming] Control Words

2018-06-26 Thread Skip Cave
Raul, Robert, Jimmy, Louis, Bo, Rob, Thanks so much for all the thoughtful and interesing answers. Your examples gave me much insight on how the while. do. control structures work, which I can never seem to remember. I also got a better understanding of itemize/laminate, very useful for sticking v

Re: [Jprogramming] Control Words

2018-06-26 Thread Rob Hodgkinson
Skip, if the goal is to write the code then the responses have already advised best ways. But if you require very high performance (eg in Monte Carlo simulations ?), then you can always consider a trade off or speed vs space. For example if you have space available, and runtime CPU is critical,

Re: [Jprogramming] Control Words

2018-06-26 Thread 'Bo Jacoby' via Programming
Make sure that the sum is 172.     (,~172-+/)>:?5#70 15 9 64 21 20 43 Discard results where the first item is not between 1 and 70    (,~172-+/)>:?5#70 _31 67 61 41 12 22 This must be faster than discarding sets where the sum is not 172. Thanks,  Bo. Den 19:29 tirsdag den 26. juni 2018 sk

Re: [Jprogramming] Control Words

2018-06-26 Thread Louis de Forcrand
Hi, If I understand your wording, you would like to generate n “multisets” of 6 random numbers which sum to 172. I say multiset because I imagine that order doesn’t matter, but that multiplicity does (so numbers can be repeated). If speed is a concern, then you could generate all possible multi

Re: [Jprogramming] Control Words

2018-06-26 Thread Jimmy Gauvin
Hi, another way to look at this is to obtain the generating function based on integer partitioning. Basically we are trying to put 172 balls into six bins with the restriction that each bin receive at least 1 ball and no more than 70. The number of valid combinations is probably a big number but n

Re: [Jprogramming] Control Words

2018-06-26 Thread Raul Miller
On Tue, Jun 26, 2018 at 12:01 PM robert therriault wrote: > I should learn to read the specs, huh Raul? That's something I often fail to put enough effort into, also. Note also that if there were performance issues here, there are a couple things that could be done to speed things up: [1] Inste

Re: [Jprogramming] Control Words

2018-06-26 Thread robert therriault
I should learn to read the specs, huh Raul? Based on Raul's better submission. (I liked the use of #~ to select appropriate candidates from ,: items) Cheers, bob ts =: 3 : 0 b=: 0 6$0 while. y>#b do. b=. b, (#~ 172=+/"1) a=.,:1+6?70 end. ) ts 6 29 49 17 47 22 8 8 43 39 40 7 35 2

Re: [Jprogramming] Control Words

2018-06-26 Thread robert therriault
Hi Skip, I came up with this using while. and putting the test for summation inside the loop. Cheers, bob ts =: 3 : 0 b=: 0 6$0 while. 6>#b do. a=:1+6?70 if. 172=+/"1 a do. b=:a,b end. end. b ) ts '' 10 60 13 26 14 49 6 37 65 5 43 16 23 26 11 56 51 5 59 19

Re: [Jprogramming] Control Words

2018-06-26 Thread Raul Miller
Here is a change to accomplish that goal: ts =: 3 : 0 b=: 0 6$0 while.y>#b do. a=:,:1+6?70 b=:b,a#~172=+/"1 a end. ) If this gets to be too slow, there's ways of speeding that up. Thanks, -- Raul On Tue, Jun 26, 2018 at 10:13 AM Skip Cave wrote: > > I want to generate n sets of 6 ra

[Jprogramming] Control Words

2018-06-26 Thread Skip Cave
I want to generate n sets of 6 random integers from 1->70 where each set of 6 integers sums to 172 Here's my first try: ts =: 3 : 0 b=: 2 6$0 for. i.y do. a=:1+6?70 b=:b,a end. b#~172=+/"1 b ) Test it: ts 1000 27 60 5 24 53 3 38 35 3 15 57 24 16 29 19 50 4 54 This generates some 6-ele