RosettaCodeData/Task/Monte-Carlo-methods/Logo/monte-carlo-methods.logo
2023-07-01 13:44:08 -04:00

16 lines
351 B
Text

to square :n
output :n * :n
end
to trial :r
output less? sum square random :r square random :r square :r
end
to sim :n :r
make "hits 0
repeat :n [if trial :r [make "hits :hits + 1]]
output 4 * :hits / :n
end
show sim 1000 10000 ; 3.18
show sim 10000 10000 ; 3.1612
show sim 100000 10000 ; 3.145
show sim 1000000 10000 ; 3.140828