Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

jsmwoolf

macrumors regular
Original poster
Aug 17, 2011
123
0
I'm trying to solve a problem from a website called Project Euler. The thing is that I already have a way how to solve it, but the problem is that the array "Number[1000]" keeps producing weird numbers to the millions per index even though it's supposed to only track numbers that have a sum less than or equal to 1,000 and then stores them to a index minus one.

Here's my code:
Code:
//Removed
How come this is happening?
 
Last edited:
the elements of Number are uninitialized. You want to start by setting them to 0
 
Thanks, it now works. However, how come it gave random numbers? Was it because if you don't initialize it, the variable just grabs a random number from the memory?
 
the method used to generate perimeters will never generate 30+40+50
 
Another vote for rechecking the perimeter math.

You might want to try a naive exhaustive approach to get the correct set of answers for comparison.
 
This morning, I found out why it didn't correctly solve the problem before I typed on this post. I found something on wikipedia that allowed you to find all the pythagorean triples with another constant.
b358c1248fba395e5766928b01b36d80.png

However, I don't know how effective this is exactly because I never see it anywhere else. This might be a B.S. statement. The rule can be found here.
http://en.wikipedia.org/wiki/Pythagorean_triple
 
However, is there a more effective way on how to find all of then without finding repeats?

EDIT: Never mind. I solved it and got the correct answer. It's now removed to prevent cheating.
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.