Skip to content

Instantly share code, notes, and snippets.

@roblogic
Last active February 12, 2025 09:17
Show Gist options
  • Save roblogic/7447f8466d935c0a6d3d6671719abfb3 to your computer and use it in GitHub Desktop.
Save roblogic/7447f8466d935c0a6d3d6671719abfb3 to your computer and use it in GitHub Desktop.
debug=#
jw(){
(($#1>$#2))&&x=$1 y=$2||x=$2 y=$1
x=$x:l y=$y:l h=$[$#y/2+1]
$debug echo x $x y $y h $h
r(){
l=$#2 g=$2 s=
for i ({0..$#1});{
p=${1:$i:1} v=$[i-h<0?0:i-h] w=$[i+h>l?l:i+h]
$debug echo i $i p $p v $v w $w
for j ({$v..$w});{
$debug echo j $j p $p g $g gj ${g:$j:1}
[[ $p = ${g:$j:1} ]]&&{ s=$s$p g=${g:0:$j}.${g:$j+1} ; break }
}
}
echo $s
}
m=`r "$x" "$y"` n=`r "$y" "$x"` d=$#m e=$#n
$debug echo m $m n $n d $d e $e
((d==0|e==0|d!=e))||{ echo 0.0;exit;}
for ((i=0;i<d;i++));{ [ "${m:$i:1}" != "${n:$i:1}" ]&&((u++));};z=$((u/2))
bc -l<<<"($d/$#y+$e/$#x+($d-$z)/$d)/3"
}
jw 1234567890qwertyuiopasdfghjklzxcvbnm mnbvcxzlkjhgfdsapoiuytrewq0987654321
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment