#!/bin/bash set -eu cd "$(dirname "$0")" TMP=$(mktemp); trap 'rm -f "$TMP"' EXIT check() { # DESCRIPTION RULES WORD EXPECTED_FINAL_STRING printf '%s\n' "$2" > "$TMP" got=$(python3 uts35.py "$TMP" "$3" | awk '/^ *[0-9]+ - /{w=$3} END{print w}') [ "$got" = "$4" ] || { echo "FAIL: $1 on $3 -> $got, want $4"; exit 1; } echo "ok: $1 on $3 -> $got" } # Collatz of 5 (5 -> 8 -> 4 -> 2 -> 1): halts at the word a check "collatz" "$(cat collatz.txt)" aaaaa Ma # a->b, b->a: each step removes two letters, appends one; 11 a's end as b check "shrink " 'M a [ab] ([ab]*) > | M $1 b ; M b [ab] ([ab]*) > | M $1 a ;' aaaaaaaaaaa Mb # a->bbb, b->(empty): the word drains through empty productions check "drain " 'M a [ab] ([ab]*) > | M $1 b b b ; M b [ab] ([ab]*) > | M $1 ;' aaaaaa Mb # c has no production (halting symbol): aaa -> abc -> cbc, then stuck check "haltsym" 'M a [abc] ([abc]*) > | M $1 b c ; M b [abc] ([abc]*) > | M $1 a ;' aaa Mcbc # The post's Collatz claim, step by step: each pass is one tag step; # on a^7 the values appear as runs of a's. cp collatz.txt "$TMP" got=$(python3 uts35.py "$TMP" aaaaaaa | awk ' /^ *[0-9]+ - / { w = $3; sub(/^M/, "", w) if (w != "" && w !~ /[^a]/ && length(w) != last) { printf "%s%s", sep, length(w); sep = " -> "; last = length(w) } }') want="7 -> 11 -> 17 -> 26 -> 13 -> 20 -> 10 -> 5 -> 8 -> 4 -> 2 -> 1" [ "$got" = "$want" ] || { echo "FAIL: milestones $got"; exit 1; } echo "Collatz milestones on a^7: $got" echo "all checks pass"