P

@pustam_egr

Solution to n^2=N with n and N together using each of the digits 1 to 9 only once

Python
1 year ago
from itertools import permutations def is_valid_solution(n, N): combined_digits = str(n) + str(N) return sorted(combined_digits) == ['1', '2', '3', '4', '5', '6', '7', '8', '9'] def find_solutions(): solutions = [] for perm in perm

2D heatmap-like plots Christmas tree light length

Python
1 year ago
import numpy as np import matplotlib.pyplot as plt def christmas_light_length(r, h, n): rho = r / h L1 = (h / 2) * np.sqrt(1 + rho**2 * (1 + 4 * np.pi**2 * n**2)) L2 = (h * (1 + rho**2)) / (4 * np.pi * n * rho) * np.arcsinh((2 * np.pi

Christmas tree light length

Python
1 year ago
import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D def christmas_light_length(r, h, n): rho = r / h L1 = (h / 2) * np.sqrt(1 + rho**2 * (1 + 4 * np.pi**2 * n**2)) L2 = (h * (1 + rho**2)) / (4 * n

Prime dates

Python
2 years ago
import math def is_prime(num): if num <= 1: return False if num <= 3: return True if num % 2 == 0 or num % 3 == 0: return False i = 5

Red Heart ❤️

R
2 years ago
dat<-data.frame(t=seq(0,2*pi,by=0.1)) xhrt<-function(t) 16*sin(t)^3 yhrt<-function(t) 13*cos(t)-5*cos(2*t)-2*cos(3*t)-cos(4*t) dat$y=yhrt(dat$t) dat$x=xhrt(dat$t) with(dat, plot(x,y, type="l",ylab="",yaxt="n",xlab="",xaxt="n")) with(dat, polygon(x,y

Pi using Ramanujan's formula and Chudnovsky algorithm

Python
2 years ago
#Estimating pi based on Ramanujan's formula and Chudnovsky algorithm import math def estimate_pi(iterations): # Initialize the sum sum_term = 0.0 # Perform the summation for k in range(iterations): term1 = math.factorial(4

Triangle of asterisks using nested loops

C
2 years ago
#include <stdio.h> int main() { int n, i, j; printf("Enter the number of rows for the triangle: "); scanf("%d", &n); for (i = 1; i <= n; i++) { // Print spaces to align the asterisks to form a triangle

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-coord

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 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 =