-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathd16.py
84 lines (63 loc) · 1.82 KB
/
d16.py
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
import sys, time
from datetime import date
sys.path.extend(['..', '.'])
from collections import *
from main import run
def pattern(inp, pos):
su = 0
pattern = [0] * (pos) + [1] * (pos+1) + [0] * (pos+1) + [-1] * (pos+1)
pattern2 = [0] * (pos+1) + [1] * (pos+1) + [0] * (pos+1) + [-1] * (pos+1)
for i, v in enumerate(inp):
mul = pattern2[(i - len(pattern))%len(pattern2)]
if i < len(pattern):
mul = pattern[i%len(pattern)]
su += (v * mul)
return abs(su)%10
def p1(v, log=False):
return 0
lines = v.strip().split('\n')
inp =[int(ch) for ch in lines[0]]
for ph in range(4):
new_inp = []
for i in range(len(inp)):
new_v = pattern(inp, i)
new_inp.append(new_v)
inp = new_inp
#print(inp)
out = ''.join(map(str, inp[:8]))
return out
def suffix_sum(inp):
suffix = [0]
su = 0
for v in inp[::-1]:
su += v
suffix.append(su)
return suffix[::-1]
def p2(v, log=False):
lines = v.strip().split('\n')
offset = int(lines[0][0:7])
inp =[int(ch) for ch in lines[0]]
end = [inp[i%len(inp)] for i in range(offset, 10000 * len(inp))]
for ph in range(100):
su = 0
for i in range(len(end) -1, -1, -1):
su += end[i]
su %= 10
end[i] = su
#print(inp)
out = ''.join(map(str, end[0:8]))
return out
return 0
def pp(*v):
if PP:
print(v)
def get_day():
return date.today().day
def get_year():
return date.today().year
if __name__ == '__main__':
#0 samples_only, 1 run everything, 2 only my input data
DB = 2
#Debugprint: print if 1, not if 0
PP = 1
run(get_year(), get_day(), p1, p2, run_samples = DB < 2, samples_only = DB == 0)