Discussion about math, puzzles, games and fun. Useful symbols: ÷ × ½ √ ∞ ≠ ≤ ≥ ≈ ⇒ ± ∈ Δ θ ∴ ∑ ∫ • π ƒ ¹ ² ³ °
 

You are not logged in.
Post a replyTopic review (newest first)
Loopless J code, about 30x faster: Code:sim =: 3 : '1+{.I.200=+/\~:?1000#1000' (+/%#)(sim "0) 100000#0
That's right.
His code will do about 30 seconds but it is procedural and does not make use of the faster functional paradigm. Also it is not compiled.
That's okay, he has mentioned his time for simulation.
Hi;
What's the time taken by the mathematica code?
Hi;
Hi bobbym, Code:(6!:2) '%. (+/%#) (sim "0) 10000$1000' NB. gets the running time
Hi gAr;
J: Code:sim =: monad define cnt =: 0 a =: y$0 while. (+/a) < 200 do. a =: 1 (?y)} a cnt =: cnt + 1 end. return. cnt ) (+/%#) (sim "0) 1000$1000 NB. (sim&+) also works ≈ 223.024
Hi;
Hi Bobby,
Hi phrontister;
Hi Bobby, Code:In[1]:= Timing[sum = 0; c = 0; s = Table[0, {1000}]; N[While[c < 100000, t = 199; ss = s; Do[ss[[RandomInteger[{1, 1000}]]] = 1, {t}] While[Count[ss, 1] < 200, ss[[RandomInteger[{1, 1000}]]] = 1;t++]; sum = sum + t; c++]; sum/c]] Out[1]= {270.985, 223.00152} So, again, just a touch > 223.
Hi phrontister; 