repos Posted July 21, 2009 Share Posted July 21, 2009 (edited) ..... Edited July 21, 2009 by repos Link to comment Share on other sites More sharing options...
0 ViZioN Posted July 21, 2009 Share Posted July 21, 2009 Maybe I'm missing something (I've not been with it today) but what is the question you have to carry out? If you post that I'm sure we can give you some help. It's not obvious to me from your post although your code seems to pick a start number and if its even divide by 2 and if odd multiply by 3 and add 1. Then repeat this till the number is 1? Link to comment Share on other sites More sharing options...
0 repos Posted July 21, 2009 Author Share Posted July 21, 2009 Maybe I'm missing something (I've not been with it today) but what is the question you have to carry out? If you post that I'm sure we can give you some help. It's not obvious to me from your post although your code seems to pick a start number and if its even divide by 2 and if odd multiply by 3 and add 1. Then repeat this till the number is 1? For our problem, the input will consist of a series of pairs of integers i and j, one pair of integers per line. All integers will be less than 1,000,000 and greater than 0. You should process all pairs of integers and for each pair determine the maximum cycle length over all integers between and including i and j. The Output For each pair of input integers i and j you should output i, j, and the maximum cycle length for integers between and including i and j. These three numbers should be separated by at least one space with all three numbers on one line and with one line of output for each line of input. The integers i and j must appear in the output in the same order in which they appeared in the input and should be followed by the maximum cycle length (on the same line). Sample Input 1 10 100 200 201 210 900 1000 Sample Output 1 10 20 100 200 125 201 210 89 900 1000 174 Link to comment Share on other sites More sharing options...
0 repos Posted July 21, 2009 Author Share Posted July 21, 2009 bump Link to comment Share on other sites More sharing options...
0 briley Posted July 21, 2009 Share Posted July 21, 2009 My C++ is quite rusty, so I'll offer some pseudo-code instead: for each line read in r0, r1 (the min and max for the range) count_max = 0 for every number i between r0 and r1 count = 0 do if i even divide else multiply count++ while i not 1 if count > count_max count_max = count print "r0 r1 count_max\n" Does that help at all? Link to comment Share on other sites More sharing options...
0 repos Posted July 21, 2009 Author Share Posted July 21, 2009 My C++ is quite rusty, so I'll offer some pseudo-code instead:for each line read in r0, r1 (the min and max for the range) count_max = 0 for every number i between r0 and r1 count = 0 do if i even divide else multiply count++ while i not 1 if count > count_max count_max = count print "r0 r1 count_max\n" Does that help at all? it may not sure. jus looking for how to get the program to do the calculation for each indiv number between max and min Link to comment Share on other sites More sharing options...
0 Andre S. Veteran Posted July 21, 2009 Veteran Share Posted July 21, 2009 I don't get what they mean by "determining the cycle length". What is a "cycle length", how is it calculated? It's not a programming question, it's a requirement for your program. If you don't know, I don't know either, ask your teacher. If you have the formula or procedure in plain maths or english it should be straightforward to express it in C++. Link to comment Share on other sites More sharing options...
0 repos Posted July 21, 2009 Author Share Posted July 21, 2009 I don't get what they mean by "determining the cycle length". What is a "cycle length", how is it calculated? It's not a programming question, it's a requirement for your program. If you don't know, I don't know either, ask your teacher.If you have the formula or procedure in plain maths or english it should be straightforward to express it in C++. cycle length would be how many numbers it take to reach 1. like for 22 the cycle length would be 16 becuase it take 16 number doing the calculations to reach 1 Link to comment Share on other sites More sharing options...
0 Andre S. Veteran Posted July 21, 2009 Veteran Share Posted July 21, 2009 cycle length would be how many numbers it take to reach 1. like for 22 the cycle length would be 16 becuase it take 16 number doing the calculations to reach 1Ok, and what are the calculations?Edit: ok judging from your code above, it's if the number is even divide by 2 else multiply by 3 and add 1 repeat above until number == 1 If that's the formula they want, what's wrong with your program? Link to comment Share on other sites More sharing options...
0 Andre S. Veteran Posted July 21, 2009 Veteran Share Posted July 21, 2009 Hum, nevermind my last response I was just being retarded. Briley's pseudo-code is spot-on, just make sure you understand it, translate it to C++ and you're set. Link to comment Share on other sites More sharing options...
0 ViZioN Posted July 21, 2009 Share Posted July 21, 2009 Ahh right I understand it now. Yeah briley's pseudocode has got it. Link to comment Share on other sites More sharing options...
Question
repos
.....
Edited by reposLink to comment
Share on other sites
10 answers to this question
Recommended Posts