Skip to content

Commit c642664

Browse files
committed
Various corrections
1 parent e7b8a23 commit c642664

7 files changed

+341
-295
lines changed

2015/24-It Hangs in the Balance.py

Lines changed: 39 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
test_data = {}
88

99
test = 1
10-
test_data[test] = {"input": """1
10+
test_data[test] = {
11+
"input": """1
1112
2
1213
3
1314
4
@@ -17,26 +18,31 @@
1718
9
1819
10
1920
11""",
20-
"expected": ['99', 'Unknown'],
21-
}
22-
23-
test = 'real'
24-
input_file = os.path.join(os.path.dirname(__file__), 'Inputs', os.path.basename(__file__).replace('.py', '.txt'))
25-
test_data[test] = {"input": open(input_file, "r+").read().strip(),
26-
"expected": ['11846773891', 'Unknown'],
27-
}
21+
"expected": ["99", "Unknown"],
22+
}
23+
24+
test = "real"
25+
input_file = os.path.join(
26+
os.path.dirname(__file__),
27+
"Inputs",
28+
os.path.basename(__file__).replace(".py", ".txt"),
29+
)
30+
test_data[test] = {
31+
"input": open(input_file, "r+").read().strip(),
32+
"expected": ["11846773891", "80393059"],
33+
}
2834

2935
# -------------------------------- Control program execution -------------------------------- #
3036

31-
case_to_test = 'real'
32-
part_to_test = 2
37+
case_to_test = "real"
38+
part_to_test = 2
3339
verbose_level = 1
3440

3541
# -------------------------------- Initialize some variables -------------------------------- #
3642

37-
puzzle_input = test_data[case_to_test]['input']
38-
puzzle_expected_result = test_data[case_to_test]['expected'][part_to_test-1]
39-
puzzle_actual_result = 'Unknown'
43+
puzzle_input = test_data[case_to_test]["input"]
44+
puzzle_expected_result = test_data[case_to_test]["expected"][part_to_test - 1]
45+
puzzle_actual_result = "Unknown"
4046

4147

4248
# -------------------------------- Actual code execution -------------------------------- #
@@ -45,37 +51,35 @@
4551

4652
mini_quantum_entanglement = 10 ** 100
4753

48-
list_packages = [int(x) for x in puzzle_input.split('\n')]
54+
list_packages = [int(x) for x in puzzle_input.split("\n")]
4955
total_weight = sum(list_packages)
5056
group_weight = total_weight // 3 if part_to_test == 1 else total_weight // 4
5157

52-
for group1_size in range (1, len(list_packages) - 2):
53-
for group1 in itertools.combinations(list_packages, group1_size):
54-
if sum(group1) != group_weight:
55-
continue
56-
if reduce(mul, group1, 1) >= mini_quantum_entanglement:
57-
continue
58+
for group1_size in range(1, len(list_packages) - 2):
59+
for group1 in itertools.combinations(list_packages, group1_size):
60+
if sum(group1) != group_weight:
61+
continue
62+
if reduce(mul, group1, 1) >= mini_quantum_entanglement:
63+
continue
5864

59-
remaining_packages = [x for x in list_packages if x not in group1]
65+
remaining_packages = [x for x in list_packages if x not in group1]
6066

61-
for group2_size in range (1, len(remaining_packages) - 2):
62-
for group2 in itertools.combinations(remaining_packages, group2_size):
63-
if sum(group2) == group_weight:
64-
mini_quantum_entanglement = min(mini_quantum_entanglement, reduce(mul, group1, 1))
67+
for group2_size in range(1, len(remaining_packages) - 2):
68+
for group2 in itertools.combinations(remaining_packages, group2_size):
69+
if sum(group2) == group_weight:
70+
mini_quantum_entanglement = min(
71+
mini_quantum_entanglement, reduce(mul, group1, 1)
72+
)
6573

66-
if mini_quantum_entanglement != 10 ** 100:
67-
break
74+
if mini_quantum_entanglement != 10 ** 100:
75+
break
6876

6977
puzzle_actual_result = mini_quantum_entanglement
7078

7179

7280
# -------------------------------- Outputs / results -------------------------------- #
7381

7482
if verbose_level >= 3:
75-
print ('Input : ' + puzzle_input)
76-
print ('Expected result : ' + str(puzzle_expected_result))
77-
print ('Actual result : ' + str(puzzle_actual_result))
78-
79-
80-
81-
83+
print("Input : " + puzzle_input)
84+
print("Expected result : " + str(puzzle_expected_result))
85+
print("Actual result : " + str(puzzle_actual_result))

2016/02-Bathroom Security.py

Lines changed: 63 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -4,101 +4,103 @@
44
test_data = {}
55

66
test = 1
7-
test_data[test] = {"input": """ULL
7+
test_data[test] = {
8+
"input": """ULL
89
RRDDD
910
LURDL
1011
UUUUD""",
11-
"expected": ['1985', '5DB3'],
12-
}
12+
"expected": ["1985", "5DB3"],
13+
}
1314

