Repository navigation
Expand file tree
/
Copy pathday1.py
More file actions
96 lines (65 loc) · 3.44 KB
/
Copy pathday1.py
File metadata and controls
96 lines (65 loc) · 3.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
def get_list_from_num():
numbers="68376334795224855827459835293967497295464175589881588256882344699473595413912688\
27864723586256612323398392166257879291745391279535274642651264996561591958851212556718683\
741137117987528762148875976142962917488697229834919772242345829932314152941319132762248524\
9495864168181327197661454464926326248274999448373741839963155646828842752761293142356422\
96435534952198748321149636128966637577972834595223164945371168453916489315181184965333184\
599899859799114688136171723451791175989379234881581875526245637862711677949543559613961724\
65716785311833359562441638714456742447655864463625291598541375359621171848751922738722228\
998873572923129782861826362329212525747381183475211876378296238318724373819792239556756342\
5788913782368492412733843324851951521179673259931492161139973657127722254633236946113627741\
74197948655241239897224923565368323139375974377178737875938494688367336425293785471511463\
975329972374393876637693347229791729548351544863829837166982126943573981533929262552729613\
8462613182967817121956928868559714113235532278825416392388837815557394875318542315899787771\
86876424464574466434225365412389797617254964262923593821685356412161242117418965525621289418\
2417224191387353782897617273827698391523224145158942191112156722889985393466795478625622361\
4621554618294467191255153395256524786159758429643756586457639177183891162214163549688595416\
89338319499582453424784141424752626821276195491371945211487676474579998279259475375962633431\
96311919178943681167388935487976611118996641383983548189311354869849447199923931486817241166\
16741428937687985152658296679845474766477741553632712968679175356452987459761126437216758171\
18239521939328919914899681376284999148467842979357862933121579699675148437578489556168215665\
857988751874686237175137269247276521737479132465674529157478449529947736296467635114818367689\
712236683865634274594494527526361772935983146656569498321725259423782818761285752334426541822\
7883219383138893873384775659548637662867572687198263688597865118173921615178165442133987362382\
721444844952715592955744739873677838847693982379696776"
numbers = list(numbers)
i = 0
while i < len(numbers):
numbers[i] = int(numbers[i])
i += 1
return numbers
def check_if_equal_with_next_num(num_list, i):
if ( i + 1 ) != len(num_list):
current_to_next = (i + 1) != len(num_list) and num_list[i] == num_list[i+1]
else:
current_to_next = False
last_to_first = (i + 1) == len(num_list) and num_list[i] == num_list[0]
result = current_to_next or last_to_first
return result
def count_solution(part_number):
num_list = get_list_from_num()
solution = 0
i = 0
while i < len(num_list):
if part_number == 1:
condition = check_if_equal_with_next_num(num_list, i)
elif part_number == 2:
condition = check_if_equal_with_middle_num(num_list, i)
if condition:
solution += num_list[i]
i += 1
return solution
def check_if_equal_with_middle_num(num_list, i):
half_len = len(num_list) / 2
half_len = int(half_len)
if i < half_len:
middle_i = i + half_len
elif i >= half_len:
middle_i = i - half_len
result = num_list[i] == num_list[middle_i]
return result
def main():
print("part 1: " + str(count_solution(1)))
print("part 2: " + str(count_solution(2)))
if __name__ == '__main__':
main()