Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
buttcoin smuggler
Jun 25, 2011

KidDynamite posted:

So I'm in school at Rutgers just finished Computers and Programming 101. I'm taking 102 in the fall, and then Computer Orginization and Data Structures & Algorithm Design. I'm doing Udacity(currently doing their 101) to supplement my learning and trying my hand at Project Euler(currently stuck on #3). Will this be enough to start applying for internships for next summer?

I don't really feel comfortable enough to start contributing to open source on github yet. Though I do have one where I have uploaded my Euler attempts.

Doing problem 3 in the obvious way gets me the answer in under a second. I'm not trying to be mean, but I really think you should work on your programming (or math?) skills before thinking about applying to internships. Problem 3 is not a hard problem. I literally started learning to program 2 days ago and I got it in under 5 minutes, and most of that time was spent looking up syntax.

Adbot
ADBOT LOVES YOU

buttcoin smuggler
Jun 25, 2011

KidDynamite posted:

I got something quickly too I just can't get my implementation to run in under a minute.

If you're trying to factor a number n, you only need to test factors up to sqrt(n). You can find the rest based on those. You can also just test the odds on this one.

If those don't help, post the code. My implementation in Haskell takes less than a second, so there's probably something really inefficient and easy to fix.

buttcoin smuggler
Jun 25, 2011
The reason it hangs is that your for-loop goes through 600851475141 iterations.

Note that the factors of a number N are symmetrical about the square root of that number, in the sense that if K is a factor less than the square root, then N/K is a factor greater than the square root (do you see why?). One way to do it is to find all of the factors less than sqrt(600851475143), find the corresponding factor greater than the square root, and then check to see which of the factors are prime.

This way is approximately 800,000 times more efficient (why?).

EDIT: Also I think it would be more efficient to see if the number divides 600851475143 first and then see if it is prime, instead of the other way around, as you have it. Fewer divisions that way.

Also, what the poster below said.

buttcoin smuggler fucked around with this message at 01:55 on Jul 13, 2012

buttcoin smuggler
Jun 25, 2011
Yeah, sorry I missed that (I don't know anything about object oriented languages). Why can't you just write a method or function or whatever you call it instead of creating hundreds of thousands of objects?

buttcoin smuggler fucked around with this message at 02:03 on Jul 13, 2012

buttcoin smuggler
Jun 25, 2011

Null Pointer posted:

You're about 12 orders of magnitude off.


I don't know C++, but doesn't

code:
x=6008514751431;
        for( long z=2; z<x; z++)
mean that we have a for loop that runs for every value of z between 2 and 600851475141? What am I missing?

buttcoin smuggler fucked around with this message at 05:28 on Jul 13, 2012

Adbot
ADBOT LOVES YOU

buttcoin smuggler
Jun 25, 2011

Bongo Bill posted:

LaTeX is easy to use and looks great. I'd highly recommend it.

Just want to reiterate this. It makes all of my word processing easier (using Mendeley and bibtex alone saved me a lot of time in school). It's also far more elegant than Word.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply