16 lines
351 B
Text
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
|