Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,7 @@
|
|||
sim1(N, F) = C =>
|
||||
C = 0,
|
||||
I = 0,
|
||||
while (I <= N)
|
||||
C := C + apply(F),
|
||||
I := I + 1
|
||||
end.
|
||||
|
|
@ -0,0 +1 @@
|
|||
sim2(N, F) = sum([apply(F) : _I in 1..N]).
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
sim_rec(N,F) = S =>
|
||||
sim_rec(N,N,F,0,S).
|
||||
sim_rec(0,_N,_F,S,S).
|
||||
sim_rec(C,N,F,S0,S) :-
|
||||
S1 = S0 + apply(F),
|
||||
sim_rec(C-1,N,F,S1,S).
|
||||
16
Task/Monte-Carlo-methods/Picat/monte-carlo-methods-4.picat
Normal file
16
Task/Monte-Carlo-methods/Picat/monte-carlo-methods-4.picat
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
go =>
|
||||
foreach(N in 0..7)
|
||||
sim_pi(10**N)
|
||||
end,
|
||||
nl.
|
||||
|
||||
% The specific pi simulation
|
||||
sim_pi(N) =>
|
||||
Inside = sim(N,pi_f),
|
||||
MyPi = 4.0*Inside/N,
|
||||
Pi = math.pi,
|
||||
println([n=N, myPi=MyPi, diff=Pi-MyPi]).
|
||||
|
||||
% The simulation function:
|
||||
% returns 1 if success, 0 otherwise
|
||||
pi_f() = cond(frand()**2 + frand()**2 <= 1, 1, 0).
|
||||
Loading…
Add table
Add a link
Reference in a new issue