Posts
Category Archives: Uncategorized
Deal
Shuffle and deal four hands of five cards each with #Python #!/usr/bin/python3 import random deck = [ ‘๐ก’,’๐ข’,’๐ฃ’,’๐ค’,’๐ฅ’,’๐ฆ’,’๐ง’,’๐จ’,’๐ฉ’,’๐ช’,’๐ซ’,’๐ญ’,’๐ฎ’, ‘๐ฑ’,’๐ฒ’,’๐ณ’,’๐ด’,’๐ต’,’๐ถ’,’๐ท’,’๐ธ’,’๐น’,’๐บ’,’๐ป’,’๐ฝ’,’๐พ’, ‘๐’,’๐’,’๐’,’๐’,’๐ ’,’๐’,’๐’,’๐’,’๐’,’๐’,’๐’,’๐’,’๐’, ‘๐’,’๐’,’๐’,’๐’,’๐’,’๐’,’๐’,’๐’,’๐’,’๐’,’๐’,’๐’,’๐’ ] random.shuffle(deck) for i in range(0, 20, 5): print(” “.join(deck[i:i+5]))
Posted in Uncategorized
Leave a comment
Perl dupes
Highlight consecutive duplicated words with Perl perl -pe ‘s/\b(\w+)\s+\1\b/\e[31m$&\e[0m/gi’ gettysburg.txt
Posted in Uncategorized
Leave a comment
Factorial Primes
Factorial primes with gawk #! /usr/bin/gawk -f function isprime(n, i) { if(n==2)return 1 if(n<2||n%2==0)return 0 for(i=3;i*i<=n;i+=2) if(n%i==0)return 0 return 1 } BEGIN { for(x=i=1;z<10;i++){ x*=i if(isprime(x-1)){z++;print i”! – 1 = “x-1} if(isprime(x+1)){z++;print i”! + 1 = “x+1} } } The … Continue reading
Posted in Uncategorized
Leave a comment
Trig
Trig functions #! /usr/bin/bc -l define t(x) { return s(x) / c(x) } define y(y) { if (y == -1) return -2 * a(1) /* -pi/2 */ if (y == 1) return 2 * a(1) /* pi/2 */ return a(y … Continue reading
Posted in Uncategorized
Leave a comment
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
1 Liners
Print all primes less than 5000: $ python3 -c ‘print([i for i in range(2,5000) if all(i%j for j in range(2,int(i**0.5)+1))])’ Break a GIF into individual frames: ffmpeg -i taarna.gif frame_%d.jpg List all the words in a file with no matches … Continue reading
Posted in Uncategorized
Leave a comment