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
with open('task3a.txt') as f: | |
lines = [] | |
for ele in f: | |
lines.append(list(ele.strip('\n\r '))) | |
gamma = ''.join([ max(x, key=x.count) for x in zip(*lines) ]) | |
epsilon = ''.join('1' if x == '0' else '0' for x in gamma) | |
power = int(gamma, 2) * int(epsilon,2) | |
print(power) |
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 decimal import Decimal, ROUND_HALF_UP | |
with open('task3a.txt') as f: | |
lines = [] | |
for ele in f: | |
lines.append([int(x) for x in ele.strip('\n\r ')]) | |
def calcVal(lines, flip): | |
linez = lines | |
loop = 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
bingoboards = [] | |
bingonumbers = [] | |
with open('task4a.txt') as f: | |
bingonumbers = f.readline().strip('\n\r ').split(',') | |
f.readline() | |
while(True): | |
bingoboard = [] | |
for x in range(5): | |
line = [] | |
for square in f.readline().strip('\n\r').split(' '): |
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
bingoBoards = [] | |
bingoNumbers = [] | |
previousWinner = [] | |
winningCall = '0' | |
with open('task4a.txt') as f: | |
bingoNumbers = f.readline().strip('\n\r ').split(',') | |
f.readline() | |
while(True): | |
bingoBoard = [] | |
for x in range(5): |
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 numpy | |
coords = [] | |
grid = numpy.zeros((1000, 1000)) | |
with open('task5.txt') as f: | |
lines = f.read().splitlines() | |
for line in lines: | |
coords.append(line.split(' -> ')) | |
for coord in coords: |
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 numpy | |
coords = [] | |
grid = numpy.zeros((1000, 1000)) | |
with open('task5.txt') as f: | |
lines = f.read().splitlines() | |
for line in lines: | |
coords.append(line.split(' -> ')) | |
for coord in coords: |
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
fishes = [] | |
with open('task6.txt') as f: | |
fishes = [int(x) for x in next(f).split(',')] | |
print ("Initial State: {}".format(','.join([str(x) for x in fishes]))) | |
for days in range(80): | |
newfish = [] | |
for index,fish in enumerate(fishes): | |
if fish > 0: | |
fishes[index] = fish -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 numpy | |
fishes = [0, 0, 0, 0, 0, 0, 0, 0, 0] | |
with open('task6.txt') as f: | |
tempfishes = [int(x) for x in next(f).split(',')] | |
for fishy in tempfishes: | |
if fishy == 0: | |
fishes[0] += 1 | |
elif fishy == 1: | |
fishes[1] += 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 numpy | |
test = False | |
file = 'data/task7test.txt' if test else 'data/task7.txt' | |
with open(file) as f: | |
crabmarines = numpy.array([int(x) for x in next(f).split(',')]) | |
bestPosition = 9999999999 | |
for position in range(crabmarines.min(),crabmarines.max()+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
test = False | |
file = 'data/task7test.txt' if test else 'data/task7.txt' | |
with open(file) as f: | |
crabmarines = [int(x) for x in next(f).split(',')] | |
bestPosition = 9999999999 | |
for position in range(min(crabmarines),max(crabmarines)+1): | |
curPosition = sum(list(map(lambda x: abs(position-x)*((abs(position-x)+1)/2), crabmarines))) | |
if curPosition < bestPosition: |