Created
July 9, 2014 02:53
-
-
Save anonymous/1360fc3849a10cb0de1a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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