-
Notifications
You must be signed in to change notification settings - Fork 0
/
day6part2.py
117 lines (88 loc) · 2.71 KB
/
day6part2.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import copy
import sys
import numpy as np
import pandas as pd
import matplotlib
import re
def getManAdjacentIndices(row, col, arr):
m = len(arr)
n = len(arr[0])
adjacent_indices = []
if row > 0:
adjacent_indices.append((row - 1, col))
if row+1 < m:
adjacent_indices.append((row + 1, col))
if col > 0:
adjacent_indices.append((row, col - 1))
if col+1 < n:
adjacent_indices.append((row, col + 1))
return adjacent_indices
def getAdjacentIndicies(x, y, arr):
position = (x, y)
adj = []
for dx in range(-1, 2):
for dy in range(-1, 2):
rangeX = range(0, arr.shape[0]) # X bounds
rangeY = range(0, arr.shape[1]) # Y bounds
(newX, newY) = (position[0] + dx, position[1] + dy) # adjacent cell
if (newX in rangeX) and (newY in rangeY) and (dx, dy) != (0, 0):
adj.append((newX, newY))
return adj
def extractKeys(string):
alphaRemoved = re.sub("[^0-9]", "", string)
num = int(alphaRemoved)
numRemoved = re.sub(r"\d+", "", string).replace(" ", "")
return [numRemoved, num]
def lazyAdd(dict, key, num):
if key in dict:
dict[key] += num
else:
dict[key] = num
def safeIndex(arr, row, col):
if row > -1 and row < len(arr):
slice = arr[row]
# print(slice)
if col > -1 and col < len(slice):
return slice[col]
else:
return "."
else:
return "."
def invDict(dict):
return {v: k for k, v in dict.items()}
def hashList(list):
return str(list)
def unHashListInt(string):
elements = string.replace('[', '').replace(']', '').split(',')
return [int(element) for element in elements]
def unHashListDouble(string):
elements = string.replace('[', '').replace(']', '').split(',')
return [float(element) for element in elements]
def intify(arr):
return [int(string) for string in arr if not (string == '')]
def doubleify(arr):
return [float(string) for string in arr]
def echo(string):
print(string)
return string
if __name__ == '__main__':
dataFile = open("day6.txt", "r")
data = dataFile.read()
data = data.split('\n')
data = data[:-1]
runningSum = 0
time = int(data[0].split(':')[-1].replace(' ', ''))
distance = int(data[1].split(':')[-1].replace(' ', ''))
firstSet = True
# for time, distance in zip(times, distances):
possibles = 0
for accel in range(time):
newDist = (time-accel)*accel
if newDist > distance:
possibles += 1
# if firstSet:
# runningSum = possibles
# firstSet = False
# else:
# runningSum *= possibles
print(possibles)