This file contains hidden or 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 is_prime(n): | |
return not any(n % i == 0 for i in range(2, n / 2 + 1)) | |
def is_palindrome(n): | |
s = str(n) | |
return s == s[::-1] | |
if __name__ == '__main__': |
This file contains hidden or 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
from itertools import count, islice | |
def is_prime(n): | |
return not any(n % i == 0 for i in range(2, n / 2 + 1)) | |
def prime_generator(): | |
for candidate in count(2): | |
if (is_prime(candidate)): |
This file contains hidden or 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
# coding=utf-8 | |
import sys | |
def fizzbuzz(a, b, n): | |
tmp = [] | |
if n % a == 0: | |
tmp.append("F") |
This file contains hidden or 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
import sys | |
def split_line(line): | |
return line.split() | |
def reverse_list(l): | |
return l[::-1] | |
This file contains hidden or 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
import sys | |
def multiple_gen(n): | |
original_n = n | |
while True: | |
n = n + original_n | |
yield n | |
def multiples_of_a_number(x, n): | |
for e in multiple_gen(n): |
This file contains hidden or 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
import sys | |
# def to_bin(n): | |
# result = '' | |
# while n > 0: | |
# result = str(n % 2) + result | |
# n /= 2 | |
# return result | |
This file contains hidden or 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
import sys | |
if __name__ == '__main__': | |
test_cases = open(sys.argv[1], 'r') | |
for line in test_cases: | |
print(line.lower().rstrip()) | |
test_cases.close() | |
This file contains hidden or 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
import sys | |
def sum_of_digits(line): | |
return sum([int(e) for e in line]) | |
if __name__ == '__main__': | |
test_cases = open(sys.argv[1], 'r') | |
for line in test_cases: | |
print sum_of_digits(line.rstrip()) |
This file contains hidden or 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
import sys | |
def fib(n): | |
if n < 2: | |
return n | |
return fib(n - 1) + fib(n - 2) | |
if __name__ == '__main__': |
This file contains hidden or 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
from itertools import product, groupby | |
for k, g in groupby(product(range(1, 13), repeat=2), lambda x: x[0]): | |
print ''.join([str(i * j).rjust(4) for i, j in g]).strip() |