1415
test += 1
15-
test_data[test] = {"input": """""",
16-
"expected": ['Unknown', 'Unknown'],
17-
}
18-
19-
test = 'real'
20-
input_file = os.path.join(os.path.dirname(__file__), 'Inputs', os.path.basename(__file__).replace('.py', '.txt'))
21-
test_data[test] = {"input": open(input_file, "r+").read().strip(),
22-
"expected": ['36629', 'Unknown'],
23-
}
16+
test_data[test] = {
17+
"input": """""",
18+
"expected": ["Unknown", "Unknown"],
19+
}
20+
21+
test = "real"
22+
input_file = os.path.join(
23+
os.path.dirname(__file__),
24+
"Inputs",
25+
os.path.basename(__file__).replace(".py", ".txt"),
26+
)
27+
test_data[test] = {
28+
"input": open(input_file, "r+").read().strip(),
29+
"expected": ["36629", "99C3D"],
30+
}
2431

2532
# -------------------------------- Control program execution -------------------------------- #
2633

27-
case_to_test = 'real'
28-
part_to_test = 2
34+
case_to_test = "real"
35+
part_to_test = 2
2936
verbose_level = 1
3037

3138
# -------------------------------- Initialize some variables -------------------------------- #
3239

33-
puzzle_input = test_data[case_to_test]['input']
34-
puzzle_expected_result = test_data[case_to_test]['expected'][part_to_test-1]
35-
puzzle_actual_result = 'Unknown'
40+
puzzle_input = test_data[case_to_test]["input"]
41+
puzzle_expected_result = test_data[case_to_test]["expected"][part_to_test - 1]
42+
puzzle_actual_result = "Unknown"
3643

3744

3845
# -------------------------------- Actual code execution -------------------------------- #
3946

40-
password = ''
47+
password = ""
4148

