Skip to content

Instantly share code, notes, and snippets.

@stopfaner
Created July 28, 2014 11:03
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 stopfaner/e25a13db5c2e8494aaf6 to your computer and use it in GitHub Desktop.
Save stopfaner/e25a13db5c2e8494aaf6 to your computer and use it in GitHub Desktop.
Turtle moving algorithm
public class Solution {
/*
* Initialisation of sum
* Initialization of parametres of field
*/
public static double sum=1;
public static double heigth = 3;
public static double length = 3;
//----------------------------------------------------------
public static void main(String[]args) {
//checking up
if(heigth == length) {
sum*=2;
for(int i=(int)heigth-1;i>2;i--) {
sum*=(length-1)/(i-1)+1;
}
sum*=length;
}
else {
if(heigth==2) {
sum=length;
}
else {
sum*=(length-1)/(heigth-1)+1;
for (int i=(int)heigth-1;i>2;i--) {
sum*=(length-1)/(i-1)+1;
}
sum*=length;
}
}
//printing
System.out.println(sum);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment