# AoC - Day 5

:date: 2023-12-05 12:00

## Part One

Here is a correct solution that works fine for the test case. However I didn't understand that the ranges in the real input data would be hundreds of millions. Because I just loaded an associative array with the mappings, running this on the real data will kill your computer.

``````\$ awk '{if(/^seeds: /)split(substr(\$0,8),S," ");else if(/^[^0-9]/)T=substr(\$0,1,2);else if(\$0 ~ /^\$/){}else{D=\$1-\$2;for(F=\$2;F<\$2+\$3;F++)M[T F]=F+D}} END{for(i in S){N=S[i]; if(M["se"N])N=M["se"N];if(M["so"N])N=M["so"N];if(M["fe"N])N=M["fe"N];if(M["wa"N])N=M["wa"N]; if(M["li"N])N=M["li"N];if(M["te"N])N=M["te"N];if(M["hu"N])N=M["hu"N]; print(N)}}' < input5.test | sort -n | head -n1

35``````

So I wrote a quick Python program that just checks ranges properly. Down from near-infinity seconds to 38.3ms.

``````\$ ./script5.py|sort -n|head -n1
178159714``````

## Part Two

Damn... Part B took nearly 2 hours! There may be some very clever way, but I'm not sure. But I got it.

``````\$ ./script5b.py
0
719150722
2
336906655
127453946
121228756
4
6
100165128
8
10
12
14
16
18
:->(1h53m)``````