Author Archives: Linuxgal

Unknown's avatar

About Linuxgal

Need a spiritual home? Consider joining us at Mary Queen of the Universe Latter-day Buddhislamic Free Will Christian UFO Synagogue of Vishnu

Perfect

Perfect #include <stdio.h> int main(void) { for (unsigned int p = 2; p <= 23; p++) { unsigned long long m = (1ULL << p) – 1; int prime = 1; for (unsigned long long i = 2; i * … Continue reading

Posted in Uncategorized | Leave a comment

Antiprime

Print a list of antiprimes (highly composite numbers) with bc #! /usr/bin/bc define factors(n) { auto c, i for(i=1;i<=n;i++) { if(n%i==0) c+=1 } return c } max = 0 n = 1 for(c=19; c > 0;) { f = factors(n) … Continue reading

Posted in Uncategorized | Leave a comment

Awk Comb

Combinations of r elements chosen from a pool of n elements BEGIN { for (i=1; i <= r; i++) { A[i] = i if (i < r ) printf i OFS else print i} while (A[1] < n – r … Continue reading

Posted in Uncategorized | Leave a comment

Hex

Hex #!/usr/bin/python3 import sys with open(sys.argv[1], “rb”) as f: data = f.read() for offset in range(0, len(data), 16): b = data[offset:offset + 16] left = ” “.join(f”{x:02x}” for x in b[:8]) right = ” “.join(f”{x:02x}” for x in b[8:]) hexpart … Continue reading

Posted in Uncategorized | Leave a comment

Euler

scale=90 for (e = n = f = 1; f != 0; f /= ++n) e += f e

Posted in Uncategorized | Leave a comment

Palprimes

Palindromic primes 20 FOR N=2 TO 100000 30 I=N 35 J=0 40 J=J*10+I-INT(I/10)*10 43 I=INT(I/10) 47 IF I>0 THEN 40 50 IF J<>N THEN 80 52 IF N=2 THEN 75 60 FOR I=2 TO SQR(N) 65 IF N-INT(N/I)*I=0 THEN 80 … Continue reading

Posted in Uncategorized | Leave a comment

Palindate

Palindate #! /bin/bash is_palyndrom_date() { date -d “$1” 1>/dev/null 2>&1 && echo “$1” ; } for _H in {2..9}; do for _I in {0..9}; do for _J in {0..99}; do is_palyndrom_date ${_H}${_I}`printf “%02d%s” ${_J}`-`printf “%02d%s” ${_J} | rev`-`printf “%02d%s” ${_H}${_I} | … Continue reading

Posted in Uncategorized | Leave a comment

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