├── 1 ├── solution.py3 ├── input ├── output └── solution.py2 ├── 7 ├── output ├── solution.py3 ├── input └── solution.py2 ├── 8 ├── input ├── output └── solution.py2 ├── 42 ├── solution.py3 ├── input ├── output └── solution.py2 ├── 82 ├── solution.py3 ├── input ├── output └── solution.py2 ├── 113 ├── solution.py3 ├── output ├── input └── solution.py2 ├── 210 ├── solution.py3 ├── output ├── input └── solution.py2 ├── 214 ├── solution.py3 ├── input ├── output └── solution.py2 ├── 232 ├── solution.py3 ├── output ├── input └── solution.py2 └── 237 ├── solution.py3 ├── output ├── input └── solution.py2 /1/solution.py3: -------------------------------------------------------------------------------- 1 | solution.py2 -------------------------------------------------------------------------------- /113/solution.py3: -------------------------------------------------------------------------------- 1 | solution.py2 -------------------------------------------------------------------------------- /210/solution.py3: -------------------------------------------------------------------------------- 1 | solution.py2 -------------------------------------------------------------------------------- /214/solution.py3: -------------------------------------------------------------------------------- 1 | solution.py2 -------------------------------------------------------------------------------- /232/solution.py3: -------------------------------------------------------------------------------- 1 | solution.py2 -------------------------------------------------------------------------------- /237/solution.py3: -------------------------------------------------------------------------------- 1 | solution.py2 -------------------------------------------------------------------------------- /42/solution.py3: -------------------------------------------------------------------------------- 1 | solution.py2 -------------------------------------------------------------------------------- /7/output: -------------------------------------------------------------------------------- 1 | 20 2 | 8 3 | 10 4 | -------------------------------------------------------------------------------- /7/solution.py3: -------------------------------------------------------------------------------- 1 | solution.py2 -------------------------------------------------------------------------------- /82/solution.py3: -------------------------------------------------------------------------------- 1 | solution.py2 -------------------------------------------------------------------------------- /1/input: -------------------------------------------------------------------------------- 1 | 3 5 10 2 | 2 7 15 3 | -------------------------------------------------------------------------------- /82/input: -------------------------------------------------------------------------------- 1 | 6 2 | 153 3 | 351 4 | -------------------------------------------------------------------------------- /232/output: -------------------------------------------------------------------------------- 1 | 3 4 2 1 2 | 4 3 5 2 1 3 | -------------------------------------------------------------------------------- /237/output: -------------------------------------------------------------------------------- 1 | True 2 | True 3 | False 4 | -------------------------------------------------------------------------------- /42/input: -------------------------------------------------------------------------------- 1 | 1 2 | 9 3 | 011 4 | 12345 5 | -------------------------------------------------------------------------------- /42/output: -------------------------------------------------------------------------------- 1 | 0 2 | 1 3 | 6 4 | 64 5 | -------------------------------------------------------------------------------- /82/output: -------------------------------------------------------------------------------- 1 | True 2 | True 3 | False 4 | -------------------------------------------------------------------------------- /232/input: -------------------------------------------------------------------------------- 1 | 4 3 2 1 | 1 2 | 5 4 3 2 1 | 2 3 | -------------------------------------------------------------------------------- /8/input: -------------------------------------------------------------------------------- 1 | Hello World 2 | Hello CodeEval 3 | -------------------------------------------------------------------------------- /8/output: -------------------------------------------------------------------------------- 1 | World Hello 2 | CodeEval Hello 3 | -------------------------------------------------------------------------------- /210/output: -------------------------------------------------------------------------------- 1 | Yo! 2 | Hello World! 3 | Hello World! 4 | -------------------------------------------------------------------------------- /113/output: -------------------------------------------------------------------------------- 1 | 135 0 54 2 | 40 3 | 13 16 225 14 120 10 4 | -------------------------------------------------------------------------------- /7/input: -------------------------------------------------------------------------------- 1 | * + 2 3 4 2 | + * 2 3 / 10 5 3 | * / 10 3 3 4 | -------------------------------------------------------------------------------- /214/input: -------------------------------------------------------------------------------- 1 | 02:26:31 14:44:45 09:53:27 2 | 05:33:44 21:25:41 3 | -------------------------------------------------------------------------------- /214/output: -------------------------------------------------------------------------------- 1 | 14:44:45 09:53:27 02:26:31 2 | 21:25:41 05:33:44 3 | -------------------------------------------------------------------------------- /1/output: -------------------------------------------------------------------------------- 1 | 1 2 F 4 B F 7 8 F B 2 | 1 F 3 F 5 F B F 9 F 11 F 13 FB 15 3 | -------------------------------------------------------------------------------- /113/input: -------------------------------------------------------------------------------- 1 | 9 0 6 | 15 14 9 2 | 5 | 8 3 | 13 4 15 1 15 5 | 1 4 15 14 8 2 4 | -------------------------------------------------------------------------------- /237/input: -------------------------------------------------------------------------------- 1 | 64 6e 78 | 100101100 11110 2 | 5e 7d 59 | 1101100 10010101 1100111 3 | 93 75 | 1000111 1011010 1100010 4 | -------------------------------------------------------------------------------- /8/solution.py2: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | from __future__ import print_function 3 | 4 | import sys 5 | 6 | with open(sys.argv[1], 'r') as test_cases: 7 | for test in test_cases: 8 | if not test: 9 | continue 10 | print(' '.join(reversed(test.split()))) 11 | -------------------------------------------------------------------------------- /210/input: -------------------------------------------------------------------------------- 1 | +[--->++<]>+++.[->+++++++<]>.[--->+<]>----. 2 | ++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+. 3 | >++++++++[-<+++++++++>]<.>>+>-[+]++>++>+++[>[->+++<<+++>]<<]>-----.>->+++..+++.>-.<<+[>[+>+]>>]<--------------.>>.+++.------.--------.>+.>+ 4 | -------------------------------------------------------------------------------- /82/solution.py2: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | from __future__ import print_function 3 | 4 | import sys 5 | 6 | with open(sys.argv[1], 'r') as test_cases: 7 | for test in test_cases: 8 | test = test.strip() 9 | if not test: 10 | continue 11 | print(sum(int(n) ** len(test) for n in test) == int(test)) 12 | -------------------------------------------------------------------------------- /214/solution.py2: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | from __future__ import print_function 3 | 4 | import time 5 | import sys 6 | 7 | with open(sys.argv[1], 'r') as test_cases: 8 | for test in test_cases: 9 | if not test: 10 | continue 11 | test = test.strip().split() 12 | sorted_times = sorted([time.strptime(t, '%H:%M:%S') for t in test]) 13 | print(' '.join(time.strftime('%H:%M:%S', t) for t in reversed(sorted_times))) 14 | -------------------------------------------------------------------------------- /113/solution.py2: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | from __future__ import print_function 3 | 4 | ''' 5 | Multiply Lists 6 | ''' 7 | 8 | import sys 9 | 10 | with open(sys.argv[1], 'r') as test_cases: 11 | for test in test_cases: 12 | if not test: 13 | continue 14 | list1, list2 = test.strip().split('|') 15 | list1 = list1.split() 16 | list2 = list2.split() 17 | assert len(list1) == len(list2) 18 | print(' '.join(str(int(x[0]) * int(x[1])) for x in zip(list1, list2))) 19 | -------------------------------------------------------------------------------- /237/solution.py2: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | from __future__ import print_function 3 | 4 | import sys 5 | 6 | def component_sum(component_string, base): 7 | return sum([int(component, base) for component in component_string.split()]) 8 | 9 | with open(sys.argv[1], 'r') as test_cases: 10 | for test in test_cases: 11 | if not test: 12 | continue 13 | virus_components, antivirus_components = test.split('|') 14 | result = component_sum(virus_components, 16) <= component_sum(antivirus_components, 2) 15 | print(result) 16 | -------------------------------------------------------------------------------- /1/solution.py2: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | from __future__ import print_function 3 | 4 | import sys 5 | 6 | with open(sys.argv[1], 'r') as test_cases: 7 | for test in test_cases: 8 | if not test: 9 | continue 10 | output = '' 11 | first_divisor, second_divisor, count = [int(x) for x in test.split()] 12 | for num in range(1, count + 1): 13 | if num % first_divisor == 0: 14 | output += 'F' 15 | if num % second_divisor == 0: 16 | output += 'B' 17 | if num % first_divisor != 0 and num % second_divisor != 0: 18 | output += str(num) 19 | output += ' ' 20 | print(output) 21 | -------------------------------------------------------------------------------- /7/solution.py2: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | from __future__ import division, print_function 3 | 4 | import sys 5 | 6 | def evaluate(elements): 7 | stack = [] 8 | for element in elements: 9 | if element == '*': 10 | stack.append(stack.pop() * stack.pop()) 11 | elif element == '+': 12 | stack.append(stack.pop() + stack.pop()) 13 | elif element == '/': 14 | top = stack.pop() 15 | bottom = stack.pop() 16 | stack.append(top / bottom) 17 | else: stack.append(int(element)) 18 | return int(stack[0]) 19 | 20 | with open(sys.argv[1], 'r') as test_cases: 21 | for test in test_cases: 22 | if not test: 23 | continue 24 | test = test.strip().split() 25 | print(evaluate(reversed(test))) 26 | -------------------------------------------------------------------------------- /232/solution.py2: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | from __future__ import division, print_function 3 | 4 | import sys 5 | 6 | def stupid_sort_iteration(values): 7 | for index in range(0, len(values) - 1): 8 | if values[index] > values[index + 1]: 9 | values[index], values[index + 1] = values[index + 1], values[index] 10 | break 11 | 12 | def run_sort_iterations(values, number): 13 | for i in range(number): 14 | stupid_sort_iteration(values) 15 | 16 | with open(sys.argv[1], 'r') as test_cases: 17 | for test in test_cases: 18 | if not test: 19 | continue 20 | values, num_iterations = test.split('|') 21 | values = list(map(int, values.split())) 22 | num_iterations = int(num_iterations) 23 | run_sort_iterations(values, num_iterations) 24 | print(' '.join(map(str, values))) 25 | -------------------------------------------------------------------------------- /42/solution.py2: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | from __future__ import print_function 3 | 4 | import itertools 5 | import sys 6 | 7 | def ugly_number(num): 8 | return bool(num % 2 == 0 or num % 3 == 0 or num % 5 == 0 or num % 7 == 0) 9 | 10 | def generate_components(num_string): 11 | yield [int(num_string)] 12 | split_choices = range(1, len(num_string)) 13 | for num_splits in split_choices: 14 | for indexes in itertools.combinations(split_choices, num_splits): 15 | yield [int(num_string[i:j]) for i, j in zip((0,) + indexes, indexes + (None,))] 16 | 17 | def generate_candidates(component): 18 | if len(component) == 1: 19 | yield component[0] 20 | else: 21 | for candidate in generate_candidates(component[1:]): 22 | yield component[0] + candidate 23 | yield component[0] - candidate 24 | 25 | def generate_results(num_string): 26 | for component in generate_components(test): 27 | for candidate in generate_candidates(component): 28 | yield ugly_number(candidate) 29 | 30 | with open(sys.argv[1], 'r') as test_cases: 31 | for test in test_cases: 32 | if not test: 33 | continue 34 | test = test.strip() 35 | print(list(generate_results(test)).count(True)) 36 | -------------------------------------------------------------------------------- /210/solution.py2: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | ''' 3 | BRAINF*CK 4 | CHALLENGE DESCRIPTION: 5 | 6 | Looking for something utterly mind-blowing? Look no further, you hit the right place! 7 | This challenge is inextricably linked with Brainf*ck, the most famous esoteric programming language invented by Urban Muller. Is this the first time you hear about Brainf*ck? Find out more Brainf*ck (wiki) 8 | 9 | Brainf*ck consists of only 8 basic commands: 10 | > - move to the next cell; 11 | < - move to the previous cell; 12 | + - increment the value in the current cell by 1; 13 | - - decrement the value of the current cell by 1; 14 | . - output the value of the current cell; 15 | , - input the value outside and store it in the current cell; 16 | [ - if the value of the current cell is zero, move forward on the text to the program to] taking into account nesting; 17 | ] - if the value of the current cell is not zero, go back on the text of the program to [considering nesting; 18 | 19 | So, you should write a program that will get the code on the Brainf*ck language, calculate this code, and display the final result of the program. It can be a simple output of letters or a complex cycle; in any case, your program should handle it. 20 | ''' 21 | from __future__ import print_function 22 | 23 | import collections 24 | import sys 25 | 26 | def preprocess(program): 27 | program_cells = [] 28 | stack = [] 29 | for index, instruction in enumerate(program): 30 | if instruction == '[': 31 | program_cells.append('[') 32 | stack.append(index) 33 | elif instruction == ']': 34 | previous_index = stack.pop() 35 | program_cells.append(previous_index) 36 | program_cells[previous_index] = index 37 | else: 38 | program_cells.append(instruction) 39 | return program_cells 40 | 41 | 42 | def evaluate(program): 43 | program = preprocess(program) 44 | 45 | cells = collections.defaultdict(int) 46 | instruction_pointer = 0 47 | cell_pointer = 0 48 | 49 | while instruction_pointer < len(program): 50 | instruction = program[instruction_pointer] 51 | if instruction == '>': 52 | cell_pointer += 1 53 | elif instruction == '<': 54 | cell_pointer -= 1 55 | elif instruction == '+': 56 | cells[cell_pointer] = (cells[cell_pointer] + 1) % 256 57 | elif instruction == '-': 58 | cells[cell_pointer] = (cells[cell_pointer] - 1) % 256 59 | elif instruction == '.': 60 | yield chr(cells[cell_pointer]) 61 | elif instruction == ',': 62 | raise Exception 63 | else: 64 | if instruction > instruction_pointer: 65 | if cells[cell_pointer] == 0: 66 | instruction_pointer = instruction 67 | elif instruction < instruction_pointer: 68 | if cells[cell_pointer] != 0: 69 | instruction_pointer = instruction 70 | else: 71 | raise Exception 72 | instruction_pointer += 1 73 | 74 | with open(sys.argv[1], 'r') as test_cases: 75 | for test in test_cases: 76 | if not test: 77 | continue 78 | test = test.strip() 79 | print(''.join(evaluate(test))) 80 | --------------------------------------------------------------------------------