-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
134 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import time | ||
from enum import Enum | ||
|
||
class Directions(Enum): | ||
UP = (0, -1) | ||
RIGHT = (1, 0) | ||
DOWN = (0, 1) | ||
LEFT = (-1, 0) | ||
|
||
def step_pt1(grid, x, y, ends: set): | ||
if grid[y][x] == 9: | ||
ends.add((x, y)) | ||
return ends | ||
for direction in Directions: | ||
if 0 <= x + direction.value[0] < len(grid[0]) and 0 <= y + direction.value[1] < len(grid): | ||
if grid[y + direction.value[1]][x + direction.value[0]] == grid[y][x] + 1: | ||
ends = step_pt1(grid, x + direction.value[0], y + direction.value[1], ends) | ||
return ends | ||
|
||
def part1(input_lines): | ||
grid = [[int(point) for point in line] for line in input_lines] | ||
total = 0 | ||
for ii in range(len(grid)): | ||
for jj in range(len(grid[ii])): | ||
if grid[ii][jj] == 0: | ||
# print(len(step_pt1(grid, jj, ii, set()))) | ||
total += len(step_pt1(grid, jj, ii, set())) | ||
print(total) | ||
|
||
def step_pt2(grid, x, y, ends: list): | ||
if grid[y][x] == 9: | ||
ends.append((x, y)) | ||
return ends | ||
for direction in Directions: | ||
if 0 <= x + direction.value[0] < len(grid[0]) and 0 <= y + direction.value[1] < len(grid): | ||
if grid[y + direction.value[1]][x + direction.value[0]] == grid[y][x] + 1: | ||
ends = step_pt2(grid, x + direction.value[0], y + direction.value[1], ends) | ||
return ends | ||
|
||
def part2(input_lines): | ||
grid = [[int(point) for point in line] for line in input_lines] | ||
total = 0 | ||
for ii in range(len(grid)): | ||
for jj in range(len(grid[ii])): | ||
if grid[ii][jj] == 0: | ||
# print(len(step_pt2(grid, jj, ii, list()))) | ||
total += len(step_pt2(grid, jj, ii, list())) | ||
print(total) | ||
|
||
if __name__ == '__main__': | ||
test = 0 | ||
part = 2 | ||
|
||
start_time = time.time() | ||
|
||
if test: | ||
inputLines = open("testInput.txt", "r").read().splitlines() | ||
else: | ||
inputLines = open("input.txt", "r").read().splitlines() | ||
|
||
if part == 1: | ||
part1(inputLines) | ||
elif part == 2: | ||
part2(inputLines) | ||
|
||
total_time = time.time() - start_time | ||
|
||
hours = int(total_time / 3600) | ||
minutes = int(total_time / 60) | ||
seconds = total_time % 60 | ||
|
||
print(f"{hours:02.0f}:{minutes:02.0f}:{seconds:06.3f}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
034565433432321821235456556798712438943432345432101010 | ||
125674344341210930012367349897601123876501656543238923 | ||
545981265210523841112398232098532014101665437654147014 | ||
436780378019654756501454101123442125012878328956056985 | ||
521091489328765661498760130210356916763969012347841076 | ||
342698456410644570187321221202197809854054521078932987 | ||
434784387569653089298435430143087612870123654169410673 | ||
525601295678762120387589347834561543965434783254321034 | ||
510567856789854871456678956921670123457650199165890321 | ||
654356943889903962345665067830589894398743278056785410 | ||
701245012958712653434784167845678765210634565410156789 | ||
898434321867012344321093254976104543231023876321943089 | ||
686321780154102101287765323987267650122012989423872176 | ||
567980691233283237898894015416398532143606788714565765 | ||
408974500543098946907623234505458545014545698601159854 | ||
312363217632127655416510107612369876105894332589018345 | ||
221457898565634562323421458733478983276701201478121230 | ||
100656967874567641032102369021098744589856782363210121 | ||
789345450923498634543001078112321654678345891054308701 | ||
654212321012654521694210981205430903543232654143489610 | ||
503403430156787610784300870376567812654121743267876523 | ||
012567567343898525695421889487854925780010893210965432 | ||
123498788210123436786438976598943056891234984921014101 | ||
019567699101898345877567887678762147878765675870123012 | ||
108754543210567212968900194589054038969454566767636323 | ||
205610121056750303453213293032123229454323879098545438 | ||
014981232347841219874984782143210110301012978121654569 | ||
123672654338932306705675676154560121212307665430743478 | ||
298543789221069455012310145069430430925408578989832387 | ||
567010176109178764563498232178521567876519454567601296 | ||
432123485458769853074567310123678106898323343218970345 | ||
012034394367458102189601489433439256765401252102181234 | ||
123465210210343012078732676512508349850106769843098321 | ||
054896990101212043896543216109612556743219856784587410 | ||
969887889654302158987894107898743445654340145697656531 | ||
878791078745983467856765545677654354567854234548545621 | ||
745622363215676500345653231987980123498960129639343210 | ||
034215454301876211256570120345678154323870038721658343 | ||
122100189321945308967981011234569067212721801290569012 | ||
543893276430932457898876323233432178008934980387378143 | ||
456764345567801966501895400145567889127645673456269654 | ||
369632105478765873432689312176876901234560012562158765 | ||
278543254309894569546576543089985432321071239873043210 | ||
103450569212723278637434010034394321810980548954560127 | ||
894321078112010198728922121165223010901289687643073438 | ||
765697151003434587017213033278112987874398796542189569 | ||
056788769876524326501304544569001056965834321233675678 | ||
145679458985015415432987693432102345216945610344569547 | ||
230989347034376102341056780540989104307898700123678632 | ||
321078234123289211652346791691071234487465410878766781 | ||
989165106000105690789905882782360943296578321969215690 | ||
076234245612234782349814943485456850123489100154304385 | ||
145210238763145671456723876596306765012101256701235276 | ||
234300149854078980365432101487217898721032349810120123 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
89010123 | ||
78121874 | ||
87430965 | ||
96549874 | ||
45678903 | ||
32019012 | ||
01329801 | ||
10456732 |