HardQuor's forum posts
I think you should totally go for it, my math skills are quite lacking as well. Hell, i was assigned high school algebra when i took my college placement tests. Besides, the more the merrier :DI thought about trying the Project Euler thing when you brought it up.
On the one hand, I like the programming part. If I didn't, then I put a lot of effort into getting a degree in something I hate (and got near-straight A's in it, too... bloody interface design :evil: )... :lol:
On the other hand, I don't do well with numbers (something that might baffle other programmers, and my math teachers in college). It took me several tries to finally understand algebra (high school, two math courses in the Navy, then it finally clicked in college... where I tutored math, too... :? ), and arithmetic can get me in trouble (9 * 7 != 16... I know it, I feel it, but it's even money if I actually write it correctly).
I'll ponder some more... I'm leaning towards "go for it," though. ;)
OrkHammer007
[QUOTE="HardQuor"]Yeah, that's way over my head :( I'll just consider my solution a good compromise between conciseness and elegance :PGabuEx
Well, it's actually not too conceptually difficult. I probably just explained it badly. There are two main concepts that need to be understood with what I was talking about:
1. First, there are prime numbers (numbers which are divisible by only 1 and itself), and there are composite numbers (numbers which are divisible by more than that). Any composite number can be represented as a product of prime numbers (for example, 12 = 2 * 2 * 3).
2. Second, to say that x is divisible by y is to say that all prime factors of y are also prime factors of x. For example, 12 is divisible by 4 because 12 = 2 * 2 * 3, while 4 = 2 * 2 - all prime factors of 4 are also prime factors of 12.
See if what I said makes any more sense in light of those two things (or tell me if the above also makes no sense).
No, i think you explained prime factors just fine (which i'm thankful for, as the next problem for Project Euler deals directly with figuring them out for a ridiculously large number). What is over my head is conceptualizing it all in code. Although, i'm not really dedicating a lot of thought to it, admittedly :PYeah, that's way over my head :( I'll just consider my solution a good compromise between conciseness and elegance :PWell, yours was a bit better, but there's actually a very much more streamlined way of doing this. If you're curious about what that is,
...
This requires code that's rather more complicated than what we've got here, though. Just for fun, though, I implemented it as a proof of concept; it pretty much instantly finds the answer.GabuEx
...I'm still trying to figure out why that worked... OrkHammer007I'm glad you left me an opening to explain my methodology, i'm a little proud of it (more than i should be, anyway :P). The reason is because i approached it more like a human approaches similar problems. When we try to find lowest common denominators, we start from the highest number and work our way down. Just think about breaking change, you usually start with quarters first, then dimes, nickels, and finally pennies. So instead of incrementing n, i decided to decrement it.
Then i had the problem of making x divisible by each previous term as well as the one it was in the loop for. I figured my problem was that i was incrementing x by 1, which is obviously not divisible by any number but 1. so since i was decrementing n anyways, it made sense to just increment x by it's previous value, since those are the smallest increments that are divisible by each previous value of n.
I'm a bit dense at the moment: programming challenges tend to cost me sleep (one time, while I was taking C++ 1 in college, I was at the PC for 12 straight hours because I literally couldn't sleep until I figured out the method that output a pyramid on the screen).haha, I've experienced similar frustrations with sleep since i've started Project Euler :POrkHammer007
that's good news! :) originally, i had thought to get more responses from others around the boards, but since it's just basically three of us, i wanted to make sure it was cool with you and gabu if i kept pestering you :PDon't worry about annoying me: I tutored programming (VB, C++, and Java) to pay part of my tuition, and I love a good coding challenge (even if it aggravates my insomnia :lol: ). Ask away!
OrkHammer007
also, seeing as you're such a big fan of these challenges, are you interested in checking out Project Euler yourself?
haha, yeah, i thought i was at the "edit post" screen, not the "new post" screen :POh... and I think GS is running part of your code: somehow, you quadruple-posted. :shock:
OrkHammer007
[QUOTE="HardQuor"]since (0 % 0) == 0GabuEx
Nope. x % 0 for any x is asking "what is the remainder when x is divided by 0"? Division by 0 is obviously not allowed, which thus causes your program to crash.
Ahh. Now i get it. I feel dense :(I should've known better than to think that my code was optimal, you just blew my mind!:shock::lol:Actually, there's an even easier way to do this that doesn't need two loops or extra variables:
int x = 1;
GabuEx
for (int n = 2; n (less than or equal to) 20; n++)
{
if (x % n != 0)
{
x++;
n = 1;
}
}
was that? could it be? did you complement my code, or am i delusional? :lol:This basically loops through all values of n, and if it finds that x is not divisible by one of the values, then it increments x by 1 and starts over.
Of course, this is very brute force, and there is a very elegant way of figuring it out if you add in a bit of smart math, but this nonetheless works.
GabuEx
oops, i didn't get to see your post before i decided to see my methodology to the end :?Hopefully, you can read the code from the screen shot; since the forum code doesn't like C++/Java, it'll probably work a bit better like this.
It's written in Java (I'm a bit more comfortable with it), but it should be simple to convert it to C++.
It took about 25 seconds to run, and it came up with a figure in 9 digits... :shock:
Hopefully, this helps. :D
OrkHammer007
but i do have good news, i got it!
int x=20;
int y=0;
for( int n=20; n > 1; n-- )
{
while( (x % n) != 0 )
{
x = x + y;
};
y = x;
};
I figured that my mistake would be easily corrected by just incrementing x by it's last known value instead of by 1. And even better, the code is simpler and it rendered instantly :) thanks for your help and sorry i wasn't able to consider your contribution :?
By the by, I hope i'm not annoying you guys with my constant questions? :?
Log in to comment