-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday2.py
More file actions
37 lines (32 loc) · 959 Bytes
/
day2.py
File metadata and controls
37 lines (32 loc) · 959 Bytes
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
import math
file = open("./day2_input", "r")
content = file.read()
strings = content.split(",")
rs = [string.split("-") for string in strings]
for r in rs:
r[0] = int(r[0])
r[1] = int(r[1])
total = 0
for r in rs:
for i in range(r[0], r[1] + 1):
string = str(i)
middle = math.floor(len(string) / 2)
check_number1 = string[:middle]
check_number2 = string[middle:]
if check_number1 == check_number2:
total = total + i
print(total)
total = 0
for r in rs:
for i in range(r[0], r[1] + 1):
string = str(i)
for split_len in range(1, math.ceil(len(string) / 2) + 1):
splitted = [
string[x: x + split_len]
for x in range(0, len(string), split_len)
]
if all(item == splitted[0]
for item in splitted) and len(splitted) > 1:
total = total + i
break
print(total)