4249
if part_to_test == 1:
43-
keypad = '''123
50+
keypad = """123
4451
456
45-
789'''
52+
789"""
4653

47-
x = 1
48-
y = 1
49-
for string in puzzle_input.split('\n'):
50-
for letter in string:
51-
if letter == 'U':
52-
y = max(0, y-1)
53-
elif letter == 'D':
54-
y = min(2, y+1)
55-
elif letter == 'L':
56-
x = max(0, x-1)
57-
elif letter == 'R':
58-
x = min(2, x+1)
54+
x = 1
55+
y = 1
56+
for string in puzzle_input.split("\n"):
57+
for letter in string:
58+
if letter == "U":
59+
y = max(0, y - 1)
60+
elif letter == "D":
61+
y = min(2, y + 1)
62+
elif letter == "L":
63+
x = max(0, x - 1)
64+
elif letter == "R":
65+
x = min(2, x + 1)
5966

60-
password += keypad.split('\n')[y][x]
67+
password += keypad.split("\n")[y][x]
6168

62-
puzzle_actual_result = password
69+
puzzle_actual_result = password
6370

6471

6572
else:
66-
keypad = '''__1__
73+
keypad = """__1__
6774
_234_
6875
56789
6976
_ABC_
70-
__D__'''
71-
72-
x = 0
73-
y = 2
74-
for string in puzzle_input.split('\n'):
75-
for letter in string:
76-
x_new, y_new = x, y
77-
if letter == 'U':
78-
y_new = max(0, y_new-1)
79-
elif letter == 'D':
80-
y_new = min(4, y_new+1)
81-
elif letter == 'L':
82-
x_new = max(0, x_new-1)
83-
elif letter == 'R':
84-
x_new = min(4, x_new+1)
77+
__D__"""
8578

86-
if not keypad.split('\n')[y_new][x_new] == '_':
87-
x, y = x_new, y_new
79+
x = 0
80+
y = 2
81+
for string in puzzle_input.split("\n"):
82+
for letter in string:
83+
x_new, y_new = x, y
84+
if letter == "U":
85+
y_new = max(0, y_new - 1)
86+
elif letter == "D":
87+
y_new = min(4, y_new + 1)
88+
elif letter == "L":
89+
x_new = max(0, x_new - 1)
90+
elif letter == "R":
91+
x_new = min(4, x_new + 1)
8892

89-
password += keypad.split('\n')[y][x]
93+
if not keypad.split("\n")[y_new][x_new] == "_":
94+
x, y = x_new, y_new
9095

91-
puzzle_actual_result = password
96+
password += keypad.split("\n")[y][x]
9297

98+
puzzle_actual_result = password
9399

94100

95101
# -------------------------------- Outputs / results -------------------------------- #
96102

97103
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-
104+
print("Input : " + puzzle_input)
105+
print("Expected result : " + str(puzzle_expected_result))
106+
print("Actual result : " + str(puzzle_actual_result))

2016/03-Squares With Three Sides.py

Lines changed: 45 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -4,74 +4,75 @@
44
test_data = {}
55

66
test = 1
7-
test_data[test] = {"input": """5 10 25
7+
test_data[test] = {
8+
"input": """5 10 25
89
10 15 12""",
9-
"expected": ['Unknown', 'Unknown'],
10-
}
10+
"expected": ["Unknown", "Unknown"],
11+
}
1112

1213
test += 1
13-
test_data[test] = {"input": """""",
14-
"expected": ['Unknown', 'Unknown'],
15-
}
16-
17-
test = 'real'
18-
input_file = os.path.join(os.path.dirname(__file__), 'Inputs', os.path.basename(__file__).replace('.py', '.txt'))
19-
test_data[test] = {"input": open(input_file, "r+").read().strip(),
20-
"expected": ['983', 'Unknown'],
21-
}
14+
test_data[test] = {
15+
"input": """""",
16+
"expected": ["Unknown", "Unknown"],
17+
}
18+
19+
test = "real"
20+
input_file = os.path.join(
21+
os.path.dirname(__file__),
22+
"Inputs",
23+
os.path.basename(__file__).replace(".py", ".txt"),
24+
)
25+
test_data[test] = {
26+
"input": open(input_file, "r+").read().strip(),
27+
"expected": ["983", "1836"],
28+
}
2229

2330
# -------------------------------- Control program execution -------------------------------- #
2431

25-
case_to_test = 'real'
26-
part_to_test = 2
32+
case_to_test = "real"
33+
part_to_test = 2
2734
verbose_level = 1
2835

2936
# -------------------------------- Initialize some variables -------------------------------- #
3037

31-
puzzle_input = test_data[case_to_test]['input']
32-
puzzle_expected_result = test_data[case_to_test]['expected'][part_to_test-1]
33-
puzzle_actual_result = 'Unknown'
38+
puzzle_input = test_data[case_to_test]["input"]
39+
puzzle_expected_result = test_data[case_to_test]["expected"][part_to_test - 1]
40+
puzzle_actual_result = "Unknown"
3441

3542

3643
# -------------------------------- Actual code execution -------------------------------- #
3744

3845
possible_triangles = 0
3946
if part_to_test == 1:
40-
for string in puzzle_input.split('\n'):
41-
sides = [int(x) for x in string.split(' ') if not x == '']
42-
sides.sort()
43-
a, b, c = sides
44-
45-
if c < (a + b):
46-
possible_triangles += 1
47+
for string in puzzle_input.split("\n"):
48+
sides = [int(x) for x in string.split(" ") if not x == ""]
49+
sides.sort()
50+
a, b, c = sides
4751

52+
if c < (a + b):
53+
possible_triangles += 1
4854

49-
puzzle_actual_result = possible_triangles
55+
puzzle_actual_result = possible_triangles
5056

5157
else:
52-
lines = puzzle_input.split('\n')
53-
for n in range(len(lines)):
54-
lines[n] = [int(x) for x in lines[n].split(' ') if not x == '']
55-
for n in range(len(lines)//3):
56-
for i in range (3):
57-
sides = [int(lines[n*3+y][i]) for y in range (3)]
58-
sides.sort()
59-
a, b, c = sides
58+
lines = puzzle_input.split("\n")
59+
for n in range(len(lines)):
60+
lines[n] = [int(x) for x in lines[n].split(" ") if not x == ""]
61+
for n in range(len(lines) // 3):
62+
for i in range(3):
63+
sides = [int(lines[n * 3 + y][i]) for y in range(3)]
64+
sides.sort()
65+
a, b, c = sides
6066

61-
if c < (a + b):
62-
possible_triangles += 1
63-
64-
puzzle_actual_result = possible_triangles
67+
if c < (a + b):
68+
possible_triangles += 1
6569

70+
puzzle_actual_result = possible_triangles
6671

6772

6873
# -------------------------------- Outputs / results -------------------------------- #
6974

7075
if verbose_level >= 3:
71-
print ('Input : ' + puzzle_input)
72-
print ('Expected result : ' + str(puzzle_expected_result))
73-
print ('Actual result : ' + str(puzzle_actual_result))
74-
75-
76-
77-
76+
print("Input : " + puzzle_input)
77+
print("Expected result : " + str(puzzle_expected_result))
78+
print("Actual result : " + str(puzzle_actual_result))

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