Starting git repo for working on files
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
public class RandomWalker
|
||||
{
|
||||
public static void main(String[] args)
|
||||
{
|
||||
int r = Integer.parseInt(args[0]);
|
||||
|
||||
int xCoordinate = 0;
|
||||
int yCoordinate = 0;
|
||||
int steps = 0;
|
||||
|
||||
System.out.println("(" + xCoordinate + ", " + yCoordinate + ")" );
|
||||
|
||||
while(Math.abs(xCoordinate) + Math.abs(yCoordinate) < r)
|
||||
{
|
||||
if(Math.random() <= 0.25) xCoordinate += 1;
|
||||
else if (Math.random() <= 0.50) xCoordinate -= 1;
|
||||
else if (Math.random() <= 0.75) yCoordinate += 1;
|
||||
else yCoordinate -= 1;
|
||||
|
||||
System.out.println("(" + xCoordinate + ", " + yCoordinate + ")" );
|
||||
steps++;
|
||||
}
|
||||
System.out.println("steps = " + steps);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user