Skip to content

Instantly share code, notes, and snippets.

Created July 9, 2014 02:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/1360fc3849a10cb0de1a to your computer and use it in GitHub Desktop.
Save anonymous/1360fc3849a10cb0de1a to your computer and use it in GitHub Desktop.
def sol(n):
numbers = [0]*n
char = 0 #store 8 bits here
c = 0 #counter for converting from binary to decimal
toreturn = "" #string to be returned
for i in range(3,n,2):
if numbers[i] != 1: #prime number
char += 2 ** (7 - c) #convert it to decimal based on its position
#delete all multiples of that prime number
for j in range(i,n,i):
numbers[j] = 1
#char reached 8 bits: combine them to 1 byte, add it to toretrun, and reset char and c
if (7 - c) == 0:
toreturn += chr(char)
char = 0
c = -1
c += 1 #update position
return toreturn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment