So... here's a collection of some of the definitions seen here, with
some timing runs:


NB. Xiao-Yong Jin's implementation as revised by Pascal Jasmin
NB. http://jsoftware.com/pipermail/programming/2017-July/047881.html
revised=: ''1 :(0 :0-.LF)
  /:~@(
    -&1`]@.(=&0)"0

     (#/.~@] + ~.@]{[)
     `(~.@])
     `[
     }

       >&0

       #

       (
         ?@#~@#@]`]`[}
           ]
           I.@:=
           i.@#
       )@?@#~@#)
)

NB. Mike Day's implementation
NB. http://jsoftware.com/pipermail/programming/2017-July/047992.html
new=: (, (# | (+ ?&.<:@#~@#)))@(i.@#) +//. ((- , ]) 1&<.)

NB. Louis de Forcrand's version
NB. http://jsoftware.com/pipermail/programming/2017-July/047996.html
RUN=: UPD rec
UPD=: 4 : 0
 b -~ x u}~ (x {~ u=. ~.y) + y +//. b=. x >: 1
)
rec=: ((] + ] >: i.@[) (?@$ <:))@#

NB. Raul Miller's revised version
NB. http://jsoftware.com/pipermail/programming/2017-July/048000.html
tock=: ((0 >. <:) + _1+i.@# #/.~@, I.@:* (] + <:) +/@:* ?@# <:@#)

NB. Skip Cave's version:
NB. http://jsoftware.com/pipermail/programming/2017-July/048003.html
hist =: <: @ (#/.~) @ (i.@#@[ , I.) NB. Histogram
iter =: 4 :0
  nx =: y$y NB. initialize money
  while. x>0
  do. sg =: +/nx>0             NB. How many still giving?
    nx =: nx-nx~:0                NB. Those that have, give
    nx =: nx+(i.y) hist ?sg$y   NB. distribute dollars
    x =. x-1
  end.
)

NB. timing
ts=: timespacex
try=:3 :0
  echo y
  echo ".y
)

testrun=:3 :0
  'n g d'=. ":&.> y
  subst=. rplc&('NN';n;'GG';g;'DD';d;' 1 ts';' ts')
  try subst '   NN ts ''revised^:GG #~DD'''
  try subst '   NN ts ''new^:GG #~DD'''
  try subst '   NN ts ''RUN^:GG #~DD'''
  try subst '   NN ts ''tock^:GG #~DD'''
  try subst '   NN ts ''GG iter DD'''
  echo ''
)

testrun 1 5e3 200
testrun 1 5e3 10
testrun 10 1e4 100
testrun 100 1e4 20
testrun 100 1e4 200

NB. ............. test runs follow:

   1 ts 'revised^:5000 #~200'
0.752696 30208
   1 ts 'new^:5000 #~200'
0.261853 20992
   1 ts 'RUN^:5000 #~200'
0.060494 25344
   1 ts 'tock^:5000 #~200'
0.04234 18432
   1 ts '5000 iter 200'
0.049315 18560

   1 ts 'revised^:5000 #~10'
0.057119 6144
   1 ts 'new^:5000 #~10'
0.023318 4992
   1 ts 'RUN^:5000 #~10'
0.017986 7040
   1 ts 'tock^:5000 #~10'
0.010964 3840
   1 ts '5000 iter 10'
0.017491 2176

   10 ts 'revised^:10000 #~100'
0.753988 16384
   10 ts 'new^:10000 #~100'
0.266346 11520
   10 ts 'RUN^:10000 #~100'
0.0737156 14848
   10 ts 'tock^:10000 #~100'
0.0521216 10240
   10 ts '10000 iter 100'
0.0603638 11136

   100 ts 'revised^:10000 #~20'
0.198089 6144
   100 ts 'new^:10000 #~20'
0.0712385 5248
   100 ts 'RUN^:10000 #~20'
0.0434272 7040
   100 ts 'tock^:10000 #~20'
0.027364 4096
   100 ts '10000 iter 20'
0.034847 3456

   100 ts 'revised^:10000 #~200'
1.53964 30208
   100 ts 'new^:10000 #~200'
0.57214 20992
   100 ts 'RUN^:10000 #~200'
0.140146 25344
   100 ts 'tock^:10000 #~200'
0.095298 18432
   100 ts '10000 iter 200'
0.100683 20352

FYI,

-- 
Raul


On Thu, Jul 20, 2017 at 2:26 PM, Skip Cave <s...@caveconsulting.com> wrote:
> My explicit, looping version:
>
> NB. y is number of people and dollars
>
> NB. x is iteration count
>
> hist =: <: @ (#/.~) @ (i.@#@[ , I.) NB. Histogram
>
>
> iter =: 4 :0
>
> nx =: y$y NB. initialize money
>
> while. x>0
>
> do. sg =: +/nx>0             NB. How many still giving?
>
> nx =: nx-nx~:0                NB. Those that have, give
>
> nx =: nx+(i.y) hist ?sg$y   NB. distribute dollars
>
> x =. x-1
>
> end.
>
> )
>
> ts =: 6!:2 , 7!:2@]
>
> 1e2 ts '1e4 iter 20'
>
> 0.0262932 4224
>
>
> 1e2 ts '1e4 iter 200'
>
> 0.0915201 20352
>
>
> 10 ts '1e4 iter 100'
>
> 0.0528825 9344
>
> 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

Reply via email to