Posts
Category Archives: Uncategorized
All the vowels
With Python find words longer than 10 characters that use all the vowels: #! /usr/bin/env python3 with open(‘unixdict.txt’) as f: while (line := f.readline().strip()): if (len(line) > 10 and all( line.count(c) == 1 for c in ‘aeiou’)): print(line)
Posted in Uncategorized
Leave a comment
Say
Number to words #!/usr/bin/env python3 import sys n = int(sys.argv[1]) ones = [“zero”, “one”, “two”, “three”, “four”, “five”, “six”, “seven”, “eight”, “nine”] teens = [“ten”, “eleven”, “twelve”, “thirteen”, “fourteen”,”fifteen”, “sixteen”, “seventeen”, “eighteen”, “nineteen”] tens = [“”, “”, “twenty”, “thirty”, “forty”,”fifty”, … Continue reading
Posted in Uncategorized
Leave a comment
Spiral
Archimedes spiral with turtle graphics #!/usr/bin/env python3 from turtle import * from math import * color(“blue”) speed(0) down() for i in range(200): t = i*pi/20 r = 1+5*t goto(r*cos(t), r*sin(t)) done()
Posted in Uncategorized
Leave a comment
Compile
Compile short C programs on the fly at the command prompt echo ‘main() { printf(“Hello world!\n”); }’ | gcc -w -x c – -o hello echo ‘#include <stdio.h> int fibonacci(int n){return n<2?n:fibonacci(n-1)+fibonacci(n-2);} int main(){printf(“%d\n”,fibonacci(19));return 0;}’ | gcc -x c – … Continue reading
Posted in Uncategorized
Leave a comment
Nth prime
Calculate the nth prime with Python #!/usr/bin/env python3 import sys import time; max=int(sys.argv[1]); n=1; p=1 t0 = time.perf_counter() while n<=max: f=0; j=2; s = int(p**0.5) while f < 1: if j >= s: f=2 if p % j == 0: f=1 … Continue reading
Posted in Uncategorized
Leave a comment
Payload
Iteratively converge on LEO-deliverable payload mass for the Astrodyne Argo Epsilon single-booster first stage (RP-1/LOX) and Delta second stage (LH2/LOX) stack: #!/usr/bin/env python3 import math S1_WET = 46357.2 S1_DRY = 3708.6 S1_ISP = 280.0 S2_WET = 19322.5 S2_DRY = 2318.7 … Continue reading
Posted in Uncategorized
Leave a comment
Ellipse
#! /usr/bin/python3 import math import sys a = float(sys.argv[1]) b = float(sys.argv[2]) h = ((a – b) / (a + b))**2 eps = sys.float_info.epsilon def binom_half(n): coef = 1.0 for k in range(n): coef *= (0.5 – k) / (k … Continue reading
Posted in Uncategorized
Leave a comment
Ellipsoid
#! /usr/bin/env python3 import matplotlib.pyplot as plt import numpy as np fig = plt.figure() ax = fig.add_subplot(111, projection=’3d’) r = 10 u = np.linspace(0, 2 * np.pi, 100) v = np.linspace(0, np.pi, 100) x = r * np.outer(np.cos(u), np.sin(v)) y … Continue reading
Posted in Uncategorized
Leave a comment
Say
#!/usr/bin/env python3 import sys n = int(sys.argv[1]) ones = [“zero”, “one”, “two”, “three”, “four”, “five”, “six”, “seven”, “eight”, “nine”] teens = [“ten”, “eleven”, “twelve”, “thirteen”, “fourteen”,”fifteen”, “sixteen”, “seventeen”, “eighteen”, “nineteen”] tens = [“”, “”, “twenty”, “thirty”, “forty”,”fifty”, “sixty”, “seventy”, “eighty”, … Continue reading
Posted in Uncategorized
Leave a comment
Truthtable
Boolean truth tables in Python #!/usr/bin/env python3 import sys from itertools import product bexp=” “.join(sys.argv[1:]) code=compile(bexp,”<string>”,”eval”) names=code.co_names print(“\n” + ” “.join(names),”:”,bexp) for values in product(range(2), repeat=len(names)): env=dict(zip(names,values)) print(” “.join(map(str,values)),”:”,int(eval(code,env)))
Posted in Uncategorized
Leave a comment