Skip to content

Commit 905841b

Browse files
committed
Added day 2015-16 and 17
1 parent f224ed4 commit 905841b

File tree

3 files changed

+154
-1
lines changed

3 files changed

+154
-1
lines changed

2015/15-Science for Hungry People.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747

4848
ingredient, capacity, durability, flavor, texture, calories = re.match('([A-Za-z]*): capacity ([0-9-]*), durability ([0-9-]*), flavor ([0-9-]*), texture ([0-9-]*), calories ([0-9-]*)', string).groups()
4949
ingredients[ingredient] = (int(capacity), int(durability), int(flavor), int(texture), int(calories))
50-
print(ingredients)
5150

5251
combinaisons = list(combinations_with_replacement(ingredients, 100))
5352
recipe_max = 0

2015/16-Aunt Sue.py

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# -------------------------------- Input data -------------------------------- #
2+
import os
3+
4+
test_data = {}
5+
6+
7+
8+
test = 'real'
9+
input_file = os.path.join(os.path.dirname(__file__), 'Inputs', os.path.basename(__file__).replace('.py', '.txt'))
10+
test_data[test] = {"input": open(input_file, "r+").read(),
11+
"expected": ['40', '241'],
12+
}
13+
14+
# -------------------------------- Control program execution -------------------------------- #
15+
16+
case_to_test = 'real'
17+
part_to_test = 2
18+
verbose_level = 1
19+
20+
# -------------------------------- Initialize some variables -------------------------------- #
21+
22+
puzzle_input = test_data[case_to_test]['input']
23+
puzzle_expected_result = test_data[case_to_test]['expected'][part_to_test-1]
24+
puzzle_actual_result = 'Unknown'
25+
26+
27+
# -------------------------------- Actual code execution -------------------------------- #
28+
29+
conditions = """children: 3
30+
cats: 7
31+
samoyeds: 2
32+
pomeranians: 3
33+
akitas: 0
34+
vizslas: 0
35+
goldfish: 5
36+
trees: 3
37+
cars: 2
38+
perfumes: 1""".split('\n')
39+
40+
if part_to_test == 1:
41+
for string in puzzle_input.split('\n'):
42+
if string == '':
43+
continue
44+
45+
possible_Sue = True
46+
for condition in conditions:
47+
if condition + ',' in string or ', ' + condition in string:
48+
pass
49+
elif condition.split()[0] not in string:
50+
pass
51+
else:
52+
possible_Sue = False
53+
continue
54+
if possible_Sue == True:
55+
puzzle_actual_result = string.split()[1]
56+
break
57+
58+
59+
60+
else:
61+
for string in puzzle_input.split('\n'):
62+
if string == '':
63+
continue
64+
65+
_, sue_id, k1, v1, k2, v2, k3, v3 = string.split()
66+
sue_data = dict(zip((k1, k2, k3), map(int, (v1[:-1], v2[:-1], v3))))
67+
68+
possible_Sue = True
69+
for condition in conditions:
70+
key, val = condition.split()
71+
val = int(val)
72+
73+
if key not in sue_data:
74+
continue
75+
elif key in ('cats:', 'trees:'):
76+
if sue_data[key] <= val:
77+
possible_Sue = False
78+
break
79+
elif key in ('pomeranians:', 'goldfish:'):
80+
if sue_data[key] >= val:
81+
possible_Sue = False
82+
break
83+
else:
84+
if sue_data[key] != val:
85+
possible_Sue = False
86+
break
87+
88+
#print (sue_data, possible_Sue)
89+
90+
if possible_Sue == True:
91+
puzzle_actual_result = sue_id
92+
break
93+
94+
95+
# -------------------------------- Outputs / results -------------------------------- #
96+
97+
if verbose_level >= 3:
98+
print ('Input : ' + puzzle_input)
99+
print ('Expected result : ' + str(puzzle_expected_result))
100+
print ('Actual result : ' + str(puzzle_actual_result))
101+
102+
103+
104+

2015/17-No Such Thing as Too Much.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# -------------------------------- Input data -------------------------------- #
2+
import os
3+
4+
test_data = {}
5+
6+
test = 'real'
7+
input_file = os.path.join(os.path.dirname(__file__), 'Inputs', os.path.basename(__file__).replace('.py', '.txt'))
8+
test_data[test] = {"input": open(input_file, "r+").read(),
9+
"expected": ['1638', '17'],
10+
}
11+
12+
# -------------------------------- Control program execution -------------------------------- #
13+
14+
case_to_test = 'real'
15+
part_to_test = 2
16+
verbose_level = 1
17+
18+
# -------------------------------- Initialize some variables -------------------------------- #
19+
20+
puzzle_input = test_data[case_to_test]['input']
21+
puzzle_expected_result = test_data[case_to_test]['expected'][part_to_test-1]
22+
puzzle_actual_result = 'Unknown'
23+
24+
25+
# -------------------------------- Actual code execution -------------------------------- #
26+
27+
from itertools import combinations
28+
29+
containers = list(map(int, puzzle_input.split('\n')))
30+
puzzle_actual_result = 0
31+
for i in range (len(containers)):
32+
combinaisons = combinations (containers, i)
33+
34+
puzzle_actual_result += sum([1 if sum(combinaison) == 150 else 0 for combinaison in combinaisons])
35+
36+
if part_to_test == 2 and puzzle_actual_result > 0:
37+
break
38+
39+
40+
41+
# -------------------------------- Outputs / results -------------------------------- #
42+
43+
if verbose_level >= 3:
44+
print ('Input : ' + puzzle_input)
45+
print ('Expected result : ' + str(puzzle_expected_result))
46+
print ('Actual result : ' + str(puzzle_actual_result))
47+
48+
49+
50+

0 commit comments

Comments
 (0)