Skip to content

Commit 4872856

Browse files
committed
Added day 2015-20
1 parent 5c41949 commit 4872856

File tree

1 file changed

+86
-0
lines changed

1 file changed

+86
-0
lines changed
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# -------------------------------- Input data -------------------------------- #
2+
import os
3+
4+
test_data = {}
5+
6+
test = 1
7+
test_data[test] = {"input": """70""",
8+
"expected": ['4', 'Unknown'],
9+
}
10+
11+
test = 'real'
12+
test_data[test] = {"input": """33100000""",
13+
"expected": ['776160', '786240'],
14+
}
15+
16+
17+
# -------------------------------- Control program execution -------------------------------- #
18+
19+
case_to_test = 'real'
20+
part_to_test = 2
21+
verbose_level = 1
22+
23+
# -------------------------------- Initialize some variables -------------------------------- #
24+
25+
puzzle_input = test_data[case_to_test]['input']
26+
puzzle_expected_result = test_data[case_to_test]['expected'][part_to_test-1]
27+
puzzle_actual_result = 'Unknown'
28+
29+
30+
# -------------------------------- Actual code execution -------------------------------- #
31+
import math
32+
33+
# Inspired from roboticon's solution at https://www.reddit.com/r/adventofcode/comments/3xjpp2/day_20_solutions/cy59lfq/
34+
35+
def get_divisors (value):
36+
small_divisors = [d for d in range (1, int(math.sqrt(value))+1) if value % d == 0 ]
37+
big_divisors = [value // d for d in small_divisors if not d**2 == value]
38+
return small_divisors + big_divisors
39+
40+
41+
if part_to_test == 1:
42+
for string in puzzle_input.split('\n'):
43+
if string == '':
44+
continue
45+
46+
47+
puzzle_input = int(puzzle_input)//10
48+
houses = {}
49+
for i in range (1, puzzle_input+1):
50+
for j in range (1, puzzle_input // i +1):
51+
if i*j not in houses:
52+
houses[i*j] = i
53+
else:
54+
houses[i*j] += i
55+
puzzle_actual_result = {i: houses[i] for i in houses.keys() if houses[i] >= puzzle_input }
56+
puzzle_actual_result = min(puzzle_actual_result.keys())
57+
58+
59+
60+
else:
61+
for string in puzzle_input.split('\n'):
62+
if string == '':
63+
continue
64+
65+
66+
puzzle_input = int(puzzle_input)
67+
houses = {}
68+
69+
for i in range (1, 1000000):
70+
total_value = sum([d*11 for d in get_divisors (i) if i // d <= 50])
71+
if total_value >= puzzle_input:
72+
puzzle_actual_result = i
73+
break
74+
75+
76+
77+
# -------------------------------- Outputs / results -------------------------------- #
78+
79+
if verbose_level >= 3:
80+
print ('Input : ' + puzzle_input)
81+
print ('Expected result : ' + str(puzzle_expected_result))
82+
print ('Actual result : ' + str(puzzle_actual_result))
83+
84+
85+
86+

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