5 filename="${1:-example.txt}"
14 declare -a results=($template)
16 while read -u 3 poly; do
19 inserts[$left]="$right"
22 for (( a=1; a<=10; a++ )); do
23 cur_string="${results[$(($a-1))]}"
24 for (( b=0; b<$((${#cur_string} - 1)); b++ )); do
25 lookup="${cur_string:$b:2}"
27 results[$a]="${lookup:0:1}${inserts[$lookup]}"
29 results[$a]+="${lookup:0:1}${inserts[$lookup]}"
32 results[$a]+="${cur_string: -1:1}"
41 for (( a=0; a<${#string}; a++ )); do
43 if [ "${counts[$char]+abc}" ]; then
51 get_highest_lowest() {
52 local -n __results="$1"
57 for key in "${!counts[@]}"; do
58 if [ $lowest_count -eq -1 ]; then
59 lowest_count=${counts[$key]}
61 elif [ ${counts[$key]} -lt $lowest_count ]; then
62 lowest_count=${counts[$key]}
65 if [ $highest_count -eq -1 ]; then
66 highest_count=${counts[$key]}
68 elif [ ${counts[$key]} -gt $highest_count ]; then
69 highest_count=${counts[$key]}
74 __results[$lowest_count]=$lowest_letter
75 __results[$highest_count]=$highest_letter
78 do_counts "${results[-1]}"
79 declare -a result_counts=()
80 get_highest_lowest result_counts
82 declare -a temp=( "${!result_counts[@]}" )
83 echo -n "Part 1: Difference between highest and lowest count: "
84 echo $(("${temp[1]}" - "${temp[0]}"))