The page reloads and the problem continues.
Printable View
The page reloads and the problem continues.
Haha, nice feature...has anyone put it in the bugs thread?
The way JM has responded to the other bugs posted, do you think it will actually do any good to post this problem there? :DQuote:
Cheers:
Well, at least if we put it in there we will be justified in complaining, we can't complain if no one has even bothered to notify them :)
Point taken Deb.Quote:
Originally posted here by debwalin
Well, at least if we put it in there we will be justified in complaining, we can't complain if no one has even bothered to notify them :)
Cheers:
i am surprised no one came out with a solution more legant than me... i was hoping for a more better and efficient method. the solution provided by me will cripple fro large nos.
hey any algo masters here..............
Although he said he didn't want an algorithm in the original post, here's what I've come up with.
The input number squared tends to be the middle number in the sequence, so in the case of even numbers there will always be an even number of numbers... (kind of confusing isn't it) and for odd numbers, there will be an odd number of numbers. For most cases it seems that input_number^3 will equal closest_odd_numbers to the input_number^2 and counting away until you reach the cube... so for like invader said in the first post:
2 -> 2^2 = 4, closest odd numbers: 3 & 5, 3+5 = 8, done.
3 -> 3^2 = 9, closest odd numbers: 9, not 27 yet so keep going, 7 + 9 + 11, the numbers around 9, they equal 27, you're done. and so on.
The only catch is that this won't yield the lowest number starting the sequence like in the case of 4
another catch ... in which way to proceed while adding...
4 * 4 * 4 = 64 = I + 3 + 5 + 7 + 9 + II + 13 + 15
4*4= 16 closest odd no. 15 ...and add all the odd nos. lower than 15
but
for 5 * 5 * 5 = 125 =21 +23 +25 +27 +29
5*5=25
while adding proceed in both ways....
so how to decide in which way to proceed.
This will do it:
#include <iostream.h>
#include <list.h> //for list (obviously)
#include <math.h> //for char to int conversion
// Made by scat (Ryan Lucas)
int main() {
char * input = new char[5]; // 6 place holders
int num, cube;
list<int> list;
cout << " Please input desired number: " ;
cin >> input; cout "/n";
//Algorithim
_itoa (input, num, 10) //base ten conversion
cube = num * num * num;
cout << "/n Cube of "<< num << " : " << cube << "/n";
int checksum;
int odd = 1;
while(1) {
if (checksum == num) {
int count = list.GetCount();
for (int i = 0; i++; i < count) { //Gets numbers in list
int oNum = list.GetAt(i);
cout << "/nNumber (" << i << ") " << oNum << "/n";
}
break;
}
else if (checksum > num ) { //If addition didn't work
int get = list.GetCount();
odd = list.GetAt(get);
for (int i = 0; i++ ; i < (get - 1) ) { //Removes all numbers except the last one used
list.RemoveAt(i);
}
checksum = 0; //Resets checksum
continue; //Repeat loop with new number
}
else {
checksum = odd + (odd + 2); //total checksum
odd = odd + 2; //get next odd number
list.SetTail(odd); //put in the list
}
}
cout << "/n/n Goodbye!";
return 1;
}
I really am a genius. That's a tight algorithim. Someone hook the greenies...I'm close to grey!
Scat
Null, yeah that's what I meant when I said the catch for 4, you get 13 + 15 + 17 + 19 using my method but the lowest starting sequence starts at 1, not 13. You could always test both conditions, counting down from the floor of the closest odd integers as well as expanding from the square using odd numbers and see which is lower but there's more than likely another way to do it, maybe dynamically using smaller numbers to start with that we know the sequence for? Who knows, I'm at work so testing anything is hard with no compiler but I might take a look at doing it dynamically once I get home. If you can somehow get the endpoints of the sequence then it's nothing to loop through and print them all out.
Scat: You should initialize checksum, it could cause some crazy results..
Also look at your code"
checksum = odd + (odd + 2); //total checksum
odd = odd + 2; //get next odd number
list.SetTail(odd); //put in the list
This is the only place you set values in list. Since odd started as 1, the first value entered will be 3..
Otherwise it looks like it should work, though the whole checksum thing is slightly confusing but does keep it from erasing the everything except the next number all the time, though it seems like it could erase too much, just a thought to where it might break, I haven't done the math to see if it will always keep it from erasing too much but if you have then yes it's a good algorithm.