Page 1 of 5 123 ... LastLast
Results 1 to 10 of 46

Thread: The Greplin Programming Challenge

Hybrid View

  1. #1
    Darth Small Macheath's Avatar
    Join Date
    Sep 2010
    Posts
    15,150

    The Greplin Programming Challenge

    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.

  2. #2
    Senior Member
    Join Date
    Sep 2010
    Location
    Burnsville, Minnesota, United States
    Posts
    2,805
    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.

  3. #3
    Darth Small Macheath's Avatar
    Join Date
    Sep 2010
    Posts
    15,150
    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.

  4. #4
    Senior Member
    Join Date
    Sep 2010
    Location
    Burnsville, Minnesota, United States
    Posts
    2,805
    Care to post your sum of prime divisors code so I can feel slightly less dumb?

  5. #5
    Darth Small Macheath's Avatar
    Join Date
    Sep 2010
    Posts
    15,150
    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;
        }

  6. #6
    Senior Member
    Join Date
    Sep 2010
    Location
    Burnsville, Minnesota, United States
    Posts
    2,805
    I swear that's what I'm doing...

  7. #7
    Darth Small Macheath's Avatar
    Join Date
    Sep 2010
    Posts
    15,150
    Well let's see your code, then.

  8. #8
    Senior Member
    Join Date
    Sep 2010
    Location
    Burnsville, Minnesota, United States
    Posts
    2,805
    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.

  9. #9
    Darth Small Macheath's Avatar
    Join Date
    Sep 2010
    Posts
    15,150
    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.


  10. #10
    Darth Small Macheath's Avatar
    Join Date
    Sep 2010
    Posts
    15,150
    This video is awesome. Bogo sort is a piece of shit. Stupid bogo sort.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •