OK here we go, #AdventOfCode day 2 with a one-liner in a different cursed language from yesterday (that was Matlab).
My plan for part 1 is to split on dashes, loop through the range, and add up numbers that match the pattern. #Awk is extremely DWIM about a value being both a number and a string so it works fine:
```
tr , '\n' <input2.txt | awk -F- 'BEGIN { sum=0 } { for(i=$1;i<=$2;i++) if(substr(i,0,length(i)/2) == substr(i,length(i)/2+1)) sum+=i } END { print sum }'
```
Part 2 is quite a bit harder, we need to allow for any number of repetitions within each ID. Awk is definitely the wrong language, but you could have told me that before. The loops nest quite a bit higher; inside of looping through the ID range, we have to loop through the possible substring lengths, and if it evenly divides the ID, go through the subsequences and make sure they are all the same. It is, *technically*, still one line:
```
tr , '\n' <input2.txt | awk -F- 'BEGIN { sum=0 } { for(id=$1;id<=$2;id++) for(sl=1;sl<length(id);sl++) if(length(id)%sl==0 && length(id)/sl>1) { ok=1; for(i=1;i<length(id)/sl;++i) ok = ok && substr(id,0,sl) == substr(id,i*sl+1,sl); if(ok) { sum+=id; break } } } END { print sum }'
```