mirror of
https://github.com/ZeusWPI/Advent-of-Code-Aggregator.git
synced 2024-12-22 10:09:42 +01:00
timo bombino
This commit is contained in:
parent
9f7eae8d51
commit
77ee7859a2
10 changed files with 2076 additions and 1 deletions
BIN
2021/SWAMP/2021/py/__pycache__/util.cpython-39.pyc
Normal file
BIN
2021/SWAMP/2021/py/__pycache__/util.cpython-39.pyc
Normal file
Binary file not shown.
2000
2021/SWAMP/2021/py/id1.txt
Normal file
2000
2021/SWAMP/2021/py/id1.txt
Normal file
File diff suppressed because it is too large
Load diff
10
2021/SWAMP/2021/py/main.py
Normal file
10
2021/SWAMP/2021/py/main.py
Normal file
|
@ -0,0 +1,10 @@
|
|||
from w1 import d1
|
||||
|
||||
|
||||
def main():
|
||||
print(d1.part1())
|
||||
print(d1.part2())
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
41
2021/SWAMP/2021/py/util.py
Normal file
41
2021/SWAMP/2021/py/util.py
Normal file
|
@ -0,0 +1,41 @@
|
|||
|
||||
def read(inputData):
|
||||
with open(inputData, "r") as infile:
|
||||
data = infile.readlines()
|
||||
return data
|
||||
|
||||
|
||||
def strArrToIntArray(inputData):
|
||||
return [int(value.replace("\n","").replace(" ","")) for value in inputData]
|
||||
|
||||
|
||||
def readAsIntArray(inputData):
|
||||
return strArrToIntArray(read(inputData))
|
||||
|
||||
def keepEven(inputData):
|
||||
return [d for d in inputData if d % 2 == 0]
|
||||
|
||||
def keepUneven(inputData):
|
||||
return [d for d in inputData if d % 2 == 1]
|
||||
|
||||
def keepIfContaint(inputData, toContain):
|
||||
return [d for d in inputData if toContain in d]
|
||||
|
||||
def removeIfContains(inputData, toContain):
|
||||
return [d for d in inputData if not toContain in d]
|
||||
|
||||
def keepIfDevisor(inputData, toDiv):
|
||||
return [d for d in inputData if toDiv % d == 0]
|
||||
|
||||
def keepIfDivisibleBy(inputData, toDiv):
|
||||
return [d for d in inputData if d % toDiv == 0]
|
||||
|
||||
def get_primelist(lower, upper):
|
||||
result = []
|
||||
for cp in range ( lower, upper + 1 ):
|
||||
for i in range ( lower, cp ):
|
||||
if ( cp % i == 0 ):
|
||||
break
|
||||
else:
|
||||
result.append(cp)
|
||||
return result
|
0
2021/SWAMP/2021/py/w1/__init__.py
Normal file
0
2021/SWAMP/2021/py/w1/__init__.py
Normal file
BIN
2021/SWAMP/2021/py/w1/__pycache__/__init__.cpython-39.pyc
Normal file
BIN
2021/SWAMP/2021/py/w1/__pycache__/__init__.cpython-39.pyc
Normal file
Binary file not shown.
BIN
2021/SWAMP/2021/py/w1/__pycache__/d1.cpython-39.pyc
Normal file
BIN
2021/SWAMP/2021/py/w1/__pycache__/d1.cpython-39.pyc
Normal file
Binary file not shown.
24
2021/SWAMP/2021/py/w1/d1.py
Normal file
24
2021/SWAMP/2021/py/w1/d1.py
Normal file
|
@ -0,0 +1,24 @@
|
|||
import util
|
||||
|
||||
def count_increments(depths, slice_length):
|
||||
increments = 0
|
||||
slice_start = 0
|
||||
slice_end = slice_start + slice_length
|
||||
prev = depths[slice_start:slice_end]
|
||||
for i in range(len(depths)):
|
||||
idx = i+1
|
||||
slice = depths[idx:idx+slice_length]
|
||||
if (sum(slice) > sum(prev) and len(slice) == slice_length):
|
||||
increments += 1
|
||||
prev = slice
|
||||
return increments
|
||||
|
||||
|
||||
def part1():
|
||||
depths = util.readAsIntArray("id1.txt")
|
||||
return count_increments(depths, 1)
|
||||
|
||||
def part2():
|
||||
depths = util.readAsIntArray("id1.txt")
|
||||
return count_increments(depths,3)
|
||||
|
1
2021/SWAMP/README.md
Normal file
1
2021/SWAMP/README.md
Normal file
|
@ -0,0 +1 @@
|
|||
# AoC
|
1
SWAMP
1
SWAMP
|
@ -1 +0,0 @@
|
|||
Subproject commit 16cd1dd8eb8a7c7e39a5ad8780e8c6a9af7c00c0
|
Loading…
Reference in a new issue