Skip to content

Instantly share code, notes, and snippets.

@LandonPowell
Last active August 10, 2016 14:00
Show Gist options
  • Save LandonPowell/aeacf1f02b49fdb96ba2f7607d5baf27 to your computer and use it in GitHub Desktop.
Save LandonPowell/aeacf1f02b49fdb96ba2f7607d5baf27 to your computer and use it in GitHub Desktop.
Someone on 4chan's /g/ board posted bad code so I sperged out and wrote this.
from sys import argv
def generatePrimes(words):
limit = len(words) ** 2
notPrimes = []
for a in range(3, limit):
for b in range(a * 2, limit, a):
notPrimes += [b]
notPrimes = set(notPrimes)
i = 3
x = []
while len(x) < len(words):
if not i in notPrimes: x += [(words[len(x)], i)]
i += 2
return x
if __name__ == "__main__":
if len(argv) < 3:
print "FizzGen requires at least 2 arguments. An int, and some strings."
rangeLimit = 100
primes = [("Fizz", 3), ("Buzz", 5), ("Bar", 7)]
else:
rangeLimit = int(argv[1]) + 1
primes = generatePrimes(argv[2:])
for number in range(1, rangeLimit):
print ''.join([
string
for string, prime in primes
if number % prime == 0 ]) or number
@LandonPowell
Copy link
Author

This latest edit should make some autists who want to optimize my shitposts slightly more happy. I'm using a sieve and a really shitty over-estimation of the limit I'll need because it runs fast, but it's entirely inelegant and unpythonic. I feel bad for folding on this. I should trigger them more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment