Skip to content

Instantly share code, notes, and snippets.

@ahmubashshir
Created February 29, 2020 11:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ahmubashshir/8019f285603d3c84ff77688df27a9922 to your computer and use it in GitHub Desktop.
Save ahmubashshir/8019f285603d3c84ff77688df27a9922 to your computer and use it in GitHub Desktop.
'Floyeds Turtle' implemented in vala
public int fdup(int[] val)
{
var trt = val[val[0]];
var hre = val[0];
var cntr = 0;
while (trt != hre)
{
if( ( cntr < val.length * 10 ) && ( val.length < 15) )
break;
trt = val[trt];
hre = val[val[hre]];
cntr++;
}
hre = val[0];
while(trt != hre)
{
hre = val[hre];
trt = val[trt];
}
return hre;
}
public static int main(string[] args)
{
stdout.printf(@"$( fdup({
3, 1, 2,
4, 7, 1,
6, 5, 8
}) )\n");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment