Skip to content

Instantly share code, notes, and snippets.

@izabera
Created September 28, 2025 01:20
Show Gist options
  • Save izabera/171e8709a0fb9f10082d5b15c4c4d8f7 to your computer and use it in GitHub Desktop.
Save izabera/171e8709a0fb9f10082d5b15c4c4d8f7 to your computer and use it in GitHub Desktop.
#!/bin/bash
genspell () {
declare -gA spell
local w s i
while read -r w; do
for ((i=${#w}-1;i>=0;i--)) do
spell[_${w::i}${w:i+1}]+=\ $w
done
spell[_$w]+=\ $w
done
}
. ./dict 2>/dev/null || {
time genspell
printf 'declare -gA spell=(\n'
printf '%q\t%q\n' "${spell[@]@k}"
printf ')\n'
} > dict
set -f
for w do
declare -A dedup=()
for ((i=0;i<=${#w};i++)) do
for s in ${spell[_${w::i}${w:i+1}]}; do
dedup[$s]=
done
done
result=(${!dedup[@]})
result=(${result[@]#_})
echo $w: ${result[@]-<no results>}
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment