![]() |
I was wondering what prime numbers would look like in binary format. So, I wrote this little Python script prime.py: def int2bin(n): return ' '.join('.#'[int(c)] for c in bin(n)[2:]) def print_bin_centered(s, w): print int2bin(s).center(w).rstrip() def is_prime(n): if n < 2: return False if n == 2: return True if n % 2 == 0: return False for i in range(3, int(n ** 0.5) + 1, 2): if n % i == 0: return False return True print_bin_centered(2, 15) for i in range(3, 256, 2): if is_prime(i): print_bin_centered(i, 15) The output is a nicely formatted ASCII interpretation prime.txt: # . # # # . # # # # # . # # # # . # # . . . # # . . # # # . # # # # # # . # # # # # # # . . # . # # . # . . # # . # . # # # . # # # # # # . # . # # # # . # # # # # # . # # . . . . # # # . . . # # # # . . # . . # # . . # # # # # . # . . # # # . # # . . # # # . . . . # # # . . # . # # # . . # # # # # . # . # # # # . # # . # # # # . . . # # # # # # # # # . . . . . # # # . . . # . . # # . . . # . # # # . . # . # . # # . . # . # # # # . . # # # . # # . # . . . # # # . # . . # # # # . # . # # . # # . # # . . # # # . # # . # . # # . # # # # # # # # . . . . . # # # . . . # . # # # . . . # # # # # . # . . # # # # . # # # # # # # # . . . # # # # # . . # . # # # # . # . . # # # # . # # # # # # # # . . . # # # # # # . # # I just did a screen shot of the output, loaded it in Photoshop, and ran a “Chalk & Charcoal” Filter. |