Results 1 to 4 of 4
 01272015, 06:56 AM #1Member
 Join Date
 Jan 2015
 Posts
 48
 Rep Power
 0
Counting number of steps throughout the circle.
The method public static int steps(int posts, int stride) calculates how many strides can be taken to get back to posts. Let's say if the method is (12, 4), it takes only three steps. Now let's say the method has parameters (12,5), so it should be (5, 10, 3, 8, 1, 6, 11, 4, 9, 2, 7, 12). My method works for such examplse as (12, 4) or (12,3) or (6,2)... but how can I figure out (12,5)?
Java Code:public static int steps(int posts, int stride) { int countSteps = 0; int result = 0; do { result += stride; /* if((result > posts)  (result < posts)) { }*/ countSteps++; } while(result != posts); return countSteps; }
Last edited by ssk2659; 01272015 at 07:29 AM.
 01272015, 07:15 AM #2Member
 Join Date
 Jan 2015
 Location
 Miami, FL
 Posts
 86
 Rep Power
 0
Re: Counting number of steps throughout the circle.
What I think you should do is check when the number of strides goes past the number posts. For example, your example (12, 5) could go like this. once the number of strides reaches 12, whatever is left over would be the new stride variable(in this case 1512=3). So you could have a temp variable that stores the number that goes pasts the number of posts.
Last edited by Deathslice; 01272015 at 07:20 AM.
 01272015, 07:35 AM #3Senior Member
 Join Date
 Jan 2013
 Location
 Northern Virginia, United States
 Posts
 6,226
 Rep Power
 14
Re: Counting number of steps throughout the circle.
Well, I have no idea how your posts are laid out. Seems to me that if you divide the number of posts by the GCD of the two values you would get the number of strides. That would mean that (15,6) would require 5 strides (15 / 3 = 5). But I have no proof or foundation for this. But I'll bet that number theory provides a solution.
Regards,
JimThe Java^{TM} Tutorials  SSCCE  Java Naming Conventions
Poor planning on your part does not constitute an emergency on my part
 01272015, 08:59 AM #4Moderator
 Join Date
 Feb 2009
 Location
 New Zealand
 Posts
 4,716
 Rep Power
 18
Re: Counting number of steps throughout the circle.
What I think you should do is check when the number of strides goes past the number posts. For example, your example (12, 5) could go like this. once the number of strides reaches 12, whatever is left over would be the new stride variable(in this case 1512=3).
Seems to me that if you divide the number of posts by the GCD of the two values you would get the number of strides. That would mean that (15,6) would require 5 strides (15 / 3 = 5). But I have no proof or foundation for this.
The second form of the question  (5,2)  is easier to think about. Clearly the total distance walked is a multiple of both 5 and 2. But because they are coprime it must be a multiple of 10, of which the smallest is 10.
So the answer to (5,2) and hence (15,6) is "5 strides, which will take you around the circle 2 times."

The algebraic slogan is LCM(n,m) = (n*m) / GCD(n,m)
So, n/GCD(n,m) = LCM(n,m)/m = distance/strideLength = number of strides as suggested
And, m/GCD(n,m) = LCM(n,m)/n = distance/cirumference = number of times around the circle.Last edited by pbrockway2; 01272015 at 09:10 AM.
Similar Threads

Counting positive number inputs and negative number inputs of user. HELP!
By cs3 in forum New To JavaReplies: 1Last Post: 10242012, 01:21 PM 
Counting number of user input
By cs3 in forum New To JavaReplies: 3Last Post: 10242012, 10:33 AM 
Counting number of entries in a file
By lenny0 in forum New To JavaReplies: 3Last Post: 05102011, 04:40 AM 
list values in a number of steps given as a command line argument
By Shyamz1 in forum New To JavaReplies: 4Last Post: 10312010, 06:19 PM 
counting number of lines of system.out
By IYIaster in forum New To JavaReplies: 1Last Post: 07212009, 01:37 AM
Bookmarks