If you divide 1 by 998001 in a really fancy calculator like bc, you get all the numerical triplets from 000 to 999 in order, except you’re missing 998.
Posts
If you divide 1 by 998001 in a really fancy calculator like bc, you get all the numerical triplets from 000 to 999 in order, except you’re missing 998.
Random name generator with Python
#!/usr/bin/python3
import sys
import random
from pathlib import Path
script_dir = Path(__file__).resolve().parent
with open(script_dir / "fnames.idx", "r") as female:
lines1 = female.readlines()
with open(script_dir / "mnames.idx", "r") as male:
lines2 = male.readlines()
with open(script_dir / "lnames.idx", "r") as last:
lines3 = last.readlines()
random.shuffle(lines1)
random.shuffle(lines2)
random.shuffle(lines3)
sys.stdout.write("Male\n\n")
for i in range (0, 10, 1):
sys.stdout.write(lines2[i].rstrip())
sys.stdout.write(" ")
sys.stdout.write(lines3[i])
sys.stdout.write("\nFemale\n\n")
for i in range (11, 21, 1):
sys.stdout.write(lines1[i].rstrip())
sys.stdout.write(" ")
sys.stdout.write(lines3[i])
Using Python and linear algebra to find the intersection of two lines, each line defined by four points.
#!/usr/bin/env python3
import sys,numpy as n
p,q,r,s=map(n.array,((float(sys.argv[i]),float(sys.argv[i+1])) for i in (1,3,5,7)))
M=n.c_[q-p,s-r]
d=n.linalg.det(M)
if abs(d)<1e-10:
print("Coincident" if abs(n.cross(q-p,r-p))<1e-10 else "Parallel")
else:
t,_=n.linalg.solve(M,r-p)
print(p+t*(q-p))
Bywater Basic
for x=33 to 126
print using “###”;x;
print ” “;chr$(x);
print ” “;
if pos > 60 then print
next x
print
Find barycentric L1 and L2 Lagrange Points from normalized mass ratio with Python
#!/usr/bin/env python3
import sys
from scipy.optimize import brentq
R = float(sys.argv[1])
m1 = R / (R + 1.0)
m2 = 1.0 / (R + 1.0)
x1 = -m2
x2 = m1
def f(x):
r1 = abs(x - x1)
r2 = abs(x - x2)
return (
x
- m1 * (x - x1) / r1**3
- m2 * (x - x2) / r2**3
)
eps = 1e-12
L1 = brentq(f, x1 + eps, x2 - eps)
L2 = brentq(f, x2 + eps, x2 + 2.0)
r1 = x2 - L1
r2 = L2 - x2
print(f"Primary : {x1:.12f}")
print(f"Secondary : {x2:.12f}")
print(f"L1 : {L1:.12f}")
print(f"L2 : {L2:.12f}")
print(f"L1 offset : {r1:.12f}")
print(f"L2 offset : {r2:.12f}")
Additive synthesis of square wave and sawtooth wave
#!/usr/bin/python3
import matplotlib.pyplot as plt
import numpy as np
x = np.arange(0, 2 * np.pi, 0.01)
y = np.zeros_like(x)
for n in range(1, 16, 2):
y += np.sin(n * x) / n
z = np.zeros_like(x)
for n in range(1, 9):
z += np.sin(n * x) / n
plt.figure(figsize=(10, 5))
plt.plot(x, y, label="Odd harmonics (1, 3, 5, ..., 15)")
plt.plot(x, z, color="red", label="All harmonics (1 through 8)")
plt.xlim(0, 2 * np.pi)
plt.xticks(
[0, np.pi/2, np.pi, 3*np.pi/2, 2*np.pi],
["0", "π/2", "π", "3π/2", "2π"]
)
plt.xlabel("Radians")
plt.ylabel("Amplitude")
plt.title("Fourier Series")
plt.grid(True)
plt.legend()
plt.tight_layout()
plt.show()
Random name generator
#!/usr/bin/python3
import sys
import random
from pathlib import Path
script_dir = Path(__file__).resolve().parent
with open(script_dir / "fnames.idx", "r") as female:
lines1 = female.readlines()
with open(script_dir / "mnames.idx", "r") as male:
lines2 = male.readlines()
with open(script_dir / "lnames.idx", "r") as last:
lines3 = last.readlines()
random.shuffle(lines1)
random.shuffle(lines2)
random.shuffle(lines3)
sys.stdout.write("Male\n\n")
for i in range (0, 10, 1):
sys.stdout.write(lines2[i].rstrip())
sys.stdout.write(" ")
sys.stdout.write(lines3[i])
sys.stdout.write("\nFemale\n\n")
for i in range (11, 21, 1):
sys.stdout.write(lines1[i].rstrip())
sys.stdout.write(" ")
sys.stdout.write(lines3[i])
Using Python and linear algebra to find the intersection of two lines, each line defined by four points.
#!/usr/bin/env python3
import sys,numpy as n
p,q,r,s=map(n.array,((float(sys.argv[i]),float(sys.argv[i+1])) for i in (1,3,5,7)))
M=n.c_[q-p,s-r]
d=n.linalg.det(M)
if abs(d)<1e-10:
print("Coincident" if abs(n.cross(q-p,r-p))<1e-10 else "Parallel")
else:
t,_=n.linalg.solve(M,r-p)
print(p+t*(q-p))