Monte Carlo methods: Difference between revisions
Content deleted Content added
m →ES6: Slight rearrangement |
|||
Line 956: | Line 956: | ||
// monteCarloPi :: Int -> Float |
// monteCarloPi :: Int -> Float |
||
const monteCarloPi = n => |
const monteCarloPi = n => |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
// GENERIC FUNCTIONS |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
} |
|||
// range :: Int -> Int -> [Int] |
// range :: Int -> Int -> [Int] |
||
Line 972: | Line 971: | ||
length: Math.floor(n - m) + 1 |
length: Math.floor(n - m) + 1 |
||
}, (_, i) => m + i); |
}, (_, i) => m + i); |
||
// rnd :: () -> Float |
|||
⚫ | |||
// TEST |
// TEST |
||
Line 977: | Line 980: | ||
.map(_ => monteCarloPi(10000000)); |
.map(_ => monteCarloPi(10000000)); |
||
// e.g. -> [3. |
// e.g. -> [3.1413288, 3.1409792, 3.141154, 3.1415712, 3.1416284] |
||
})();</lang> |
})();</lang> |
||
{{Out}} (5 sample runs) |
{{Out}} (5 sample runs) |
||
<lang JavaScript>[3. |
<lang JavaScript>[3.1413288, 3.1409792, 3.141154, 3.1415712, 3.1416284]</lang> |
||
=={{header|Julia}}== |
=={{header|Julia}}== |