Skip to content

Instantly share code, notes, and snippets.

@uwi
Created September 22, 2012 06:40
Show Gist options
  • Save uwi/3765379 to your computer and use it in GitHub Desktop.
Save uwi/3765379 to your computer and use it in GitHub Desktop.
ProjectEuler Problem 62
#!/bin/bash
declare -A ct
declare -A mins
lct=(0 0 0 0 0 0 0 0 0 0)
for((i=1;i<=100000;i++)); do
for((j=0;j<10;j++)); do
lct[$j]=0
done
for((v=i*i*i;v>0;v/=10)); do
((u=v%10));
((lct[u]++))
done
s=""
for((j=0;j<10;j++)); do
s=$s${lct[$j]},
done
((q=ct[$s]>>0))
if [ $q -eq 0 ]; then
mins[$s]=$i
fi
((q++))
if [ $q -eq 5 ]; then
w=mins[$s]
echo $((w*w*w))
break
fi
ct[$s]=$q
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment