day 22 part 1
[aoc_eblake.git] / 2018 / day5b.sh
blobac9f2bbcb8b7bda4050c5bffa163664e60fbd98a
1 read line < ${1-/dev/tty}
2 echo "Starting with ${#line} characters"
3 orig=$line
4 best_len=${#line}
5 for outer in {a..z}; do
6 adj=${orig//[$outer${outer^}]/}
7 line=$orig
8 while [[ $line != $adj ]]; do
9 line=$adj
10 for l in {a..z}; do
11 eval adj=\${adj//$l${l^}}
12 eval adj=\${adj//${l^}$l}
13 done
14 done
15 echo "Letter $outer gives ${#line} characters"
16 if [[ ${#line} -lt $best_len ]]; then
17 best_len=${#line}
18 best_letter=$outer
20 done
21 echo "Best letter $best_letter gives $best_len"