Skip to content

Instantly share code, notes, and snippets.

View yuheiomori's full-sized avatar

Yuhei Omori yuheiomori

View GitHub Profile
@yuheiomori
yuheiomori / prime_palindrome.py
Created April 24, 2012 21:24
codeeval Prime Palindrome
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__':
@yuheiomori
yuheiomori / sum_of_primes.py
Created April 24, 2012 21:25
codeeval Sum of Primes
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)):
@yuheiomori
yuheiomori / fizzbuzz.py
Last active October 3, 2015 17:18
codeeval fizzbuzz
# coding=utf-8
import sys
def fizzbuzz(a, b, n):
tmp = []
if n % a == 0:
tmp.append("F")
@yuheiomori
yuheiomori / reverse_words.py
Created April 26, 2012 20:51
CodeEval Reverse Words
import sys
def split_line(line):
return line.split()
def reverse_list(l):
return l[::-1]
@yuheiomori
yuheiomori / multiples_of_a_number.py
Last active October 3, 2015 19:38
CodeEval Multiples of a Number
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):
@yuheiomori
yuheiomori / bits_positions.py
Last active October 3, 2015 20:38
CodeEval Bits Positions
import sys
# def to_bin(n):
# result = ''
# while n > 0:
# result = str(n % 2) + result
# n /= 2
# return result
@yuheiomori
yuheiomori / lower_case.py
Created April 30, 2012 00:58
CodeEval Lower Case
import sys
if __name__ == '__main__':
test_cases = open(sys.argv[1], 'r')
for line in test_cases:
print(line.lower().rstrip())
test_cases.close()
@yuheiomori
yuheiomori / sum_of_digits.py
Created May 1, 2012 00:27
CodeEval Sum of Digits
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())
@yuheiomori
yuheiomori / fibonacci_series.py
Created May 1, 2012 21:16
CodeEval Fibonacci series
import sys
def fib(n):
if n < 2:
return n
return fib(n - 1) + fib(n - 2)
if __name__ == '__main__':
@yuheiomori
yuheiomori / multiplication_tables.py
Created May 3, 2012 00:00
CodeEval Multiplication Tables
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()