last update
This commit is contained in:
40
9/9.py
Executable file
40
9/9.py
Executable file
@@ -0,0 +1,40 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
from random import randrange
|
||||
import sys
|
||||
|
||||
L = []
|
||||
with open(sys.argv[1], 'r') as f:
|
||||
L = f.readlines()
|
||||
L = [int(x.strip()) for x in L]
|
||||
|
||||
|
||||
def validsum(L, n):
|
||||
for i in L:
|
||||
for ii in L:
|
||||
if i + ii == n:
|
||||
return True
|
||||
return False
|
||||
|
||||
# part 1
|
||||
p = 25
|
||||
ans = 0
|
||||
for i in range(len(L)):
|
||||
if i < p:
|
||||
continue
|
||||
if not validsum(L[i-p:i], L[i]):
|
||||
print(L[i])
|
||||
ans = L[i]
|
||||
break
|
||||
|
||||
# part 2
|
||||
for i in range(len(L)):
|
||||
nums = [L[i]]
|
||||
for ii in L[i+1:]:
|
||||
nums.append(ii)
|
||||
if sum(nums) == ans:
|
||||
nums.sort()
|
||||
print(nums[0] + nums[-1])
|
||||
sys.exit(0)
|
||||
elif sum(nums) > ans:
|
||||
break
|
||||
20
9/e.txt
Normal file
20
9/e.txt
Normal file
@@ -0,0 +1,20 @@
|
||||
35
|
||||
20
|
||||
15
|
||||
25
|
||||
47
|
||||
40
|
||||
62
|
||||
55
|
||||
65
|
||||
95
|
||||
102
|
||||
117
|
||||
150
|
||||
182
|
||||
127
|
||||
219
|
||||
299
|
||||
277
|
||||
309
|
||||
576
|
||||
1000
9/input.txt
Normal file
1000
9/input.txt
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user