RSS

Coding Challenge

19 Jun

Recently, there have been a couple new revelations about number theory published in Science Within the article was a pair of theories about prime numbers that I had never heard before, one of which was:

Goldbach’s conjecture, [which] makes two assertions: that every even number greater than 2 is the sum of two primes, and that every odd number greater than 5 is the sum of three primes.

I thought it would be fun to start with the first part of this problem and write a program to accept user input in the form of an even integer > 2  and then look for the two primes whose sum is equal to the user provided:

Goldbach_partitions_of_the_even_integers_from_4_to_28_300pxprime1 + prime2 = user input

where prime1 and prime2 may be any prime number (even the same number twice)

I could easily see this escaping the processing power of my machine if the numbers get high, but I think it shouldn’t be too hard to at least write a code that could look for them and demonstrate whether this worked with known input.

Are you up for a quick challenge?

zombie locker

Learn Fractions with Zombies

If so, submit your documented answer here as a comment. Feel free to use any language you would like (I just did it in C++, but I’m eager to see better answers than my own). My favorite submissions will win a free copy of  my iBook, In Parts, Tales of Fractional Zombies, which you can enjoy yourself or regift to a youngster in your life who wants a fun way to learn the concept of fractions.

You can use these links as resources to help check your work:

prime numbers       prime checker

If you are new to coding and are looking for a coding environment to work in, check out this posting for help setting up a C++ coding environment using Xcode (on your mac)

 
7 Comments

Posted by on June 19, 2013 in Codecademy, Coding

 

Tags: , , , , , , , , , , , , ,

7 responses to “Coding Challenge

  1. Eric

    June 25, 2013 at 11:22 pm

    Hey sorry I’m a bit late, let me know what you think of it!

    The code’s here
    http://pastebin.com/9GTC1NK6

    and you can run it here under Python
    http://labs.codecademy.com/

     
    • downhousesoftware

      June 26, 2013 at 8:47 am

      Thanks for submitting a solution. Your code looks great.
      Could you provide a little more instructional documentation? For instance, how does each chunk of code get you to your answer? Think educationally descriptive rather than documentation for other programmers. (just a few quick statements is enough)

      So far, all my entries are in python. It really is the go-to language for so many people now.

       
  2. Russel Walker

    June 27, 2013 at 1:26 pm

    Yet another Python entry 🙂

    http://pastebin.com/GvrwZetj

     
  3. Helton

    July 13, 2013 at 12:23 am

    Hi, @downhousesoftware!

    Here is my numerical solution to Golbach’s Conjecture.
    There are 2 files:

    1) Minimal (no documentation or tests, but more simpler to read):
    http://pastebin.com/kzbu4VfR

    2) Complete (with documentation and tests)
    http://pastebin.com/T6sT77cw

    Realize that the goldbach_conjecture function can be reduced to 1 line! But I preferred keep the functions calls (it’s more “understandable”)

    Helton

     
    • downhousesoftware

      July 13, 2013 at 8:54 am

      Thanks for the entry Helton – I’m taking a look at your code now and it looks nice and lean. I am having some trouble running it…getting strange error messages, although it is also giving me your output at the same time and it all looks good.
      I’ll come back to this in a bit and see what I’m missing here. Thanks for the entry!

      -Jack

       
      • Helton

        July 13, 2013 at 12:50 pm

        Hi, Jack
        I’m not sure if you’re running this script using Python 3.x, because it’s not compatible with version 2.x (the incompatibility is caused by “print”, because in Python 3.x it’s a function and in Python 2.x isn’t.
        I pasted the script in Codecademy Labs to you. I only altered the print function calls and I commented the last three tests (because they’re very slow to compute)…
        Realize that I didn’t mind with performance of this script, but it can easily increased (increasing the difficulty to understand too, sure)
        Any doubts, let me know

        http://labs.codecademy.com/BNwF#:workspace

         
    • downhousesoftware

      July 16, 2013 at 2:56 pm

      Helton:

      Thanks for sharing your code on this project. It was a novel approach compared to the others I received (or my own). You also did a lot more with fewer lines than probably everyone else.
      The challenge was closed by the time you submitted your answer, but I am going to have a free weekend for my iBooks (which was the prize) this coming weekend. Check back here later for details.

      Jack

       

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

 
%d bloggers like this: