myCompiler myCompiler
Deutsch English Español Français Italiano 日本語 한국어 Nederlands Polski Português
Recent
Login Sign up
Recent
Login Sign up
P

@pustam_egr

JS code to compute pi using Monte Carlo

NodeJS
2 years ago
//Monte Carlo simulation function estimatePiMonteCarlo(iterations) { let insideCircle = 0; for (let i = 0; i < iterations; i++) { const x = Math.random(); // Random x-coordinate between 0 and 1 const y = Math.random(); // Random y-coordinate between 0 and 1 // Check if the point (x, y) is inside the unit circle (radius = 1) if (x * x + y * y <= 1) {

Computation of multifactorials

Python
2 years ago
# Python code to demonstrate the naive method # to compute multifactorial n = 7 fact = 1 if n % 3==1: for i in range(1, n+1, 3): fact *=i elif n % 3==2:

Pi using Leibniz formula and convergence acceleration

Python
2 years ago
#Pi using Leibniz's formula def calculate_pi(iterations): pi_approximation = 0.0 for i in range(iterations): term = 4.0 * (-1) ** i / (2 * i + 1) pi_approximation += term return pi_approximation def compute_pi(iterations): pi_approx = 0.0

Pi using Monte Carlo method

Python
2 years ago
#Monte Carlo method import random def estimate_pi(num_samples): inside_circle = 0 for _ in range(num_samples): x = random.random() y = random.random() distance = x ** 2 + y ** 2

Pi using Leibniz method

Python
2 years ago
def calculate_pi(iterations): pi_approximation = 0.0 for i in range(iterations): term = 4.0 * (-1) ** i / (2 * i + 1) pi_approximation += term return pi_approximation # Number of iterations for approximation iterations = 1000000 approx_pi = calculate_pi(iterations)
Previous Next page

Supported languages

Deno JavaScript NodeJS Python Ruby Go C C++ Java C# TypeScript PHP Bash R Octave (MATLAB) Fortran Lua Erlang SQL MySQL MongoDB Clojure D Perl Kotlin Swift Rust Assembly
© 2026 mycompiler.io
Terms of service Privacy policy Contact us