Skip to content

Commit 280b46c

Browse files
committed
Added days 1 to 13
1 parent f80c5a1 commit 280b46c

14 files changed

+1223
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Inputs/
2+
template.py

2015/01-Not Quite Lisp.py

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# -------------------------------- Input data -------------------------------- #
2+
import os
3+
4+
test_data = {}
5+
test = 1
6+
test_data[test] = {"input": '(())',
7+
"expected": ['0', ''],
8+
}
9+
10+
test += 1
11+
test_data[test] = {"input": '()()',
12+
"expected": ['0', ''],
13+
}
14+
15+
test += 1
16+
test_data[test] = {"input": '(((',
17+
"expected": ['3', ''],
18+
}
19+
test += 1
20+
test_data[test] = {"input": '(()(()(',
21+
"expected": ['3', ''],
22+
}
23+
24+
test += 1
25+
test_data[test] = {"input": '))(((((',
26+
"expected": ['3', ''],
27+
}
28+
29+
test += 1
30+
test_data[test] = {"input": '())',
31+
"expected": ['-1', ''],
32+
}
33+
test += 1
34+
test_data[test] = {"input": '))(',
35+
"expected": ['-1', ''],
36+
}
37+
38+
test += 1
39+
test_data[test] = {"input": ')))',
40+
"expected": ['-3', ''],
41+
}
42+
43+
test += 1
44+
test_data[test] = {"input": ')())())',
45+
"expected": ['-3', ''],
46+
}
47+
48+
test = 'real'
49+
input_file = os.path.join(os.path.dirname(__file__), 'Inputs', os.path.basename(__file__).replace('.py', '.txt'))
50+
test_data[test] = {"input": open(input_file, "r+").read(),
51+
"expected": ['232', '1783'],
52+
}
53+
54+
# -------------------------------- Control program execution -------------------------------- #
55+
case_to_test = 'real'
56+
part_to_test = 2
57+
verbose_level = 3
58+
59+
60+
# -------------------------------- Initialize some variables -------------------------------- #
61+
puzzle_input = test_data[case_to_test]['input']
62+
puzzle_expected_result = test_data[case_to_test]['expected'][part_to_test-1]
63+
puzzle_actual_result = 'Unknown'
64+
65+
66+
# -------------------------------- Actual code execution -------------------------------- #
67+
if part_to_test == 1:
68+
puzzle_actual_result = puzzle_input.count('(') - puzzle_input.count(')')
69+
70+
71+
else:
72+
count_plus = 0
73+
count_minus = 0
74+
i = 0
75+
while count_plus >= count_minus and i < len(puzzle_input):
76+
count_plus += 1 if puzzle_input[i] == '(' else 0
77+
count_minus += 1 if puzzle_input[i] == ')' else 0
78+
i += 1
79+
puzzle_actual_result = i
80+
81+
82+
83+
# -------------------------------- Outputs / results -------------------------------- #
84+
if verbose_level >= 3:
85+
print ('Input : ' + puzzle_input)
86+
print ('Expected result : ' + str(puzzle_expected_result))
87+
print ('Actual result : ' + str(puzzle_actual_result))
88+
89+
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# -------------------------------- Input data -------------------------------- #
2+
import os
3+
4+
test_data = {}
5+
6+
test = 1
7+
test_data[test] = {"input": '2x3x4',
8+
"expected": ['58', '34'],
9+
}
10+
11+
test += 1
12+
test_data[test] = {"input": '1x1x10',
13+
"expected": ['43', '14'],
14+
}
15+
16+
test = 'real'
17+
input_file = os.path.join(os.path.dirname(__file__), 'Inputs', os.path.basename(__file__).replace('.py', '.txt'))
18+
test_data[test] = {"input": open(input_file, "r+").read(),
19+
"expected": ['1598415', '3812909'],
20+
}
21+
22+
# -------------------------------- Control program execution -------------------------------- #
23+
24+
case_to_test = 'real'
25+
part_to_test = 2
26+
verbose_level = 1
27+
28+
# -------------------------------- Initialize some variables -------------------------------- #
29+
puzzle_input = test_data[case_to_test]['input']
30+
puzzle_expected_result = test_data[case_to_test]['expected'][part_to_test-1]
31+
puzzle_actual_result = 'Unknown'
32+
33+
34+
# -------------------------------- Actual code execution -------------------------------- #
35+
36+
if part_to_test == 1:
37+
all_boxes = puzzle_input.split('\n')
38+
wrapping_paper_area = 0
39+
for box in all_boxes:
40+
x, y, z = map(int, box.split('x'))
41+
wrapping_paper_area += 2*(x*z + x*y + y*z)
42+
wrapping_paper_area += min(x*z, x*y, y*z)
43+
puzzle_actual_result = wrapping_paper_area
44+
45+
else:
46+
all_boxes = puzzle_input.split('\n')
47+
ribbon_length = 0
48+
for box in all_boxes:
49+
x, y, z = map(int, box.split('x'))
50+
perimeter = [x, y, z]
51+
perimeter.sort()
52+
ribbon_length += 2*sum(perimeter[0:2]) + x * y * z
53+
puzzle_actual_result = ribbon_length
54+
55+
# -------------------------------- Outputs / results -------------------------------- #
56+
57+
if verbose_level >= 3:
58+
print ('Input : ' + puzzle_input)
59+
print ('Expected result : ' + str(puzzle_expected_result))
60+
print ('Actual result : ' + str(puzzle_actual_result))
61+
62+
63+
64+
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# -------------------------------- Input data -------------------------------- #
2+
import os
3+
4+
test_data = {}
5+
6+
test = 1
7+
test_data[test] = {"input": '>',
8+
"expected": ['2', 'Unknown'],
9+
}
10+
11+
test += 1
12+
test_data[test] = {"input": '^>v<',
13+
"expected": ['4', 'Unknown'],
14+
}
15+
16+
test += 1
17+
test_data[test] = {"input": '^v^v^v^v^v',
18+
"expected": ['2', 'Unknown'],
19+
}
20+
21+
22+
test += 1
23+
test_data[test] = {"input": '^v',
24+
"expected": ['Unknown', '3'],
25+
}
26+
27+
28+
test += 1
29+
test_data[test] = {"input": '^>v<',
30+
"expected": ['Unknown', '3'],
31+
}
32+
33+
34+
test += 1
35+
test_data[test] = {"input": '^v^v^v^v^v',
36+
"expected": ['Unknown', '11'],
37+
}
38+
39+
test = 'real'
40+
input_file = os.path.join(os.path.dirname(__file__), 'Inputs', os.path.basename(__file__).replace('.py', '.txt'))
41+
test_data[test] = {"input": open(input_file, "r+").read(),
42+
"expected": ['2592', '2360'],
43+
}
44+
45+
# -------------------------------- Control program execution -------------------------------- #
46+
47+
case_to_test = 'real'
48+
part_to_test = 2
49+
verbose_level = 1
50+
51+
# -------------------------------- Initialize some variables -------------------------------- #
52+
53+
puzzle_input = test_data[case_to_test]['input']
54+
puzzle_expected_result = test_data[case_to_test]['expected'][part_to_test-1]
55+
puzzle_actual_result = 'Unknown'
56+
57+
58+
# -------------------------------- Actual code execution -------------------------------- #
59+
60+
directions = {'v': [0, -1], '^': [0, 1], '>': [1, 0], '<': [-1, 0]}
61+
62+
if part_to_test == 1:
63+
current_position = [0, 0]
64+
visited_positions = []
65+
visited_positions.append(current_position)
66+
67+
for direction in puzzle_input:
68+
current_position = [x + x_dir for x, x_dir in zip(current_position, directions[direction])]
69+
if not current_position in visited_positions:
70+
visited_positions.append(current_position)
71+
72+
puzzle_actual_result = len(visited_positions)
73+
74+
75+
76+
else:
77+
santa_position = [0, 0]
78+
robot_position = [0, 0]
79+
visited_positions = []
80+
visited_positions.append(santa_position)
81+
82+
santa = 1
83+
for direction in puzzle_input:
84+
if santa == 1:
85+
santa_position = [x + x_dir for x, x_dir in zip(santa_position, directions[direction])]
86+
if not santa_position in visited_positions:
87+
visited_positions.append(santa_position)
88+
else:
89+
robot_position = [x + x_dir for x, x_dir in zip(robot_position, directions[direction])]
90+
if not robot_position in visited_positions:
91+
visited_positions.append(robot_position)
92+
santa = 1 - santa
93+
94+
puzzle_actual_result = len(visited_positions)
95+
96+
97+
# -------------------------------- Outputs / results -------------------------------- #
98+
99+
if verbose_level >= 3:
100+
print ('Input : ' + puzzle_input)
101+
print ('Expected result : ' + str(puzzle_expected_result))
102+
print ('Actual result : ' + str(puzzle_actual_result))
103+
104+
105+
106+

