another day of coding
This commit is contained in:
parent
6a4482d038
commit
570f54b720
63
11/part1.py
Normal file
63
11/part1.py
Normal file
@ -0,0 +1,63 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
import re
|
||||
|
||||
RE_PAIR = re.compile(r'(.)\1.*(.)\2')
|
||||
|
||||
def get_next_char(ch):
|
||||
i = ord(ch) + 1
|
||||
if i > 122:
|
||||
return (True, 'a')
|
||||
return (False, chr(i))
|
||||
|
||||
|
||||
def get_next_password(passwd):
|
||||
|
||||
result = ""
|
||||
copy = False
|
||||
overflow = None
|
||||
for pos in reversed(range(len(passwd))):
|
||||
if not copy:
|
||||
(overflow, ch) = get_next_char(passwd[pos])
|
||||
result = ch + result
|
||||
copy = not overflow
|
||||
else:
|
||||
result = passwd[pos] + result
|
||||
if overflow:
|
||||
result = 'a' + result
|
||||
return result
|
||||
|
||||
def check_password(passwd):
|
||||
|
||||
if passwd.count('i') > 0:
|
||||
return False
|
||||
if passwd.count('l') > 0:
|
||||
return False
|
||||
if re.search(RE_PAIR, passwd) is None:
|
||||
return False
|
||||
|
||||
for pos in range(len(passwd)-2):
|
||||
x1 = ord(passwd[pos])
|
||||
x2 = ord(passwd[pos+1])
|
||||
x3 = ord(passwd[pos+2])
|
||||
if (x1 +1 != x2):
|
||||
continue
|
||||
if (x2 +1 != x3):
|
||||
continue
|
||||
break
|
||||
else:
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
|
||||
def main():
|
||||
input = 'vzbxkghb';
|
||||
while True:
|
||||
input = get_next_password(input)
|
||||
if check_password(input):
|
||||
break
|
||||
print input
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
67
11/part2.py
Normal file
67
11/part2.py
Normal file
@ -0,0 +1,67 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
import re
|
||||
|
||||
RE_PAIR = re.compile(r'(.)\1.*(.)\2')
|
||||
|
||||
def get_next_char(ch):
|
||||
i = ord(ch) + 1
|
||||
if i > 122:
|
||||
return (True, 'a')
|
||||
return (False, chr(i))
|
||||
|
||||
|
||||
def get_next_password(passwd):
|
||||
|
||||
result = ""
|
||||
copy = False
|
||||
overflow = None
|
||||
for pos in reversed(range(len(passwd))):
|
||||
if not copy:
|
||||
(overflow, ch) = get_next_char(passwd[pos])
|
||||
result = ch + result
|
||||
copy = not overflow
|
||||
else:
|
||||
result = passwd[pos] + result
|
||||
if overflow:
|
||||
result = 'a' + result
|
||||
return result
|
||||
|
||||
def check_password(passwd):
|
||||
|
||||
if passwd.count('i') > 0:
|
||||
return False
|
||||
if passwd.count('l') > 0:
|
||||
return False
|
||||
if re.search(RE_PAIR, passwd) is None:
|
||||
return False
|
||||
|
||||
for pos in range(len(passwd)-2):
|
||||
x1 = ord(passwd[pos])
|
||||
x2 = ord(passwd[pos+1])
|
||||
x3 = ord(passwd[pos+2])
|
||||
if (x1 +1 != x2):
|
||||
continue
|
||||
if (x2 +1 != x3):
|
||||
continue
|
||||
break
|
||||
else:
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
|
||||
def main():
|
||||
input = 'vzbxkghb';
|
||||
while True:
|
||||
input = get_next_password(input)
|
||||
if check_password(input):
|
||||
break
|
||||
while True:
|
||||
input = get_next_password(input)
|
||||
if check_password(input):
|
||||
break
|
||||
print input
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
40
12/part1.py
Normal file
40
12/part1.py
Normal file
@ -0,0 +1,40 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
import json
|
||||
from pprint import pprint
|
||||
|
||||
def traverse_structructure(data):
|
||||
|
||||
result = []
|
||||
|
||||
if type(data) is list:
|
||||
for item in data:
|
||||
for value in traverse_structructure(item):
|
||||
yield value
|
||||
|
||||
if type(data) is dict:
|
||||
for key in data.keys():
|
||||
for value in traverse_structructure(data[key]):
|
||||
yield value
|
||||
|
||||
if type(data) is unicode:
|
||||
yield 0
|
||||
|
||||
if type(data) is int:
|
||||
yield data
|
||||
|
||||
# print type(data)
|
||||
|
||||
def main():
|
||||
with open("input") as data_file:
|
||||
input = json.load(data_file)
|
||||
|
||||
sum = 0
|
||||
for value in traverse_structructure(input):
|
||||
sum += value
|
||||
|
||||
print sum
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
54
12/part2.py
Normal file
54
12/part2.py
Normal file
@ -0,0 +1,54 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
import json
|
||||
from pprint import pprint
|
||||
|
||||
def traverse_structructure(data):
|
||||
|
||||
result = []
|
||||
|
||||
if type(data) is list:
|
||||
for item in data:
|
||||
for value in traverse_structructure(item):
|
||||
if value is None:
|
||||
value = 0
|
||||
yield value
|
||||
|
||||
if type(data) is dict:
|
||||
sum = 0
|
||||
foundNone = False
|
||||
for key in data.keys():
|
||||
for value in traverse_structructure(data[key]):
|
||||
print "dict: %s" % value
|
||||
if value is None:
|
||||
foundNone = True
|
||||
value = 0
|
||||
sum += value
|
||||
if foundNone:
|
||||
sum = 0
|
||||
yield sum
|
||||
|
||||
if type(data) is unicode:
|
||||
if data == 'red':
|
||||
yield None
|
||||
else:
|
||||
yield 0
|
||||
|
||||
if type(data) is int:
|
||||
yield data
|
||||
|
||||
|
||||
def main():
|
||||
with open("input") as data_file:
|
||||
input = json.load(data_file)
|
||||
|
||||
sum = 0
|
||||
for value in traverse_structructure(input):
|
||||
if value is not None:
|
||||
sum += value
|
||||
|
||||
print sum
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
56
13/input
Normal file
56
13/input
Normal file
@ -0,0 +1,56 @@
|
||||
Alice would gain 54 happiness units by sitting next to Bob.
|
||||
Alice would lose 81 happiness units by sitting next to Carol.
|
||||
Alice would lose 42 happiness units by sitting next to David.
|
||||
Alice would gain 89 happiness units by sitting next to Eric.
|
||||
Alice would lose 89 happiness units by sitting next to Frank.
|
||||
Alice would gain 97 happiness units by sitting next to George.
|
||||
Alice would lose 94 happiness units by sitting next to Mallory.
|
||||
Bob would gain 3 happiness units by sitting next to Alice.
|
||||
Bob would lose 70 happiness units by sitting next to Carol.
|
||||
Bob would lose 31 happiness units by sitting next to David.
|
||||
Bob would gain 72 happiness units by sitting next to Eric.
|
||||
Bob would lose 25 happiness units by sitting next to Frank.
|
||||
Bob would lose 95 happiness units by sitting next to George.
|
||||
Bob would gain 11 happiness units by sitting next to Mallory.
|
||||
Carol would lose 83 happiness units by sitting next to Alice.
|
||||
Carol would gain 8 happiness units by sitting next to Bob.
|
||||
Carol would gain 35 happiness units by sitting next to David.
|
||||
Carol would gain 10 happiness units by sitting next to Eric.
|
||||
Carol would gain 61 happiness units by sitting next to Frank.
|
||||
Carol would gain 10 happiness units by sitting next to George.
|
||||
Carol would gain 29 happiness units by sitting next to Mallory.
|
||||
David would gain 67 happiness units by sitting next to Alice.
|
||||
David would gain 25 happiness units by sitting next to Bob.
|
||||
David would gain 48 happiness units by sitting next to Carol.
|
||||
David would lose 65 happiness units by sitting next to Eric.
|
||||
David would gain 8 happiness units by sitting next to Frank.
|
||||
David would gain 84 happiness units by sitting next to George.
|
||||
David would gain 9 happiness units by sitting next to Mallory.
|
||||
Eric would lose 51 happiness units by sitting next to Alice.
|
||||
Eric would lose 39 happiness units by sitting next to Bob.
|
||||
Eric would gain 84 happiness units by sitting next to Carol.
|
||||
Eric would lose 98 happiness units by sitting next to David.
|
||||
Eric would lose 20 happiness units by sitting next to Frank.
|
||||
Eric would lose 6 happiness units by sitting next to George.
|
||||
Eric would gain 60 happiness units by sitting next to Mallory.
|
||||
Frank would gain 51 happiness units by sitting next to Alice.
|
||||
Frank would gain 79 happiness units by sitting next to Bob.
|
||||
Frank would gain 88 happiness units by sitting next to Carol.
|
||||
Frank would gain 33 happiness units by sitting next to David.
|
||||
Frank would gain 43 happiness units by sitting next to Eric.
|
||||
Frank would gain 77 happiness units by sitting next to George.
|
||||
Frank would lose 3 happiness units by sitting next to Mallory.
|
||||
George would lose 14 happiness units by sitting next to Alice.
|
||||
George would lose 12 happiness units by sitting next to Bob.
|
||||
George would lose 52 happiness units by sitting next to Carol.
|
||||
George would gain 14 happiness units by sitting next to David.
|
||||
George would lose 62 happiness units by sitting next to Eric.
|
||||
George would lose 18 happiness units by sitting next to Frank.
|
||||
George would lose 17 happiness units by sitting next to Mallory.
|
||||
Mallory would lose 36 happiness units by sitting next to Alice.
|
||||
Mallory would gain 76 happiness units by sitting next to Bob.
|
||||
Mallory would lose 34 happiness units by sitting next to Carol.
|
||||
Mallory would gain 37 happiness units by sitting next to David.
|
||||
Mallory would gain 40 happiness units by sitting next to Eric.
|
||||
Mallory would gain 18 happiness units by sitting next to Frank.
|
||||
Mallory would gain 7 happiness units by sitting next to George.
|
12
13/input1
Normal file
12
13/input1
Normal file
@ -0,0 +1,12 @@
|
||||
Alice would gain 54 happiness units by sitting next to Bob.
|
||||
Alice would lose 79 happiness units by sitting next to Carol.
|
||||
Alice would lose 2 happiness units by sitting next to David.
|
||||
Bob would gain 83 happiness units by sitting next to Alice.
|
||||
Bob would lose 7 happiness units by sitting next to Carol.
|
||||
Bob would lose 63 happiness units by sitting next to David.
|
||||
Carol would lose 62 happiness units by sitting next to Alice.
|
||||
Carol would gain 60 happiness units by sitting next to Bob.
|
||||
Carol would gain 55 happiness units by sitting next to David.
|
||||
David would gain 46 happiness units by sitting next to Alice.
|
||||
David would lose 7 happiness units by sitting next to Bob.
|
||||
David would gain 41 happiness units by sitting next to Carol.
|
77
13/part1.py
Normal file
77
13/part1.py
Normal file
@ -0,0 +1,77 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
import re
|
||||
|
||||
RE_HAPPY = re.compile(r'^(.*) would (gain|lose) (\d+) happiness units by sitting next to (.*).')
|
||||
|
||||
|
||||
class Person:
|
||||
|
||||
def __init__(self, name):
|
||||
self.name = name
|
||||
self.happiness = dict()
|
||||
|
||||
def addNeighborHappyness(self, name, value):
|
||||
self.happiness[name] = value
|
||||
|
||||
|
||||
def read_file(filename):
|
||||
file = open(filename, 'r')
|
||||
while True:
|
||||
line = file.readline()
|
||||
if not line:
|
||||
break
|
||||
yield line
|
||||
|
||||
|
||||
def getNeighborHappyness(persons, p1, p2):
|
||||
h1 = persons[p1].happiness[p2]
|
||||
h2 = persons[p2].happiness[p1]
|
||||
return h1 + h2
|
||||
|
||||
def computeHappiness(personList, personSitting, happyness):
|
||||
# empty list
|
||||
if len(personSitting) == 0:
|
||||
personSitting.insert(0, personList.keys()[0])
|
||||
computeHappiness(personList, personSitting, happyness)
|
||||
personSitting.pop(0)
|
||||
return
|
||||
|
||||
# full list
|
||||
if len(personList.keys()) == len(personSitting):
|
||||
p1 = personSitting[0]
|
||||
p2 = personSitting[len(personSitting)-1]
|
||||
happyness += getNeighborHappyness(personList, p1, p2)
|
||||
print "%010d %s" % (happyness, ", ".join(personSitting))
|
||||
happyness -= getNeighborHappyness(personList, p1, p2)
|
||||
return
|
||||
|
||||
firstPerson = personSitting[0]
|
||||
for neighbor in personList[firstPerson].happiness.keys():
|
||||
if neighbor in personSitting:
|
||||
continue
|
||||
personSitting.insert(0, neighbor)
|
||||
happyness += getNeighborHappyness(personList, firstPerson, neighbor)
|
||||
computeHappiness(personList, personSitting, happyness)
|
||||
personSitting.pop(0)
|
||||
happyness -= getNeighborHappyness(personList, firstPerson, neighbor)
|
||||
|
||||
|
||||
def main():
|
||||
persons = dict()
|
||||
for line in read_file('input'):
|
||||
match = re.search(RE_HAPPY, line)
|
||||
if not match:
|
||||
print "wrong operation syntax"
|
||||
if match.group(1) not in persons:
|
||||
persons[match.group(1)] = Person(match.group(1))
|
||||
happynnes = int(match.group(3))
|
||||
if match.group(2) == "lose":
|
||||
happynnes = happynnes * -1
|
||||
persons[match.group(1)].addNeighborHappyness(match.group(4), happynnes)
|
||||
|
||||
computeHappiness(persons, [], 0)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
83
13/part2.py
Normal file
83
13/part2.py
Normal file
@ -0,0 +1,83 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
import re
|
||||
|
||||
RE_HAPPY = re.compile(r'^(.*) would (gain|lose) (\d+) happiness units by sitting next to (.*).')
|
||||
|
||||
|
||||
class Person:
|
||||
|
||||
def __init__(self, name):
|
||||
self.name = name
|
||||
self.happiness = dict()
|
||||
|
||||
def addNeighborHappyness(self, name, value):
|
||||
self.happiness[name] = value
|
||||
|
||||
|
||||
def read_file(filename):
|
||||
file = open(filename, 'r')
|
||||
while True:
|
||||
line = file.readline()
|
||||
if not line:
|
||||
break
|
||||
yield line
|
||||
|
||||
|
||||
def getNeighborHappyness(persons, p1, p2):
|
||||
h1 = persons[p1].happiness[p2]
|
||||
h2 = persons[p2].happiness[p1]
|
||||
return h1 + h2
|
||||
|
||||
def computeHappiness(personList, personSitting, happyness):
|
||||
# empty list
|
||||
if len(personSitting) == 0:
|
||||
personSitting.insert(0, personList.keys()[0])
|
||||
computeHappiness(personList, personSitting, happyness)
|
||||
personSitting.pop(0)
|
||||
return
|
||||
|
||||
# full list
|
||||
if len(personList.keys()) == len(personSitting):
|
||||
p1 = personSitting[0]
|
||||
p2 = personSitting[len(personSitting)-1]
|
||||
happyness += getNeighborHappyness(personList, p1, p2)
|
||||
print "%010d %s" % (happyness, ", ".join(personSitting))
|
||||
happyness -= getNeighborHappyness(personList, p1, p2)
|
||||
return
|
||||
|
||||
firstPerson = personSitting[0]
|
||||
for neighbor in personList[firstPerson].happiness.keys():
|
||||
if neighbor in personSitting:
|
||||
continue
|
||||
personSitting.insert(0, neighbor)
|
||||
happyness += getNeighborHappyness(personList, firstPerson, neighbor)
|
||||
computeHappiness(personList, personSitting, happyness)
|
||||
personSitting.pop(0)
|
||||
happyness -= getNeighborHappyness(personList, firstPerson, neighbor)
|
||||
|
||||
|
||||
def main():
|
||||
persons = dict()
|
||||
for line in read_file('input'):
|
||||
match = re.search(RE_HAPPY, line)
|
||||
if not match:
|
||||
print "wrong operation syntax"
|
||||
if match.group(1) not in persons:
|
||||
persons[match.group(1)] = Person(match.group(1))
|
||||
happynnes = int(match.group(3))
|
||||
if match.group(2) == "lose":
|
||||
happynnes = happynnes * -1
|
||||
persons[match.group(1)].addNeighborHappyness(match.group(4), happynnes)
|
||||
|
||||
me = Person('me')
|
||||
for person in persons.keys():
|
||||
persons[person].addNeighborHappyness('me', 0)
|
||||
me.addNeighborHappyness(person, 0)
|
||||
persons['me'] = me
|
||||
|
||||
computeHappiness(persons, [], 0)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
9
14/input
Normal file
9
14/input
Normal file
@ -0,0 +1,9 @@
|
||||
Rudolph can fly 22 km/s for 8 seconds, but then must rest for 165 seconds.
|
||||
Cupid can fly 8 km/s for 17 seconds, but then must rest for 114 seconds.
|
||||
Prancer can fly 18 km/s for 6 seconds, but then must rest for 103 seconds.
|
||||
Donner can fly 25 km/s for 6 seconds, but then must rest for 145 seconds.
|
||||
Dasher can fly 11 km/s for 12 seconds, but then must rest for 125 seconds.
|
||||
Comet can fly 21 km/s for 6 seconds, but then must rest for 121 seconds.
|
||||
Blitzen can fly 18 km/s for 3 seconds, but then must rest for 50 seconds.
|
||||
Vixen can fly 20 km/s for 4 seconds, but then must rest for 75 seconds.
|
||||
Dancer can fly 7 km/s for 20 seconds, but then must rest for 119 seconds.
|
2
14/input1
Normal file
2
14/input1
Normal file
@ -0,0 +1,2 @@
|
||||
Comet can fly 14 km/s for 10 seconds, but then must rest for 127 seconds.
|
||||
Dancer can fly 16 km/s for 11 seconds, but then must rest for 162 seconds.
|
37
14/part1.py
Normal file
37
14/part1.py
Normal file
@ -0,0 +1,37 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
import re
|
||||
|
||||
RE_SPEED_INFO = re.compile(r'^(.*) can fly (\d+) km/s for (\d+) seconds, but then must rest for (\d+) seconds.$')
|
||||
|
||||
|
||||
def read_file(filename):
|
||||
file = open(filename, 'r')
|
||||
while True:
|
||||
line = file.readline()
|
||||
if not line:
|
||||
break
|
||||
yield line
|
||||
|
||||
def calculateDistance(time, speed, speedTime, restTime):
|
||||
|
||||
distance = 0
|
||||
cycleTime = speedTime + restTime
|
||||
cycles = int(time/cycleTime)
|
||||
distance = distance + cycles*speed*speedTime
|
||||
|
||||
distance += min(speedTime, time % cycleTime)*speed
|
||||
return distance
|
||||
|
||||
|
||||
def main():
|
||||
time = 2503
|
||||
for line in read_file('input'):
|
||||
match = re.search(RE_SPEED_INFO, line)
|
||||
if not match:
|
||||
print "wrong operation syntax"
|
||||
distance = calculateDistance(time, int(match.group(2)), int(match.group(3)), int(match.group(4)))
|
||||
print "%010d %s" % (distance, match.group(1))
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
68
14/part2.py
Normal file
68
14/part2.py
Normal file
@ -0,0 +1,68 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
import re
|
||||
|
||||
RE_SPEED_INFO = re.compile(r'^(.*) can fly (\d+) km/s for (\d+) seconds, but then must rest for (\d+) seconds.$')
|
||||
|
||||
class Reindeer:
|
||||
|
||||
def __init__(self, name):
|
||||
self.name = name
|
||||
self.speed = None
|
||||
self.speedTime = None
|
||||
self.restTime = None
|
||||
self.points = 0
|
||||
|
||||
def addPoint(self):
|
||||
self.points += 1
|
||||
|
||||
def calculateDistance(self, time):
|
||||
|
||||
distance = 0
|
||||
cycleTime = self.speedTime + self.restTime
|
||||
cycles = int(time/cycleTime)
|
||||
distance = distance + cycles*self.speed*self.speedTime
|
||||
|
||||
distance += min(self.speedTime, time % cycleTime)*self.speed
|
||||
return distance
|
||||
|
||||
|
||||
def read_file(filename):
|
||||
file = open(filename, 'r')
|
||||
while True:
|
||||
line = file.readline()
|
||||
if not line:
|
||||
break
|
||||
yield line
|
||||
|
||||
|
||||
def main():
|
||||
time = 2503
|
||||
reindeers = dict()
|
||||
distance = dict()
|
||||
|
||||
for line in read_file('input'):
|
||||
match = re.search(RE_SPEED_INFO, line)
|
||||
if not match:
|
||||
print "wrong operation syntax"
|
||||
reindeers[match.group(1)] = Reindeer(match.group(1))
|
||||
reindeers[match.group(1)].speed = int(match.group(2))
|
||||
reindeers[match.group(1)].speedTime = int(match.group(3))
|
||||
reindeers[match.group(1)].restTime = int(match.group(4))
|
||||
distance[match.group(1)] = 0
|
||||
|
||||
for t in range(2503):
|
||||
maxDistance = 0
|
||||
for r,v in reindeers.iteritems():
|
||||
distance[r] = v.calculateDistance(t+1)
|
||||
maxDistance = max(maxDistance, distance[r])
|
||||
for r,v in distance.iteritems():
|
||||
if v == maxDistance:
|
||||
reindeers[r].addPoint()
|
||||
|
||||
|
||||
for r,v in reindeers.iteritems():
|
||||
print "%010d %s" % (v.points, r)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
4
15/input
Normal file
4
15/input
Normal file
@ -0,0 +1,4 @@
|
||||
Sprinkles: capacity 5, durability -1, flavor 0, texture 0, calories 5
|
||||
PeanutButter: capacity -1, durability 3, flavor 0, texture 0, calories 1
|
||||
Frosting: capacity 0, durability -1, flavor 4, texture 0, calories 6
|
||||
Sugar: capacity -1, durability 0, flavor 0, texture 2, calories 8
|
2
15/input1
Normal file
2
15/input1
Normal file
@ -0,0 +1,2 @@
|
||||
Butterscotch: capacity -1, durability -2, flavor 6, texture 3, calories 8
|
||||
Cinnamon: capacity 2, durability 3, flavor -2, texture -1, calories 3
|
82
15/part1.py
Normal file
82
15/part1.py
Normal file
@ -0,0 +1,82 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
import re
|
||||
|
||||
RE_INGRADIENT_INFO = re.compile(r'^(.*): capacity (-?\d+), durability (-?\d+), flavor (-?\d+), texture (-?\d+), calories (-?\d+)$')
|
||||
|
||||
|
||||
class Ingredient:
|
||||
|
||||
def __init__(self, name):
|
||||
self.name = name
|
||||
self.capacity = 0
|
||||
self.durability = 0
|
||||
self.flavor = 0
|
||||
self.texture = 0
|
||||
self.calories = 0
|
||||
|
||||
|
||||
def read_file(filename):
|
||||
file = open(filename, 'r')
|
||||
while True:
|
||||
line = file.readline()
|
||||
if not line:
|
||||
break
|
||||
yield line
|
||||
|
||||
|
||||
def split_spoons(minCount, maxCount, pos, spoons):
|
||||
if pos == len(spoons):
|
||||
if sum(spoons) == maxCount:
|
||||
yield spoons
|
||||
return
|
||||
|
||||
for x in range(minCount, maxCount+1):
|
||||
spoons[pos] = x
|
||||
for s in split_spoons(minCount, maxCount, pos+1, spoons):
|
||||
yield s
|
||||
spoons[pos] = minCount
|
||||
|
||||
|
||||
def calculate_score(split, ingrediens):
|
||||
capacity = 0
|
||||
durability = 0
|
||||
flavor = 0
|
||||
texture = 0
|
||||
|
||||
for x in range(len(split)):
|
||||
capacity += split[x]*ingrediens[x].capacity
|
||||
durability += split[x]*ingrediens[x].durability
|
||||
flavor += split[x]*ingrediens[x].flavor
|
||||
texture += split[x]*ingrediens[x].texture
|
||||
|
||||
capacity = max(0, capacity)
|
||||
durability = max(0, durability)
|
||||
flavor = max(0, flavor)
|
||||
texture = max(0, texture)
|
||||
|
||||
return capacity*durability*flavor*texture
|
||||
|
||||
|
||||
def main():
|
||||
ingrediens = []
|
||||
spoons = []
|
||||
for line in read_file('input'):
|
||||
match = re.search(RE_INGRADIENT_INFO, line)
|
||||
if not match:
|
||||
print "wrong operation syntax"
|
||||
i = Ingredient(match.group(1))
|
||||
i.capacity = int(match.group(2))
|
||||
i.durability = int(match.group(3))
|
||||
i.flavor = int(match.group(4))
|
||||
i.texture = int(match.group(5))
|
||||
i.calories = int(match.group(6))
|
||||
ingrediens.append(i)
|
||||
spoons.append(0)
|
||||
|
||||
for split in split_spoons(0, 100, 0, spoons):
|
||||
score = calculate_score(split, ingrediens)
|
||||
print score
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
84
15/part2.py
Normal file
84
15/part2.py
Normal file
@ -0,0 +1,84 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
import re
|
||||
|
||||
RE_INGRADIENT_INFO = re.compile(r'^(.*): capacity (-?\d+), durability (-?\d+), flavor (-?\d+), texture (-?\d+), calories (-?\d+)$')
|
||||
|
||||
|
||||
class Ingredient:
|
||||
|
||||
def __init__(self, name):
|
||||
self.name = name
|
||||
self.capacity = 0
|
||||
self.durability = 0
|
||||
self.flavor = 0
|
||||
self.texture = 0
|
||||
self.calories = 0
|
||||
|
||||
|
||||
def read_file(filename):
|
||||
file = open(filename, 'r')
|
||||
while True:
|
||||
line = file.readline()
|
||||
if not line:
|
||||
break
|
||||
yield line
|
||||
|
||||
|
||||
def split_spoons(minCount, maxCount, pos, spoons):
|
||||
if pos == len(spoons):
|
||||
if sum(spoons) == maxCount:
|
||||
yield spoons
|
||||
return
|
||||
|
||||
for x in range(minCount, maxCount+1):
|
||||
spoons[pos] = x
|
||||
for s in split_spoons(minCount, maxCount, pos+1, spoons):
|
||||
yield s
|
||||
spoons[pos] = minCount
|
||||
|
||||
|
||||
def calculate_score(split, ingrediens):
|
||||
capacity = 0
|
||||
durability = 0
|
||||
flavor = 0
|
||||
texture = 0
|
||||
calories = 0
|
||||
|
||||
for x in range(len(split)):
|
||||
capacity += split[x]*ingrediens[x].capacity
|
||||
durability += split[x]*ingrediens[x].durability
|
||||
flavor += split[x]*ingrediens[x].flavor
|
||||
texture += split[x]*ingrediens[x].texture
|
||||
calories += split[x]*ingrediens[x].calories
|
||||
|
||||
capacity = max(0, capacity)
|
||||
durability = max(0, durability)
|
||||
flavor = max(0, flavor)
|
||||
texture = max(0, texture)
|
||||
|
||||
return (capacity*durability*flavor*texture, calories)
|
||||
|
||||
|
||||
def main():
|
||||
ingrediens = []
|
||||
spoons = []
|
||||
for line in read_file('input'):
|
||||
match = re.search(RE_INGRADIENT_INFO, line)
|
||||
if not match:
|
||||
print "wrong operation syntax"
|
||||
i = Ingredient(match.group(1))
|
||||
i.capacity = int(match.group(2))
|
||||
i.durability = int(match.group(3))
|
||||
i.flavor = int(match.group(4))
|
||||
i.texture = int(match.group(5))
|
||||
i.calories = int(match.group(6))
|
||||
ingrediens.append(i)
|
||||
spoons.append(0)
|
||||
|
||||
for split in split_spoons(0, 100, 0, spoons):
|
||||
(score, calories) = calculate_score(split, ingrediens)
|
||||
print "%d %d" % (score, calories)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
499
16/input
Normal file
499
16/input
Normal file
@ -0,0 +1,499 @@
|
||||
Sue 1: goldfish: 9, cars: 0, samoyeds: 9
|
||||
Sue 2: perfumes: 5, trees: 8, goldfish: 8
|
||||
Sue 3: pomeranians: 2, akitas: 1, trees: 5
|
||||
Sue 4: goldfish: 10, akitas: 2, perfumes: 9
|
||||
Sue 5: cars: 5, perfumes: 6, akitas: 9
|
||||
Sue 6: goldfish: 10, cats: 9, cars: 8
|
||||
Sue 7: trees: 2, samoyeds: 7, goldfish: 10
|
||||
Sue 8: cars: 8, perfumes: 6, goldfish: 1
|
||||
Sue 9: cats: 4, pomeranians: 0, trees: 0
|
||||
Sue 10: trees: 2, children: 10, samoyeds: 10
|
||||
Sue 11: akitas: 10, perfumes: 4, vizslas: 1
|
||||
Sue 12: akitas: 1, trees: 0, goldfish: 3
|
||||
Sue 13: perfumes: 6, goldfish: 10, cars: 8
|
||||
Sue 14: cats: 8, akitas: 5, vizslas: 0
|
||||
Sue 15: cars: 8, trees: 3, samoyeds: 5
|
||||
Sue 16: vizslas: 6, cats: 6, pomeranians: 10
|
||||
Sue 17: akitas: 6, cats: 2, perfumes: 9
|
||||
Sue 18: children: 9, goldfish: 2, akitas: 10
|
||||
Sue 19: trees: 3, perfumes: 0, goldfish: 6
|
||||
Sue 20: vizslas: 3, akitas: 0, trees: 1
|
||||
Sue 21: vizslas: 3, cars: 7, akitas: 3
|
||||
Sue 22: perfumes: 7, children: 1, pomeranians: 7
|
||||
Sue 23: trees: 10, cars: 9, akitas: 10
|
||||
Sue 24: akitas: 5, goldfish: 6, vizslas: 6
|
||||
Sue 25: samoyeds: 3, trees: 8, vizslas: 5
|
||||
Sue 26: vizslas: 4, pomeranians: 2, trees: 1
|
||||
Sue 27: cars: 9, goldfish: 2, trees: 4
|
||||
Sue 28: vizslas: 6, goldfish: 10, perfumes: 7
|
||||
Sue 29: vizslas: 6, pomeranians: 3, akitas: 6
|
||||
Sue 30: trees: 0, samoyeds: 5, akitas: 9
|
||||
Sue 31: vizslas: 1, perfumes: 0, trees: 6
|
||||
Sue 32: cars: 7, vizslas: 1, children: 10
|
||||
Sue 33: vizslas: 1, cars: 1, perfumes: 7
|
||||
Sue 34: vizslas: 9, trees: 10, akitas: 9
|
||||
Sue 35: akitas: 3, vizslas: 5, cars: 10
|
||||
Sue 36: cats: 3, children: 9, samoyeds: 3
|
||||
Sue 37: vizslas: 5, pomeranians: 7, cars: 6
|
||||
Sue 38: cars: 10, akitas: 5, vizslas: 8
|
||||
Sue 39: akitas: 5, trees: 9, children: 2
|
||||
Sue 40: vizslas: 0, cats: 7, akitas: 0
|
||||
Sue 41: cars: 9, trees: 10, perfumes: 8
|
||||
Sue 42: akitas: 4, trees: 2, goldfish: 3
|
||||
Sue 43: goldfish: 1, cats: 1, akitas: 8
|
||||
Sue 44: goldfish: 8, akitas: 9, vizslas: 4
|
||||
Sue 45: perfumes: 3, goldfish: 4, trees: 0
|
||||
Sue 46: trees: 7, perfumes: 1, goldfish: 8
|
||||
Sue 47: pomeranians: 10, cars: 7, trees: 2
|
||||
Sue 48: trees: 2, akitas: 1, cars: 4
|
||||
Sue 49: goldfish: 5, perfumes: 7, akitas: 8
|
||||
Sue 50: akitas: 9, vizslas: 9, trees: 2
|
||||
Sue 51: cars: 0, samoyeds: 0, vizslas: 8
|
||||
Sue 52: trees: 0, perfumes: 6, pomeranians: 4
|
||||
Sue 53: vizslas: 1, cats: 6, akitas: 3
|
||||
Sue 54: samoyeds: 8, akitas: 1, vizslas: 4
|
||||
Sue 55: goldfish: 10, perfumes: 2, pomeranians: 10
|
||||
Sue 56: trees: 9, perfumes: 3, goldfish: 5
|
||||
Sue 57: akitas: 3, perfumes: 0, cats: 2
|
||||
Sue 58: perfumes: 4, vizslas: 4, cars: 8
|
||||
Sue 59: goldfish: 7, children: 5, pomeranians: 8
|
||||
Sue 60: cars: 1, trees: 1, perfumes: 10
|
||||
Sue 61: trees: 4, samoyeds: 4, cars: 6
|
||||
Sue 62: akitas: 10, trees: 2, vizslas: 6
|
||||
Sue 63: goldfish: 3, perfumes: 7, vizslas: 10
|
||||
Sue 64: pomeranians: 5, children: 10, cars: 0
|
||||
Sue 65: vizslas: 10, cars: 8, perfumes: 3
|
||||
Sue 66: children: 5, vizslas: 4, akitas: 10
|
||||
Sue 67: children: 6, perfumes: 7, cars: 3
|
||||
Sue 68: goldfish: 8, cars: 6, children: 1
|
||||
Sue 69: vizslas: 5, perfumes: 3, cars: 9
|
||||
Sue 70: goldfish: 0, cats: 6, perfumes: 0
|
||||
Sue 71: trees: 2, samoyeds: 3, cars: 1
|
||||
Sue 72: cats: 3, akitas: 8, vizslas: 7
|
||||
Sue 73: akitas: 3, vizslas: 2, goldfish: 6
|
||||
Sue 74: pomeranians: 10, samoyeds: 9, cats: 8
|
||||
Sue 75: vizslas: 7, cars: 7, akitas: 10
|
||||
Sue 76: children: 3, cats: 6, vizslas: 3
|
||||
Sue 77: goldfish: 7, pomeranians: 10, trees: 0
|
||||
Sue 78: vizslas: 9, children: 7, trees: 10
|
||||
Sue 79: trees: 6, pomeranians: 8, samoyeds: 1
|
||||
Sue 80: vizslas: 5, children: 6, pomeranians: 5
|
||||
Sue 81: cars: 9, vizslas: 9, akitas: 9
|
||||
Sue 82: vizslas: 3, cars: 8, akitas: 1
|
||||
Sue 83: vizslas: 4, trees: 2, cats: 1
|
||||
Sue 84: children: 3, akitas: 0, vizslas: 1
|
||||
Sue 85: cats: 6, vizslas: 5, akitas: 2
|
||||
Sue 86: cars: 3, akitas: 7, goldfish: 8
|
||||
Sue 87: samoyeds: 8, vizslas: 3, goldfish: 8
|
||||
Sue 88: vizslas: 4, children: 0, cats: 7
|
||||
Sue 89: goldfish: 9, pomeranians: 10, samoyeds: 0
|
||||
Sue 90: trees: 6, akitas: 3, cars: 7
|
||||
Sue 91: samoyeds: 3, akitas: 7, perfumes: 10
|
||||
Sue 92: cars: 7, pomeranians: 10, trees: 2
|
||||
Sue 93: samoyeds: 1, children: 3, cars: 3
|
||||
Sue 94: samoyeds: 8, akitas: 7, vizslas: 0
|
||||
Sue 95: goldfish: 7, children: 2, cars: 6
|
||||
Sue 96: cars: 3, perfumes: 9, akitas: 10
|
||||
Sue 97: akitas: 9, cars: 10, vizslas: 10
|
||||
Sue 98: trees: 4, goldfish: 8, pomeranians: 7
|
||||
Sue 99: samoyeds: 6, pomeranians: 0, vizslas: 7
|
||||
Sue 100: akitas: 7, perfumes: 8, vizslas: 3
|
||||
Sue 101: cars: 5, perfumes: 1, trees: 0
|
||||
Sue 102: akitas: 6, pomeranians: 10, trees: 0
|
||||
Sue 103: trees: 3, perfumes: 5, cats: 9
|
||||
Sue 104: goldfish: 10, perfumes: 8, akitas: 0
|
||||
Sue 105: goldfish: 6, vizslas: 5, trees: 2
|
||||
Sue 106: pomeranians: 9, samoyeds: 10, perfumes: 10
|
||||
Sue 107: cars: 8, vizslas: 4, akitas: 2
|
||||
Sue 108: cats: 0, goldfish: 7, trees: 0
|
||||
Sue 109: cars: 3, pomeranians: 6, trees: 2
|
||||
Sue 110: perfumes: 4, goldfish: 5, akitas: 10
|
||||
Sue 111: cars: 3, perfumes: 4, pomeranians: 4
|
||||
Sue 112: cats: 2, goldfish: 10, akitas: 0
|
||||
Sue 113: cats: 10, children: 0, trees: 1
|
||||
Sue 114: akitas: 10, vizslas: 3, goldfish: 0
|
||||
Sue 115: samoyeds: 3, goldfish: 6, vizslas: 1
|
||||
Sue 116: cars: 3, perfumes: 5, trees: 6
|
||||
Sue 117: akitas: 9, samoyeds: 8, goldfish: 8
|
||||
Sue 118: pomeranians: 5, perfumes: 10, trees: 1
|
||||
Sue 119: goldfish: 6, perfumes: 3, children: 1
|
||||
Sue 120: trees: 1, children: 3, pomeranians: 6
|
||||
Sue 121: akitas: 7, cars: 10, vizslas: 9
|
||||
Sue 122: trees: 4, akitas: 8, samoyeds: 10
|
||||
Sue 123: cats: 4, cars: 8, vizslas: 9
|
||||
Sue 124: cars: 10, children: 1, trees: 0
|
||||
Sue 125: goldfish: 5, pomeranians: 5, trees: 2
|
||||
Sue 126: goldfish: 1, vizslas: 8, akitas: 10
|
||||
Sue 127: vizslas: 4, cars: 9, akitas: 1
|
||||
Sue 128: goldfish: 8, perfumes: 3, cars: 9
|
||||
Sue 129: goldfish: 9, pomeranians: 9, perfumes: 1
|
||||
Sue 130: trees: 1, vizslas: 9, perfumes: 3
|
||||
Sue 131: children: 6, trees: 8, vizslas: 8
|
||||
Sue 132: cars: 1, vizslas: 3, children: 7
|
||||
Sue 133: cars: 7, children: 1, perfumes: 6
|
||||
Sue 134: trees: 8, vizslas: 3, samoyeds: 2
|
||||
Sue 135: cats: 9, perfumes: 4, pomeranians: 7
|
||||
Sue 136: perfumes: 0, akitas: 8, vizslas: 6
|
||||
Sue 137: goldfish: 5, trees: 0, vizslas: 7
|
||||
Sue 138: trees: 1, perfumes: 2, cars: 10
|
||||
Sue 139: samoyeds: 8, goldfish: 8, trees: 0
|
||||
Sue 140: vizslas: 10, perfumes: 9, goldfish: 0
|
||||
Sue 141: perfumes: 7, cars: 9, cats: 5
|
||||
Sue 142: trees: 2, samoyeds: 2, cars: 0
|
||||
Sue 143: cars: 1, perfumes: 1, akitas: 1
|
||||
Sue 144: vizslas: 9, cars: 7, pomeranians: 10
|
||||
Sue 145: pomeranians: 2, samoyeds: 7, children: 7
|
||||
Sue 146: vizslas: 6, cars: 9, goldfish: 7
|
||||
Sue 147: trees: 2, vizslas: 1, cats: 9
|
||||
Sue 148: perfumes: 9, trees: 4, pomeranians: 5
|
||||
Sue 149: samoyeds: 8, children: 1, vizslas: 9
|
||||
Sue 150: cats: 3, trees: 2, vizslas: 4
|
||||
Sue 151: goldfish: 7, akitas: 10, trees: 3
|
||||
Sue 152: perfumes: 4, vizslas: 7, cars: 4
|
||||
Sue 153: pomeranians: 4, akitas: 0, vizslas: 3
|
||||
Sue 154: samoyeds: 8, trees: 2, vizslas: 10
|
||||
Sue 155: vizslas: 7, cats: 7, pomeranians: 5
|
||||
Sue 156: goldfish: 10, pomeranians: 1, vizslas: 1
|
||||
Sue 157: cars: 6, perfumes: 7, trees: 9
|
||||
Sue 158: trees: 5, samoyeds: 9, goldfish: 3
|
||||
Sue 159: pomeranians: 4, akitas: 6, vizslas: 8
|
||||
Sue 160: goldfish: 7, children: 0, cats: 0
|
||||
Sue 161: vizslas: 5, akitas: 0, samoyeds: 2
|
||||
Sue 162: akitas: 4, children: 0, vizslas: 3
|
||||
Sue 163: samoyeds: 2, perfumes: 0, goldfish: 9
|
||||
Sue 164: cars: 9, vizslas: 8, akitas: 6
|
||||
Sue 165: samoyeds: 9, vizslas: 9, perfumes: 5
|
||||
Sue 166: cars: 5, pomeranians: 4, samoyeds: 8
|
||||
Sue 167: cars: 10, perfumes: 3, samoyeds: 6
|
||||
Sue 169: vizslas: 7, akitas: 3, samoyeds: 4
|
||||
Sue 170: cats: 2, goldfish: 0, vizslas: 4
|
||||
Sue 171: perfumes: 3, goldfish: 10, cats: 3
|
||||
Sue 172: goldfish: 7, akitas: 6, cars: 0
|
||||
Sue 173: cars: 9, goldfish: 7, akitas: 5
|
||||
Sue 174: goldfish: 6, cats: 0, vizslas: 8
|
||||
Sue 175: perfumes: 7, cats: 10, cars: 10
|
||||
Sue 176: samoyeds: 9, vizslas: 4, pomeranians: 10
|
||||
Sue 177: perfumes: 0, trees: 0, cars: 10
|
||||
Sue 178: vizslas: 6, children: 7, samoyeds: 1
|
||||
Sue 179: vizslas: 8, children: 6, trees: 0
|
||||
Sue 180: cars: 1, vizslas: 6, trees: 1
|
||||
Sue 181: vizslas: 10, perfumes: 3, cars: 1
|
||||
Sue 182: trees: 8, samoyeds: 9, cars: 7
|
||||
Sue 183: cars: 6, vizslas: 2, perfumes: 7
|
||||
Sue 184: trees: 5, samoyeds: 9, akitas: 0
|
||||
Sue 185: cars: 8, goldfish: 8, trees: 4
|
||||
Sue 186: samoyeds: 6, goldfish: 1, trees: 2
|
||||
Sue 187: perfumes: 1, trees: 2, akitas: 7
|
||||
Sue 188: samoyeds: 5, cars: 6, perfumes: 2
|
||||
Sue 189: samoyeds: 8, goldfish: 3, perfumes: 5
|
||||
Sue 190: akitas: 2, cats: 1, samoyeds: 1
|
||||
Sue 191: trees: 5, akitas: 1, goldfish: 7
|
||||
Sue 192: vizslas: 3, trees: 0, perfumes: 4
|
||||
Sue 193: cars: 3, perfumes: 4, akitas: 3
|
||||
Sue 194: perfumes: 4, vizslas: 8, children: 4
|
||||
Sue 195: vizslas: 1, samoyeds: 3, cars: 6
|
||||
Sue 196: cars: 5, perfumes: 6, vizslas: 2
|
||||
Sue 197: vizslas: 8, akitas: 8, cats: 6
|
||||
Sue 198: cars: 9, akitas: 2, pomeranians: 7
|
||||
Sue 199: cats: 9, akitas: 6, cars: 10
|
||||
Sue 200: vizslas: 10, pomeranians: 2, goldfish: 9
|
||||
Sue 201: vizslas: 9, samoyeds: 4, akitas: 3
|
||||
Sue 202: akitas: 5, cats: 2, vizslas: 0
|
||||
Sue 203: perfumes: 1, children: 3, akitas: 10
|
||||
Sue 204: trees: 4, vizslas: 7, akitas: 9
|
||||
Sue 205: trees: 8, perfumes: 9, cars: 1
|
||||
Sue 206: goldfish: 6, trees: 5, cars: 8
|
||||
Sue 207: akitas: 3, vizslas: 8, trees: 8
|
||||
Sue 208: vizslas: 4, perfumes: 7, akitas: 10
|
||||
Sue 209: cars: 9, perfumes: 7, goldfish: 9
|
||||
Sue 210: vizslas: 2, cats: 2, akitas: 10
|
||||
Sue 211: akitas: 1, trees: 3, cars: 2
|
||||
Sue 212: goldfish: 5, trees: 0, vizslas: 7
|
||||
Sue 213: akitas: 3, perfumes: 1, vizslas: 5
|
||||
Sue 214: perfumes: 3, pomeranians: 6, cars: 0
|
||||
Sue 215: goldfish: 1, cats: 9, cars: 3
|
||||
Sue 216: goldfish: 9, pomeranians: 6, samoyeds: 0
|
||||
Sue 217: cars: 6, trees: 2, perfumes: 2
|
||||
Sue 218: vizslas: 3, goldfish: 8, akitas: 5
|
||||
Sue 219: cats: 9, perfumes: 7, cars: 5
|
||||
Sue 220: pomeranians: 5, vizslas: 4, cats: 5
|
||||
Sue 221: trees: 0, akitas: 7, goldfish: 10
|
||||
Sue 222: akitas: 2, cars: 3, vizslas: 5
|
||||
Sue 223: goldfish: 3, perfumes: 7, akitas: 4
|
||||
Sue 224: samoyeds: 2, cars: 4, vizslas: 7
|
||||
Sue 225: trees: 5, cars: 0, perfumes: 0
|
||||
Sue 226: trees: 2, goldfish: 10, perfumes: 6
|
||||
Sue 227: cars: 8, trees: 9, akitas: 6
|
||||
Sue 228: goldfish: 10, trees: 10, perfumes: 0
|
||||
Sue 229: children: 7, samoyeds: 4, goldfish: 6
|
||||
Sue 230: vizslas: 9, perfumes: 1, children: 10
|
||||
Sue 231: vizslas: 8, trees: 5, akitas: 9
|
||||
Sue 232: akitas: 5, goldfish: 9, trees: 1
|
||||
Sue 233: vizslas: 3, trees: 2, children: 9
|
||||
Sue 234: samoyeds: 8, perfumes: 0, cats: 0
|
||||
Sue 235: perfumes: 4, vizslas: 3, akitas: 5
|
||||
Sue 236: pomeranians: 5, vizslas: 3, akitas: 9
|
||||
Sue 237: cats: 1, trees: 7, vizslas: 5
|
||||
Sue 238: children: 5, cats: 4, samoyeds: 5
|
||||
Sue 239: trees: 3, akitas: 2, goldfish: 6
|
||||
Sue 240: goldfish: 9, trees: 1, perfumes: 1
|
||||
Sue 241: cars: 2, pomeranians: 1, samoyeds: 2
|
||||
Sue 242: akitas: 2, trees: 3, cars: 4
|
||||
Sue 243: vizslas: 6, akitas: 2, samoyeds: 7
|
||||
Sue 244: trees: 0, perfumes: 5, cars: 7
|
||||
Sue 245: goldfish: 10, perfumes: 5, vizslas: 8
|
||||
Sue 246: akitas: 0, perfumes: 0, cars: 1
|
||||
Sue 247: samoyeds: 8, goldfish: 0, cars: 6
|
||||
Sue 248: perfumes: 0, children: 10, trees: 10
|
||||
Sue 249: perfumes: 6, akitas: 5, cats: 5
|
||||
Sue 250: vizslas: 7, akitas: 4, cats: 5
|
||||
Sue 251: samoyeds: 4, akitas: 1, trees: 8
|
||||
Sue 252: perfumes: 8, pomeranians: 5, cars: 1
|
||||
Sue 253: akitas: 10, trees: 4, cats: 3
|
||||
Sue 254: perfumes: 2, cats: 2, goldfish: 9
|
||||
Sue 255: cars: 4, trees: 1, akitas: 4
|
||||
Sue 256: samoyeds: 9, goldfish: 0, akitas: 9
|
||||
Sue 257: vizslas: 9, perfumes: 2, goldfish: 2
|
||||
Sue 258: perfumes: 1, cars: 9, samoyeds: 1
|
||||
Sue 259: trees: 0, goldfish: 0, samoyeds: 3
|
||||
Sue 260: perfumes: 7, cars: 1, goldfish: 0
|
||||
Sue 261: cars: 0, trees: 5, goldfish: 6
|
||||
Sue 262: akitas: 7, vizslas: 3, pomeranians: 5
|
||||
Sue 263: trees: 1, vizslas: 3, goldfish: 3
|
||||
Sue 264: akitas: 7, vizslas: 4, children: 0
|
||||
Sue 265: samoyeds: 5, trees: 0, akitas: 4
|
||||
Sue 266: perfumes: 9, goldfish: 9, cars: 8
|
||||
Sue 267: cars: 7, perfumes: 10, pomeranians: 8
|
||||
Sue 268: cars: 0, akitas: 7, perfumes: 4
|
||||
Sue 269: pomeranians: 0, cars: 9, perfumes: 10
|
||||
Sue 270: samoyeds: 10, perfumes: 10, cars: 9
|
||||
Sue 271: akitas: 2, vizslas: 8, cats: 5
|
||||
Sue 272: akitas: 3, children: 9, samoyeds: 10
|
||||
Sue 273: perfumes: 2, cars: 10, goldfish: 8
|
||||
Sue 274: cars: 3, children: 10, perfumes: 10
|
||||
Sue 275: cats: 9, akitas: 5, trees: 0
|
||||
Sue 276: akitas: 6, children: 2, vizslas: 1
|
||||
Sue 277: pomeranians: 6, trees: 10, samoyeds: 3
|
||||
Sue 278: cars: 7, perfumes: 10, trees: 1
|
||||
Sue 279: cars: 6, pomeranians: 8, trees: 2
|
||||
Sue 280: pomeranians: 9, cats: 0, perfumes: 7
|
||||
Sue 281: vizslas: 10, goldfish: 9, pomeranians: 5
|
||||
Sue 282: perfumes: 4, samoyeds: 7, cars: 9
|
||||
Sue 283: cars: 9, vizslas: 6, trees: 5
|
||||
Sue 284: cars: 7, trees: 1, vizslas: 4
|
||||
Sue 285: samoyeds: 4, goldfish: 10, cats: 4
|
||||
Sue 286: samoyeds: 0, akitas: 4, children: 5
|
||||
Sue 287: trees: 1, perfumes: 3, goldfish: 10
|
||||
Sue 288: pomeranians: 10, akitas: 3, cars: 2
|
||||
Sue 289: trees: 7, pomeranians: 4, goldfish: 10
|
||||
Sue 290: samoyeds: 10, perfumes: 0, cars: 9
|
||||
Sue 291: akitas: 0, pomeranians: 7, vizslas: 4
|
||||
Sue 292: cats: 2, vizslas: 8, goldfish: 5
|
||||
Sue 293: vizslas: 6, pomeranians: 9, perfumes: 0
|
||||
Sue 294: akitas: 6, cars: 7, vizslas: 5
|
||||
Sue 295: goldfish: 0, akitas: 9, cats: 0
|
||||
Sue 296: goldfish: 1, trees: 0, cars: 6
|
||||
Sue 297: perfumes: 6, cats: 8, pomeranians: 6
|
||||
Sue 298: cats: 0, goldfish: 6, perfumes: 2
|
||||
Sue 299: cars: 4, akitas: 1, samoyeds: 10
|
||||
Sue 300: goldfish: 9, samoyeds: 6, cats: 5
|
||||
Sue 301: cars: 0, vizslas: 7, trees: 0
|
||||
Sue 302: goldfish: 9, samoyeds: 1, children: 6
|
||||
Sue 303: cars: 6, perfumes: 7, samoyeds: 8
|
||||
Sue 304: trees: 8, goldfish: 9, children: 9
|
||||
Sue 305: perfumes: 0, cars: 5, goldfish: 4
|
||||
Sue 306: cats: 3, cars: 7, vizslas: 7
|
||||
Sue 307: pomeranians: 4, perfumes: 6, cars: 2
|
||||
Sue 308: cars: 9, akitas: 6, goldfish: 4
|
||||
Sue 309: pomeranians: 2, vizslas: 10, goldfish: 10
|
||||
Sue 310: children: 0, cats: 4, akitas: 7
|
||||
Sue 311: children: 10, akitas: 8, vizslas: 2
|
||||
Sue 312: children: 5, cars: 0, vizslas: 4
|
||||
Sue 313: perfumes: 10, trees: 3, pomeranians: 9
|
||||
Sue 314: samoyeds: 3, goldfish: 2, trees: 9
|
||||
Sue 315: cars: 2, cats: 5, pomeranians: 10
|
||||
Sue 316: cats: 6, pomeranians: 6, children: 9
|
||||
Sue 317: cats: 2, vizslas: 3, perfumes: 1
|
||||
Sue 318: akitas: 1, perfumes: 3, vizslas: 10
|
||||
Sue 319: cars: 7, perfumes: 0, trees: 0
|
||||
Sue 320: goldfish: 6, samoyeds: 6, pomeranians: 4
|
||||
Sue 321: trees: 2, goldfish: 6, children: 0
|
||||
Sue 322: goldfish: 0, trees: 2, akitas: 8
|
||||
Sue 323: pomeranians: 2, samoyeds: 9, vizslas: 1
|
||||
Sue 324: trees: 4, goldfish: 6, pomeranians: 6
|
||||
Sue 325: trees: 2, pomeranians: 3, goldfish: 1
|
||||
Sue 326: perfumes: 4, goldfish: 6, trees: 5
|
||||
Sue 327: akitas: 3, cars: 8, cats: 2
|
||||
Sue 328: cats: 6, vizslas: 0, akitas: 2
|
||||
Sue 329: perfumes: 3, goldfish: 10, akitas: 3
|
||||
Sue 330: goldfish: 3, vizslas: 1, akitas: 6
|
||||
Sue 331: perfumes: 4, trees: 1, goldfish: 5
|
||||
Sue 332: goldfish: 7, vizslas: 9, akitas: 1
|
||||
Sue 333: children: 8, cars: 8, trees: 4
|
||||
Sue 334: cars: 1, vizslas: 6, trees: 0
|
||||
Sue 335: goldfish: 2, cars: 2, akitas: 1
|
||||
Sue 336: goldfish: 5, akitas: 5, trees: 9
|
||||
Sue 337: cars: 5, vizslas: 6, goldfish: 6
|
||||
Sue 338: cats: 9, akitas: 3, goldfish: 9
|
||||
Sue 339: akitas: 3, cats: 2, children: 7
|
||||
Sue 340: goldfish: 0, pomeranians: 8, perfumes: 9
|
||||
Sue 341: trees: 0, pomeranians: 1, goldfish: 5
|
||||
Sue 342: goldfish: 10, trees: 3, vizslas: 4
|
||||
Sue 343: cats: 3, samoyeds: 1, children: 6
|
||||
Sue 344: perfumes: 3, children: 4, samoyeds: 2
|
||||
Sue 345: children: 6, trees: 2, goldfish: 1
|
||||
Sue 346: trees: 2, pomeranians: 3, goldfish: 5
|
||||
Sue 347: akitas: 10, vizslas: 7, trees: 1
|
||||
Sue 348: perfumes: 4, akitas: 2, vizslas: 7
|
||||
Sue 349: perfumes: 8, goldfish: 3, vizslas: 5
|
||||
Sue 350: trees: 4, pomeranians: 5, akitas: 10
|
||||
Sue 351: perfumes: 5, cars: 9, trees: 0
|
||||
Sue 352: akitas: 6, children: 8, trees: 10
|
||||
Sue 353: samoyeds: 7, akitas: 6, vizslas: 4
|
||||
Sue 354: children: 9, goldfish: 7, perfumes: 5
|
||||
Sue 355: trees: 1, perfumes: 4, cars: 1
|
||||
Sue 356: samoyeds: 1, perfumes: 4, pomeranians: 8
|
||||
Sue 357: trees: 7, goldfish: 10, akitas: 0
|
||||
Sue 358: akitas: 1, vizslas: 6, cars: 7
|
||||
Sue 359: vizslas: 3, goldfish: 8, trees: 4
|
||||
Sue 360: akitas: 10, vizslas: 2, trees: 3
|
||||
Sue 361: samoyeds: 6, pomeranians: 1, perfumes: 0
|
||||
Sue 362: samoyeds: 3, cars: 1, trees: 0
|
||||
Sue 363: vizslas: 0, pomeranians: 9, akitas: 4
|
||||
Sue 364: perfumes: 9, pomeranians: 8, vizslas: 9
|
||||
Sue 365: vizslas: 7, cars: 4, perfumes: 10
|
||||
Sue 366: cars: 0, samoyeds: 5, goldfish: 10
|
||||
Sue 367: children: 4, vizslas: 5, akitas: 4
|
||||
Sue 368: samoyeds: 9, perfumes: 4, vizslas: 6
|
||||
Sue 369: perfumes: 5, cars: 4, samoyeds: 5
|
||||
Sue 370: akitas: 3, vizslas: 2, perfumes: 1
|
||||
Sue 371: cars: 8, cats: 7, children: 5
|
||||
Sue 372: vizslas: 9, perfumes: 2, akitas: 10
|
||||
Sue 373: trees: 10, pomeranians: 9, goldfish: 3
|
||||
Sue 374: children: 4, cars: 10, perfumes: 2
|
||||
Sue 375: children: 7, samoyeds: 5, cats: 0
|
||||
Sue 376: akitas: 10, samoyeds: 5, vizslas: 5
|
||||
Sue 377: goldfish: 8, trees: 3, perfumes: 3
|
||||
Sue 378: goldfish: 10, vizslas: 0, perfumes: 2
|
||||
Sue 379: trees: 1, vizslas: 7, pomeranians: 4
|
||||
Sue 380: samoyeds: 8, vizslas: 3, trees: 2
|
||||
Sue 381: goldfish: 2, perfumes: 5, samoyeds: 9
|
||||
Sue 382: cats: 3, vizslas: 10, akitas: 5
|
||||
Sue 383: cars: 7, goldfish: 5, akitas: 8
|
||||
Sue 384: children: 6, goldfish: 10, trees: 1
|
||||
Sue 385: cats: 2, akitas: 6, samoyeds: 7
|
||||
Sue 386: cars: 10, children: 4, goldfish: 2
|
||||
Sue 387: cats: 0, perfumes: 5, akitas: 9
|
||||
Sue 388: pomeranians: 7, akitas: 0, samoyeds: 9
|
||||
Sue 389: trees: 0, akitas: 9, vizslas: 8
|
||||
Sue 390: cars: 0, trees: 10, perfumes: 9
|
||||
Sue 391: cats: 9, goldfish: 10, perfumes: 10
|
||||
Sue 392: cars: 3, vizslas: 6, cats: 3
|
||||
Sue 393: vizslas: 10, perfumes: 4, goldfish: 5
|
||||
Sue 394: perfumes: 4, akitas: 10, trees: 2
|
||||
Sue 395: pomeranians: 5, cars: 4, perfumes: 3
|
||||
Sue 396: pomeranians: 9, vizslas: 5, akitas: 2
|
||||
Sue 397: cars: 10, goldfish: 8, trees: 2
|
||||
Sue 398: perfumes: 7, children: 9, goldfish: 9
|
||||
Sue 399: akitas: 6, cats: 2, goldfish: 7
|
||||
Sue 400: goldfish: 9, perfumes: 0, cars: 2
|
||||
Sue 401: children: 4, vizslas: 0, trees: 2
|
||||
Sue 402: akitas: 4, cars: 8, pomeranians: 4
|
||||
Sue 403: vizslas: 8, perfumes: 7, goldfish: 1
|
||||
Sue 404: goldfish: 10, samoyeds: 7, vizslas: 3
|
||||
Sue 405: akitas: 1, vizslas: 6, perfumes: 6
|
||||
Sue 406: pomeranians: 8, goldfish: 6, cats: 3
|
||||
Sue 407: goldfish: 2, vizslas: 4, akitas: 7
|
||||
Sue 408: cars: 10, perfumes: 10, vizslas: 3
|
||||
Sue 409: vizslas: 7, pomeranians: 4, perfumes: 4
|
||||
Sue 410: goldfish: 4, vizslas: 7, trees: 5
|
||||
Sue 411: cars: 8, trees: 0, goldfish: 4
|
||||
Sue 412: cars: 8, perfumes: 5, vizslas: 4
|
||||
Sue 413: vizslas: 3, akitas: 7, samoyeds: 6
|
||||
Sue 414: trees: 0, perfumes: 6, cars: 10
|
||||
Sue 415: pomeranians: 4, trees: 1, perfumes: 6
|
||||
Sue 416: cars: 10, perfumes: 6, akitas: 2
|
||||
Sue 417: perfumes: 6, samoyeds: 0, akitas: 0
|
||||
Sue 418: children: 1, perfumes: 9, vizslas: 3
|
||||
Sue 419: goldfish: 9, samoyeds: 3, perfumes: 8
|
||||
Sue 420: goldfish: 4, cars: 10, vizslas: 7
|
||||
Sue 421: samoyeds: 7, vizslas: 7, cats: 2
|
||||
Sue 422: trees: 1, goldfish: 8, perfumes: 0
|
||||
Sue 423: cars: 3, perfumes: 2, trees: 3
|
||||
Sue 424: samoyeds: 6, vizslas: 0, akitas: 6
|
||||
Sue 425: trees: 3, akitas: 7, goldfish: 1
|
||||
Sue 426: cars: 9, trees: 1, perfumes: 0
|
||||
Sue 427: pomeranians: 0, children: 5, perfumes: 8
|
||||
Sue 428: cars: 0, perfumes: 6, children: 4
|
||||
Sue 429: akitas: 7, pomeranians: 9, cats: 6
|
||||
Sue 430: cats: 6, trees: 1, cars: 0
|
||||
Sue 431: children: 8, akitas: 5, perfumes: 9
|
||||
Sue 432: perfumes: 5, akitas: 10, trees: 9
|
||||
Sue 433: akitas: 4, perfumes: 10, vizslas: 7
|
||||
Sue 434: trees: 3, children: 10, samoyeds: 4
|
||||
Sue 435: vizslas: 5, goldfish: 2, akitas: 2
|
||||
Sue 436: samoyeds: 3, trees: 2, cars: 6
|
||||
Sue 437: children: 9, akitas: 0, pomeranians: 3
|
||||
Sue 438: perfumes: 10, akitas: 2, cars: 7
|
||||
Sue 439: perfumes: 10, samoyeds: 6, akitas: 10
|
||||
Sue 440: vizslas: 10, trees: 2, akitas: 8
|
||||
Sue 441: perfumes: 8, akitas: 2, pomeranians: 7
|
||||
Sue 442: cars: 8, trees: 3, goldfish: 6
|
||||
Sue 443: cars: 1, goldfish: 5, vizslas: 5
|
||||
Sue 444: vizslas: 2, akitas: 10, samoyeds: 4
|
||||
Sue 445: vizslas: 2, akitas: 10, perfumes: 9
|
||||
Sue 446: akitas: 3, vizslas: 8, goldfish: 1
|
||||
Sue 447: vizslas: 7, pomeranians: 5, trees: 10
|
||||
Sue 448: cats: 6, perfumes: 10, children: 6
|
||||
Sue 449: trees: 2, cars: 5, goldfish: 8
|
||||
Sue 450: trees: 0, goldfish: 6, samoyeds: 3
|
||||
Sue 451: perfumes: 0, cars: 8, trees: 1
|
||||
Sue 452: akitas: 4, trees: 8, perfumes: 9
|
||||
Sue 453: goldfish: 1, perfumes: 7, akitas: 6
|
||||
Sue 454: vizslas: 3, cars: 1, perfumes: 6
|
||||
Sue 455: trees: 1, akitas: 7, goldfish: 10
|
||||
Sue 456: samoyeds: 4, vizslas: 2, cars: 9
|
||||
Sue 457: perfumes: 10, children: 1, trees: 8
|
||||
Sue 458: perfumes: 0, vizslas: 9, cars: 8
|
||||
Sue 459: cats: 0, children: 7, trees: 3
|
||||
Sue 460: vizslas: 4, cats: 6, perfumes: 2
|
||||
Sue 461: trees: 3, children: 5, cars: 8
|
||||
Sue 462: goldfish: 7, vizslas: 7, children: 5
|
||||
Sue 463: cars: 5, akitas: 3, goldfish: 5
|
||||
Sue 464: vizslas: 0, pomeranians: 5, cars: 0
|
||||
Sue 465: goldfish: 4, akitas: 0, cats: 5
|
||||
Sue 466: cars: 5, trees: 1, goldfish: 6
|
||||
Sue 467: perfumes: 10, trees: 8, cars: 1
|
||||
Sue 468: perfumes: 4, akitas: 3, cars: 0
|
||||
Sue 469: vizslas: 3, cars: 7, pomeranians: 1
|
||||
Sue 470: perfumes: 1, vizslas: 7, akitas: 8
|
||||
Sue 471: goldfish: 10, samoyeds: 10, pomeranians: 5
|
||||
Sue 472: goldfish: 6, trees: 0, perfumes: 0
|
||||
Sue 473: goldfish: 5, vizslas: 0, children: 5
|
||||
Sue 474: cars: 3, vizslas: 7, perfumes: 10
|
||||
Sue 475: vizslas: 5, trees: 9, goldfish: 8
|
||||
Sue 476: akitas: 2, goldfish: 6, children: 7
|
||||
Sue 477: samoyeds: 0, perfumes: 1, pomeranians: 5
|
||||
Sue 478: trees: 2, goldfish: 9, vizslas: 0
|
||||
Sue 479: perfumes: 1, cars: 6, goldfish: 9
|
||||
Sue 480: pomeranians: 3, perfumes: 5, trees: 9
|
||||
Sue 481: cats: 3, akitas: 0, vizslas: 8
|
||||
Sue 482: pomeranians: 10, akitas: 8, trees: 5
|
||||
Sue 483: goldfish: 6, akitas: 10, perfumes: 2
|
||||
Sue 484: cats: 0, goldfish: 0, children: 9
|
||||
Sue 485: children: 4, akitas: 10, vizslas: 8
|
||||
Sue 486: vizslas: 3, goldfish: 9, children: 10
|
||||
Sue 487: children: 8, cats: 6, vizslas: 10
|
||||
Sue 488: cars: 7, akitas: 10, samoyeds: 5
|
||||
Sue 489: vizslas: 9, akitas: 6, trees: 2
|
||||
Sue 490: vizslas: 5, akitas: 1, children: 5
|
||||
Sue 491: vizslas: 8, goldfish: 3, perfumes: 6
|
||||
Sue 492: trees: 3, samoyeds: 1, pomeranians: 6
|
||||
Sue 493: akitas: 1, vizslas: 5, cars: 8
|
||||
Sue 494: akitas: 4, cars: 4, vizslas: 9
|
||||
Sue 495: vizslas: 1, akitas: 2, cats: 2
|
||||
Sue 496: trees: 7, vizslas: 5, akitas: 6
|
||||
Sue 497: akitas: 8, trees: 2, perfumes: 6
|
||||
Sue 498: akitas: 1, trees: 1, samoyeds: 4
|
||||
Sue 499: cars: 0, akitas: 5, vizslas: 3
|
||||
Sue 500: cats: 2, goldfish: 9, children: 8
|
51
16/part1.py
Normal file
51
16/part1.py
Normal file
@ -0,0 +1,51 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
import re
|
||||
|
||||
RE_TICKER = re.compile(r'^\s*(.*): (\d+)$')
|
||||
RE_SUE = re.compile(r'Sue (\d+): (.*)')
|
||||
|
||||
|
||||
def read_file(filename):
|
||||
file = open(filename, 'r')
|
||||
while True:
|
||||
line = file.readline()
|
||||
if not line:
|
||||
break
|
||||
yield line
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
ticker_type = dict()
|
||||
for line in read_file('ticker_type'):
|
||||
match = re.match(RE_TICKER, line)
|
||||
if not match:
|
||||
print "wrong input"
|
||||
print line
|
||||
break
|
||||
ticker_type[match.group(1)] = int(match.group(2))
|
||||
|
||||
for line in read_file('input'):
|
||||
sue = dict()
|
||||
number = None
|
||||
match = re.match(RE_SUE, line)
|
||||
if not match:
|
||||
print "wrong input"
|
||||
print line
|
||||
break
|
||||
number = match.group(1)
|
||||
for token in match.group(2).split(','):
|
||||
match1 = re.match(RE_TICKER, token)
|
||||
sue[match1.group(1)] = int(match1.group(2))
|
||||
|
||||
for k, v in ticker_type.iteritems():
|
||||
if k in sue:
|
||||
if sue[k] == v:
|
||||
del sue[k]
|
||||
|
||||
if len(sue.keys()) == 0:
|
||||
print number
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
58
16/part2.py
Normal file
58
16/part2.py
Normal file
@ -0,0 +1,58 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
import re
|
||||
|
||||
RE_TICKER = re.compile(r'^\s*(.*): (\d+)$')
|
||||
RE_SUE = re.compile(r'Sue (\d+): (.*)')
|
||||
|
||||
|
||||
def read_file(filename):
|
||||
file = open(filename, 'r')
|
||||
while True:
|
||||
line = file.readline()
|
||||
if not line:
|
||||
break
|
||||
yield line
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
ticker_type = dict()
|
||||
for line in read_file('ticker_type'):
|
||||
match = re.match(RE_TICKER, line)
|
||||
if not match:
|
||||
print "wrong input"
|
||||
print line
|
||||
break
|
||||
ticker_type[match.group(1)] = int(match.group(2))
|
||||
|
||||
for line in read_file('input'):
|
||||
sue = dict()
|
||||
number = None
|
||||
match = re.match(RE_SUE, line)
|
||||
if not match:
|
||||
print "wrong input"
|
||||
print line
|
||||
break
|
||||
number = match.group(1)
|
||||
for token in match.group(2).split(','):
|
||||
match1 = re.match(RE_TICKER, token)
|
||||
sue[match1.group(1)] = int(match1.group(2))
|
||||
|
||||
for k, v in ticker_type.iteritems():
|
||||
if k in sue:
|
||||
if k in ['cats', 'trees']:
|
||||
if sue[k] > v:
|
||||
del sue[k]
|
||||
elif k in ['pomeranians', 'goldfish']:
|
||||
if sue[k] < v:
|
||||
del sue[k]
|
||||
else:
|
||||
if sue[k] == v:
|
||||
del sue[k]
|
||||
|
||||
if len(sue.keys()) == 0:
|
||||
print number
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
10
16/ticker_type
Normal file
10
16/ticker_type
Normal file
@ -0,0 +1,10 @@
|
||||
children: 3
|
||||
cats: 7
|
||||
samoyeds: 2
|
||||
pomeranians: 3
|
||||
akitas: 0
|
||||
vizslas: 0
|
||||
goldfish: 5
|
||||
trees: 3
|
||||
cars: 2
|
||||
perfumes: 1
|
Loading…
x
Reference in New Issue
Block a user