Category Archives: Uncategorized

Anagrams

Find anagrams with Python #!/usr/bin/env python3 from collections import Counter import sys,os s=sys.argv[1] def anagrams(word,words): cw=Counter(word) return [w for w in words if Counter(w)==cw] base=os.path.dirname(os.path.abspath(__file__)) path=os.path.join(base,”words.txt”) with open(path) as f: lines=f.read().splitlines() print(anagrams(s,lines))

Posted in Uncategorized | Leave a comment

Win311

Posted in Uncategorized | Leave a comment

Quadratic

Solve quadratic equations with impunity using Python (and complex numbers) #!/usr/bin/env python3 import math,sys a,b,c=map(float,sys.argv[1:]) d=b*b-4*a*c if d>=0:x1=(-b+math.sqrt(d))/(2*a);x2=(-b-math.sqrt(d))/(2*a) else:r=-b/(2*a);i=math.sqrt(-d)/(2*a);x1,x2=complex(r,i),complex(r,-i) print(“The function has”,”two real roots: {} and {}”.format(x1,x2)if d>0 else “one double root: {}”.format(x1)if d==0 else “two complex roots: {} and … Continue reading

Posted in Uncategorized | Leave a comment

Pyble

Print the shortest and longest verses in the Bible with Python #!/usr/bin/env python3 import os base=os.path.dirname(os.path.abspath(__file__)) path=os.path.join(base,”kjv.txt”) with open(path) as f: print(“Shortest verse:”,min(f,key=len)) with open(path) as f: print(“Longest verse:”,max(f,key=len))

Posted in Uncategorized | Leave a comment

Contours

#!/usr/bin/env python3 import matplotlib.pyplot as p,numpy as n x,y=n.meshgrid(n.linspace(-4,4,512),n.linspace(-4,4,512)) z=(1-x/2+x**4+y**3)*n.exp(-x**2-y**2)*(1-x/3-y**4)*(3-y+x**2) z+=.5*n.sin(.8*x+.6*y)+.4*n.cos(.5*x-.7*y)+.3*n.sin(.6*x-.4*y) p.contour(x,y,z,levels=n.linspace(z.min(),z.max(),25),cmap=’terrain’) p.show()

Posted in Uncategorized | Leave a comment

Xmas

#!/usr/bin/env python3 from datetime import* t=datetime.today() print(“Only”,(datetime(t.year,12,25)-t).days,”shopping days until Christmas.”)

Posted in Uncategorized | Leave a comment

Factorials

teresita:Desktop$ seq 3 | paste -sd* | bc 6 teresita:Desktop$ seq 30 | paste -sd* | bc 265252859812191058636308480000000 teresita:Desktop$ seq 300 | paste -sd* | bc 306057512216440636035370461297268629388588804173576999416776741259476533176716867465515291422477573349939147888701726368864263907759003154226842927906974559841225476930271954604008012215776252176854255965356903506788725264321896264299365204576448830388909753943489625436053225980776521270822437639449120128678675368305712293681943649956460498166450227716500185176546469340112226034729724066333258583506870150169794168850353752137554910289126407157154830282284937952636580145235233156936482233436799254594095276820608062232812387383880817049600000000000000000000000000000000000000000000000000000000000000000000000000

Posted in Uncategorized | Leave a comment

Rot13

Rot13 with Python #!/usr/bin/python3 import sys, string def rot13(s): return ”.join([chr(x.islower() and ((ord(x) – 84) % 26) + 97 or x.isupper() and ((ord(x) – 52) % 26) + 65 or ord(x)) for x in s]) for line in sys.stdin: sys.stdout.write(rot13(line))

Posted in Uncategorized | Leave a comment

PyPrime

Print prime numbers in a range with Python #!/usr/bin/env python3 import sys m = int(sys.argv[1]) n = int(sys.argv[2]) primes = [i for i in range(m,n) if all(i%j !=0 for j in range(2,int(i**0.5) + 1))] print(primes)

Posted in Uncategorized | Leave a comment

Aiksaurus

Aiksaurus – a thesaurus for the Linux terminal

Posted in Uncategorized | Leave a comment