Skip to content

Instantly share code, notes, and snippets.

@odedlaz
Last active February 9, 2016 19:10
Show Gist options
  • Save odedlaz/6cb8c75197e92bd5da5f to your computer and use it in GitHub Desktop.
Save odedlaz/6cb8c75197e92bd5da5f to your computer and use it in GitHub Desktop.
mary hw
########### hw 4 #############
print([num for num in xrange(1000) if sum(map(int, str(num))) == 10])
################ hw 5 ################
def occ(n, specific):
for num in xrange(n):
times = len([x for x in str(num) if str(specific) == x])
yield (num, times)
for num, times in occ(100,2):
print("%s -> %s" % (num,times))
################ hw 6 ################
def is_prime(num):
if num in [0,1]:
return False
if num == 2:
return True
return False if num & 1 == 0 else not any(num % n == 0 for n in xrange(3,int(num**0.5),2))
for n in xrange(100):
print("%s %s prime" % (n,"is" if is_prime(n) else "is not"))
################ hw 7 ################
def fib(num):
a,b = 0,1
while a + b < num:
a, b = b, a + b
yield b
print(list(fib(100)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment