Skip to content

Instantly share code, notes, and snippets.

@uwi
Created September 25, 2012 16:24
Show Gist options
  • Save uwi/3782937 to your computer and use it in GitHub Desktop.
Save uwi/3782937 to your computer and use it in GitHub Desktop.
ProjectEuler Problm 65
#!/bin/bash
a=(0)
b=(0)
for((i=1;i<=6;i++)) do
a=(${a[@]} ${a[@]})
b=(${b[@]} ${b[@]})
done
a[0]=2
b[0]=1
for((i=2;i<=100;i++)) do
((k=i%3==0?i/3*2:1))
c=(${b[@]})
carry=0
for((j=0;j<64;j++)) do
((c[j]+=a[j]*k+carry))
((carry=c[j]/10))
((c[j]%=10))
done
b=(${a[@]})
a=(${c[@]})
echo ${a[@]};
done
tot=0
for((i=0;i<64;i++)) do
((tot+=a[i]))
done
echo $tot; # 272
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment