Created
December 12, 2022 09:36
-
-
Save halitanildonmez/922349ee34ae79e04789ffd0dff54ba6 to your computer and use it in GitHub Desktop.
Advent of Code 2020 day 13 pt1,2
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
import math | |
import collections | |
T = "bb.txt" | |
M = "aa.txt" | |
file1 = open(M, 'r') | |
Lines = file1.read().splitlines() | |
input_grid = [] | |
for i, line in enumerate(Lines): | |
if len(line.strip()) == 0: | |
continue | |
input_grid.append(line) | |
def part1(): | |
wait_time = int(input_grid[0]) | |
busses = [] | |
bus_str = input_grid[1].split(',') | |
for b in bus_str: | |
if b != 'x': | |
busses.append(int(b)) | |
num_wait = [10000, busses[0], 0] | |
for bn in busses: | |
val = wait_time // bn | |
tmp = val * bn | |
if tmp < wait_time: | |
tmp += bn | |
w = (tmp - wait_time) | |
#print(bn, val, tmp, w, num_wait) | |
if num_wait[0] > w: | |
num_wait[0] = w | |
num_wait[1] = bn | |
num_wait[2] = tmp | |
print((num_wait[0]*num_wait[1])) | |
def part2(): | |
generated_wolfram_str = [] | |
bus_str = input_grid[1].split(',') | |
for i, b in enumerate(bus_str): | |
if b != 'x': | |
#busses.append(int(b)) | |
strs = "(t + " + str(i) + ")" + "mod " + str(b) + "=0," | |
generated_wolfram_str.append(strs) | |
print('paste the following to wolfram alpha, answer is in the form An + answer') | |
print("".join(generated_wolfram_str)) | |
part1() | |
part2() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment