|
-
July 25th, 2003, 04:58 PM
#20
Senior Member
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.
Reality is the one who has it wrong, not you
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|