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 detecting_cycles(l): | |
while True: | |
try: | |
top = l.pop(0) | |
pos = l.index(top) | |
candidate = l[0:pos] | |
sample = l[pos + 1:pos + 1 + len(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
import sys | |
import re | |
def pangrams(s): | |
alphabet = "abcdefghijklmnopqrstuvwxyz" | |
s = re.sub(' ', '', s).lower() | |
for c in s: |
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 get_first_non_repeated_character(s): | |
first_idx_of_non_repeated_character = map(lambda x: s.count(x), s).index(1) | |
return s[first_idx_of_non_repeated_character] | |
if __name__ == '__main__': | |
test_cases = open(sys.argv[1], 'r') |
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 remove_characters(s, s2): | |
return ''.join([c for c in s if c not in s2]) | |
if __name__ == '__main__': | |
test_cases = open(sys.argv[1], 'r') | |
for line in test_cases: |
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 sys.byteorder == 'little': | |
print "LittleEndian" | |
else: | |
print "BigEndian" |
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 | |
def sum_of_integers(ints): | |
max_ending_here = 0 | |
max_so_far = max_element = -sys.maxint - 1 | |
for x in ints: | |
max_ending_here = max(0, max_ending_here + x) | |
max_so_far = max(max_so_far, max_ending_here) | |
max_element = max(max_element, x) |
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 decimal_to_binary(n): | |
if n == 0: | |
return '0' | |
result = '' | |
while n > 0: | |
result = str(n % 2) + 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 | |
def trailing_string(ary): | |
if ary[0].split()[-1].endswith(ary[1]): | |
return 1 | |
else: | |
return 0 | |
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 | |
from math import sqrt | |
def double_square(n): | |
s = int(sqrt(n)) | |
count = 0 | |
for i in range(0, s + 1): | |
D = sqrt(n - i * i) | |
if D >= i and D == int(D): |