http://challenge.greplin.com/
Give it a shot. I had fun with it. I used Java, but it's a lot of string and number manipulation -- other languages would probably be better.
http://challenge.greplin.com/
Give it a shot. I had fun with it. I used Java, but it's a lot of string and number manipulation -- other languages would probably be better.
I got the first one but I cannot figure out what the hell the sum of prime divisors is. I've looked all over and can't find a formula to determine it. I thought it would be just all the factors of the number that are prime added up, but all examples have 2 more than once and I can't figure out why.
Yeah, I don't know why 2 would be a divisor more than once, but I just put it in once and got the right answer.
Maybe "(12 / 2) / 2 = 3" or something. That's stupid.
Some of the instructions are slightly tough to figure out. I totally misread that problem at first.
Last edited by Macheath; 10-12-2010 at 10:11 AM.
Care to post your sum of prime divisors code so I can feel slightly less dumb?
Code:/** * TEST 2 */ int number = 1; int lastNumber = 1; int limit = 227000; // find first fib number over limit while (number < limit) { int tmp = lastNumber; lastNumber = number; number = lastNumber+tmp; } // find next prime fib number while (!isPrime(number)) { int tmp = lastNumber; lastNumber = number; number = lastNumber+tmp; } System.out.println("x = " + number); int xp1 = number+1; System.out.println("x+1 = " + xp1); int sum = 0; // find divisors of xp1 for (int i = 2; i < xp1/2; i++) { if (xp1%i == 0) { // print if divisor System.out.print(i); if (isPrime(i)) { // add to sum if prime System.out.print(" (prime)"); sum += i; } System.out.println(); } } System.out.println("sum = " + sum);Code:public static boolean isPrime(int n) { if (n == 2) { return true; } int topBound = Integer.MAX_VALUE; for (int i = 2; i < topBound; i++) { if (n % i == 0) { return false; } topBound = (n/i)+1; } return true; }
I swear that's what I'm doing...
I'll post it when I get home, it's on my desktop. I used javascript because I didn't have to install an IDE.
I happen to agree that everyone should learn at least a little bit of programming. You don't need to be a Software Engineer, you don't need to install Linux on your thermostat, but the more you know, the less clueless you'll be in the world we're moving toward. Computer literacy is no longer defined as the ability to use Microsoft Word.
This video is awesome. Bogo sort is a piece of shit. Stupid bogo sort.
Bookmarks