Created
February 29, 2020 11:19
-
-
Save ahmubashshir/8019f285603d3c84ff77688df27a9922 to your computer and use it in GitHub Desktop.
'Floyeds Turtle' implemented in vala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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