2015/04-The Ideal Stocking Stuffer.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# -------------------------------- Input data -------------------------------- #
2+
import os
3+
4+
test_data = {}
5+
6+
test = 1
7+
test_data[test] = {"input": 'abcdef',
8+
"expected": ['609043', 'Unknown'],
9+
}
10+
11+
test += 1
12+
test_data[test] = {"input": 'pqrstuv',
13+
"expected": ['1048970', 'Unknown'],
14+
}
15+
16+
test = 'real'
17+
input_file = os.path.join(os.path.dirname(__file__), 'Inputs', os.path.basename(__file__).replace('.py', '.txt'))
18+
test_data[test] = {"input": open(input_file, "r+").read(),
19+
"expected": ['254575', '1038736'],
20+
}
21+
22+
# -------------------------------- Control program execution -------------------------------- #
23+
24+
case_to_test = 'real'
25+
part_to_test = 1
26+
verbose_level = 1
27+
28+
# -------------------------------- Initialize some variables -------------------------------- #
29+
30+
puzzle_input = test_data[case_to_test]['input']
31+
puzzle_expected_result = test_data[case_to_test]['expected'][part_to_test-1]
32+
puzzle_actual_result = 'Unknown'
33+
34+
35+
# -------------------------------- Actual code execution -------------------------------- #
36+
37+
import hashlib
38+
39+
if part_to_test == 1:
40+
password = 1
41+
password_md5 = hashlib.md5((puzzle_input + str(password)).encode('utf-8')).hexdigest()
42+
43+
while password_md5[0:5] != '00000':
44+
password += 1
45+
password_md5 = hashlib.md5((puzzle_input + str(password)).encode('utf-8')).hexdigest()
46+
47+
puzzle_actual_result = password
48+
49+
else:
50+
password = 1
51+
password_md5 = hashlib.md5((puzzle_input + str(password)).encode('utf-8')).hexdigest()
52+
53+
while password_md5[0:6] != '000000':
54+
password += 1
55+
password_md5 = hashlib.md5((puzzle_input + str(password)).encode('utf-8')).hexdigest()
56+
57+
puzzle_actual_result = password
58+
59+
# -------------------------------- Outputs / results -------------------------------- #
60+
61+
if verbose_level >= 3:
62+
print ('Input : ' + puzzle_input)
63+
print ('Expected result : ' + str(puzzle_expected_result))
64+
print ('Actual result : ' + str(puzzle_actual_result))
65+
66+
67+
68+

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy