<jupyter_start><jupyter_text>Day 13 part A<jupyter_code>import numpy as np
infile="13a_input.txt"
with open(infile) as f:
    start=int(f.readline().replace("\n",""))
    idslist=f.readline().replace("\n","")
idslist=idslist.split(",")
ids=[int(i) for i in idslist if i!="x"]
ids
start
for i in ids:
    mod=start%i
    if mod==0:
        wait=0
    else:
        wait=i-mod
    print("id",i,"waiting:",wait)
# earliest bus is id 773 with waiting time 5
773*5<jupyter_output><empty_output><jupyter_text>part B<jupyter_code>delays=[]
for idx,val in enumerate(idslist):
    if val!="x":
        delays.append(idx)
print("ID,    delay")
for tmpid,tmpdelay in zip(ids,delays):
    print(tmpid,",  ",tmpdelay)<jupyter_output>ID,    delay
13 ,   0
37 ,   7
449 ,   13
29 ,   15
19 ,   32
23 ,   36
773 ,   44
41 ,   54
17 ,   61<jupyter_text>equations1. $13*n1=t$2. $37*n2=t+7$3. $449*n3=t+13$4. $29*n4=t+15$5. $19*n5=t+32$6. $23*n6=t+36$7. $773*n7=t+44$8. $41*n8=t+54$9. $17*n9=t+61$ observations* n7 is multiple of 37 (see n2 and n7 line: $773*n7=t+7+37=37*(n2+1)$). with m7=n7/37: ```(773*37)*m7=t+44```* n3 is multiple of 13 (see n1 and n3 line). with m3=n3/13: ```(449*13)*m3=t+13```* -> ```m3=[(773*37)*m7-44+13]/(449*13)```* all numbers on the left side of the equations are prime.  continuing the argumentation similarly:* ```7. 773*n7=t+44```    * 2.: n7 is multiple of 37    * 4.: n7 is multiple of 29    * 9.: n7 is multiple of 17    * $-> \mathbf{(773*37*29*17)*a=t+44}$* ```3. 449*n3=t+13```    * 1.: n3 is multiple of 13    * 5.: n3 is multiple of 19    * 6.: n3 is multiple of 23    * 8.: n3 is multiple of 41    * $-> \mathbf{(449*13*19*23*41)*b=t+13}$* $\mathbf{a,b, \in N}$ solving for b:$\mathbf{b = [(773*37*29*17)*a-44+13] / (449*13*19*23*41)}$<jupyter_code>%%time
# try integer values for a and check whether b is then also an integer
#for a in range(100000):
a=0
while True:
    remainder=((773*37*29*17)*a-44+13) % (449*13*19*23*41)
    if a%1000000==0:
        t=(773*37*29*17)*a-44
        print("Iteration",a, "t:",t)
        #pass
    if remainder==0:
        t=(773*37*29*17)*a-44
        print("a:",a, "t:",t)
        break
    a+=1
print("done")<jupyter_output>Iteration 0 t: -44
Iteration 1000000 t: 14100292999956
Iteration 2000000 t: 28200585999956
Iteration 3000000 t: 42300878999956
Iteration 4000000 t: 56401171999956
Iteration 5000000 t: 70501464999956
Iteration 6000000 t: 84601757999956
Iteration 7000000 t: 98702050999956
Iteration 8000000 t: 112802343999956
Iteration 9000000 t: 126902636999956
Iteration 10000000 t: 141002929999956
Iteration 11000000 t: 155103222999956
Iteration 12000000 t: 169203515999956
Iteration 13000000 t: 183303808999956
Iteration 14000000 t: 197404101999956
Iteration 15000000 t: 211504394999956
Iteration 16000000 t: 225604687999956
Iteration 17000000 t: 239704980999956
Iteration 18000000 t: 253805273999956
Iteration 19000000 t: 267905566999956
Iteration 20000000 t: 282005859999956
Iteration 21000000 t: 296106152999956
Iteration 22000000 t: 310206445999956
Iteration 23000000 t: 324306738999956
Iteration 24000000 t: 338407031999956
Iteration 25000000 t: 352507324999956
Iteration 26000000 t: 366607617999956
Iteration[...]
{'fraction_non_alphanumeric': 0.15198997179567533, 'fraction_numerical': 0.28267000940144155, 'mean_word_length': 4.456410256410257, 'pattern_counts': {'":': 1, '<': 11, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '628540', 'license': 'MIT', 'n_tokens_mistral': 1899, 'n_tokens_neox': 1298, 'n_words': 334, 'path': 'advent_of_code_13.ipynb', 'repo_name': 'walkernoreen/adventofcode2020', 'size': '3191'}