Saturday, September 27, 2014

4 - Palindrome Product, Heads or Tails?

Important News:

Project Euler is back running at capacity.  You can now go ahead and make an account and save progress.

Problem

A palindromic number reads the same both ways.  The largest palindrome made from the product of two 2-digit numbers is \(9009 = 91 \times 99\).

Find the largest palindrome made from the product of two 3-digit numbers.

Background


Palindromes are not unique to math, in fact there is little inherently mathematical about them.  They existed first as a linguistic construct.  A coincedence in the arrangement of letters such that they read the same one way as the other way.  Some linguistic palindromes are "racecar," "rotor,"  "star rats," the name "Mike Kim," "A man, a plan, a canal, Panama," which coincides with the centenial aniversary of the Panama Canal's opening on August 15th,  and my personal favorite "Go hang a salami, I'm a lasagna hog!"

The same concept can be applied to numbers.  \(12321\) would be an example of a Palindromic number because if you reverse the digits then it would still have the same value.  To a computer though, there isn't much a difference between a number and a character, especially when determining if it is a palindrome.  A long time ago nearly everything on a computer was written in plain text, using ASCI character designations.  Where each character took up one byte of storage (a string of 8 binary digits)
ASCII Table
The characters in this table are represented by hexadecimal notation, which is just an easy way to represent base-2 numbers. Base-16 is like base-10, only it uses 6 extra digits to represent number, the digits are represented by the letters A-F, where A is 10, B is 11, and so on to where F is 15.  The letter 'A' in hexadecimal is represented as 0x41, which is 65 in decimal \(65 = 4 \times 16 + 1\), and in binary it is 0b01000001.  People who work with binary a lot like to use hexadecimal, base-16, or octal, base-8, because each digit will corespond to 4 or 3 digits of binary, respectively.  Binary is not dense notationally, and needing to write binary all the time would increase the chance of making a mistake, which would take time to correct.

A computer stores text as a list of characters, and a word, or even whole sentances can be written as just a list of the characters.  "racecar" would look like [0x72 , 0x61, 0x63, 0x65, 0x63, 0x61, 0x72] in memory, and "12321" would look like [0x31, 0x32, 0x33, 0x32, 0x31].  Notice that both palindromes look pretty similar, they are just a list of numbers.  So it really matters more about how the characters are structured than any property of the word or number itself.

If this problem concerned letters our job would be slightly more complicated.  We would have spaces, capital letters, and maybe even punctuation to worry about.  None of which effects what we would deem a palindrome.  Thankfully we are working strictly with number, which have no spaces or capitals, so we can look exclusively at the order.

The Math

In the context of this problem it is a little more useful to regard the palindromes as words, using characters instead of numbers.  That is not to say that we cannot use math to describe palindromic numbers.  And some interesting patterns arise after looking at a few candid examples.

\(0, 1, 2, 3, 4, 5, 6, 7, 8, 9\)  These numbers are all trivial palindromes.  They are single digits, and only have one digit to repeat.

\(11, 22, 33, 44, 55, 66, 77, 88, 99\) are two digit palindromic numbers.  Each is divisable by eleven.  And 11 has some more interesting palindromic properties.

The powers of 11 are palindromes up to 11^4
$$11^0 = 1 \\
11^1 = 11 \\
11^2 = 121 \\
11^3 = 1331 \\
11^4 = 14641 \\
11^5 = 161051 $$

11^5 is a combo breaker,  and arises because of carrying extra digits.

Likewise repeating strings of ones give an interesting result
$$1 \times 1 = 1 \\
11 \times 11 = 121 \\
111 \times 111 = 12321 \\
\vdots \\
111111111 \times 111111111 = 12345678987654321 $$

And I propose that every palindromic number with an even number of digits is divisible by 11.  We can throw the odd digit numbers out right away, 101 is a prime number, so by definition it is only divisible by itself and 1.  For two digit numbers this is pretty simple to see, we only need to look at the first 9 multiples of 11.  But I want to prove it for palindromes of 4 digits and 6 digits and 100 digits.  I'm going to do this proof, wrongly at first, by a method we saw in the last blog post, it is a form of proof by contradiction, it is the proof by least counter example.

Let us assume we have a number \(abc \ldots cba\)  this can be rearranged into
$$ a(10^k + 10^0) + b(10^{k-1} + 10^1) + c(10^{k-2} + 10^2) + \ldots + n(10^{k-n} + k^n)$$ where \((k-n) - n = 1\) or \(k = 2n + 1\)  put more clearly, \(k\) is odd.

To solve this I'm going to look at a more general problem, and use that proof in this one.  I propose that any number in the form of \(10^k + 10^j\) where \(k+j\) is odd is divisible by 11.  So first we need to constrain this equation a little bit.  \(k\) and \(j\) are both integers greater than or equal to \(0\).  \(k\) is strictly greater than \(j\) and as stated before, \(k + j\) is odd, or put another way \(k+j = 2m + 1\). Where \(m\) is a nonnegative integer.  Let's assume that the number \(10^k + 10^j\) is the lowest number fitting our constraints that 11 does not divide into.  We know that \(10^1 + 10^0 = 11\) is divisible by 11, so there is at least one instance where this identity holds.

$$
(10^k + 10^j)  = 10^j (10^{k-j} + 10^0)
$$

But in the expression that we get, k-j must be an odd number because we have already asserted k+j to be odd.  We are subtracting \(2j\) from \(k+j\) and adding or subtracting an even number from another number does not change its parity.  Parity is simply a term for a number being odd or even, and there is plenty of opportunity to talk about that in another post.  Anyways, the number in the parentheses also follows the form \(10^k + 10^j\) in this case k is replaced by k-j and j is replaced by 0.  This number is smaller than our original expression, because we factored out 10^j, but we are assuming that \(10^k + 10^j\) is the smallest number that can be expressed like that without being divisible by 11, so \(10^{k-j} + 10^0\) must be divisible by 11.  This means \(10^k + 10^j\) is also divisible by 11, because one of it's factors is.  This creates a contradiction, in our initial condition, that \(10^k + 10^j\) is not divisible by 11, so the premise is incorrect, there is not smallest number such that \(10^k + 10^j\) is not divisible by 11.

I've already told you that this proof is wrong.  And you can stop reading here if you want to figure the answer out by yourself, because I'm just going to give it away in this next sentence.  \(10^{k-j} + 10^0\) is not necessarily smaller than \(10^k + 10^j\)  because j can equal 0.  We could make the proof more correct by stating that j must be greater than 0, but then we would have to prove a new base case, and we would have to factor our \(10^{j-1}\) from our number.  And then we would have to create a corollary extending the proof to be more inclusive by saying we could just divide out a 10, and none of this would be very elegant.

There was a very famous and prolific mathematician named Paul Erdos, who was so prolific that many mathematicians in academics have an Erdos number, basically their degree of separation to Paul Erdos in research papers collaborations.  Think of the system like 7 degrees of Kevin Bacon.  Erdos himself was 0, a collaborator of his on any of his papers would have an Erdos number of 1, any people who collaborated with Erdos's collaborators, but not Erdos himself have an Erdos number of 2, and it goes on. Anyways, Erdos believed that a proof should be elegant. You could prove for example that \(a^2 + b^2 = c^2\) for right triangles in a crazy mathematically rigorous sort of way in a paper that is over 100 pages long.  Or you could show that due to similar triangles the ratios of the sides demand that \(a^2 + b^2 = c^2\) Erdos believed that even if two proofs demonstrated the validity, or invalidity, of a mathematical statement, the more elegant one was always more correct.

My more correct proof involves modular arithmetic sometimes called clock arithmetic.  The modulus operator we have already discussed.  It basically gives the remainder in a division problem.  A clock is modular 12 because even though the time keeps on advancing, we express the time as one of 12 hours, at least in the United States we do.  The modulus is excellent to describe things that are cyclical, and it is easier to work with numbers that follow cyclical patters, because the range that needs to be proved is reduced.

As it turns out, 10^n follows a cyclical and predictable pattern.  And instead of modulo 12 as in our clock example, we will use modulo 11.  Firstly, lets look at at few examples.
$$
10^0 = 1 \equiv 1 (mod \ 11) \\
10^1 = 10 \equiv 10 (mod  \ 11) \\
10^0 = 100 \equiv 1 (mod \ 11) \\
10^0 1000 \equiv 10 (mod \ 11) \\
$$

In modular arithmetic sometimes nice to express numbers in the negative.  It is perfectly okay to do this.  I like to think of the modulus less of a function and more of a way to say that some numbers behave the same if you look at them in a certain way.  So 10 (mod 11) is equivalent to -1 (mod 11)  You can think of it like a clock.   Going from 12, or 0, backwards an hour brings to to 11, or -1.  The hand would still be in the same place in either case, so they can be considered equivalent.

A pattern seems to have emerged, alternating between 1 and 10 in modulo 11, or 1 and -1 put another way.  Let's show that this is always the case.

$$
10^0 \equiv 1 (mod \ 11)\\
10^1 = 10 \times 10^0 \equiv 10 \times 1 (mod \ 11) \equiv 10 (mod \ 11) \equiv -1 (mod \ 11)\\
10^2 = 10 \times 10^1 \equiv 10 \times -1 (mod \ 11) \equiv -10 (mod \ 11) \equiv 1 (mod \ 11)\\
$$

Basically, any time a power of ten is equivalent to \(1 (mod \ 11)\) then multiplying it by 10 again will change it to \(-1 (mod \ 11)\) and vice versa.  The equivalent sign \(\equiv\) is like a equal sign, in that algebraic operations can be performed across it.  It just says that the terms on either side are not exactly equal, only that the first term can be represented in a logically consistent way with the second term.   So, we can say in one simple equation \(10^n \equiv (-1)^n (mod \ 11)\)

As a side note it can also be shown  \(\forall x: x^n \equiv (-1)^n (mod x+1)\).

When we add two powers of 10 to exponents of differing parity then one power will be equal to \(-1 (mod \ 11)\) while the other is equal to \(1 (mod \ 11)\).  The sum of these two numbers would be \(0 (mod \ 11)\) meaning the number is divisible by 11.

The Code:

That was a pretty lengthy post, and a bit longer than I was expecting.  And in typical fashion of this blog, I am not using what I just talked about in my code.  There isn't a point to knowing that 6 digit long palindrome numbers are all divisible by 11.  I mean, it's cool, but I wouldn't call it vital.   But just so what I wrote about wasn't a complete waste, I'm going to see if I can use that information to my advantage to narrow down the search by a factor of 11.

The design philosophy for my code takes a few differing paths to arrive at the same answer.  One is more top down, the other bottom up.  In my python code I am iterating through multiplying all 3 digit numbers together, and checking to see if the answer is a palindrome.  For my C code I am doing the opposite, generating all of the possible palindromes, and finding out if it has two 3 digit factors.  The burning question is which algorithm is more efficient.

You might think that because the python code is more brute-force like it takes more time to run, but there are some interesting optimizations that can be done.  For instance, instead of counting up, we can count down.  That helps since the largest palindrome product is more likely to be at the higher range of numbers.

Python:


largestPrime = 2

def isPalindrome(num):
    return str(num) == str(num)[::-1]

longpal = 1

for i in range(1000):
    for j in range(1000):
        if isPalindrome(i*j) and i*j &gt longpal:
            longpal = i*j

    
    
This code is a really simple brute force code.  My method of checking whether or not a number is a palindrome is a little wonky.  I first turn it into a string, then I use python's advanced string indexing to select all of the string, and the -1 indicates that I want it indexed backwards.  A little convoluted, but it works.

A few ways that I can improve the code is to tweak the range, we only want to check 3 digit numbers.  But this alone doesn't do too much for us.  We can also count down from j = 999, and all numbers after that are guaranteed to be lower, so we can just break the loop.  We also run into the issue where we are multiplying most numbers twice.  When i goes from 999 to 998, j will still start at 999, even though that was already calculated that multiple.  So we can start at i instead of 999 each time.  And for that matter, if i*i is less then the largest palindrome then we might as well stop there, because j is going to be less than i, so any palindrome found will be smaller and rejected anyways.  Since we already know the answer past that point, there is no point in checking it.  So here is the revised code, basically the same, but a few more breaks put in.


largestPrime = 2

def isPalindrome(num):
    return str(num) == str(num)[::-1]

longpal = 1

for i in range(999, 99, -1):
    if i*i &lt longpal:
        break
    for j in range(i, 99, -1):
        if i*j &lt longpal:
            break
        if isPalindrome(i*j) and i*j &gt longpal:
            longpal = i*j
            break
    

I timed out both programs and the difference is pretty apparent.  The first, brute force search took way longer than the second one.  It took 2.36 seconds compared to the optimized .0210 seconds. Two whole orders of magnitude out of just going backwards and knowing what stuff you don't need to check.

And I did manage to make the code a bit more optimized.  You know how I said I wouldn't be using that all even digit palindromes are multiples of 11 business. I may not have been telling the whole truth.  You can put it in the j loop when defining it by "for j in range(i - i%11, 99, -11)"  This will initialize j at the first multiple of 11 below i, and step j down in increments of 11.  So at least one multiple will always be 11.  Using this technique I managed to whittle the time down by another order of magnitude, to 2.00 ms.

Edit:  I realized that this technique only works coincidentally.  To implement it right there should be two j loops, one for when i is a multiple of 11 where j steps down by 1, and when i isn't divisible by 11, then j can be decremented by 11.

C:


#include <stdio.h>
#include <stdio.h>
#include <math.h>

main()
{
    int palindromes[1800];
    
    /*Populate palindromes*/
    /*6-digit numbers*/
    char i, j, k;
    int pos = 0;
    int p = 0;
    for (i = 9; i>=1; i--){
        for (j = 9; j >=0; j--){
            for (k = 9; k>=0; k--){
                p = i*(100001) + j*(10010) + k*(1100);   /*Middle digits*/
                palindromes[pos] = p; /*pos also = 100*(9-i)+10*(9-j)+(9-k) */
                pos++;
                p = 0;
            }
        }
    }
    /*5-digit numbers, for the lulz*/
    for (i = 9; i&g;t=1; i--){
        for (j = 9; j>=0; j--){
            for (k = 9; k>=0; k--){
                p = i*(10001) + j*(10010) + k*(100);
                palindromes[pos] = p; /*pos also = 100*(9-i)+10*(9-j)+(9-k) + 900*/
                pos++;
                p = 0;
            }
        }
    }

    /*Iterate through palindromes*/
    int axis;
    int a, b;
    for (i = 0; i<1800; ++i){
        axis = floor(sqrt(palindromes[i]));

        for (a = axis; a>=100; a--){
            for (b = axis; b<1000; b++){
                if (a * b == palindromes[i]){
                    break;
                }
                else if (a*b >  palindromes[i]){
                    break;
                    /*If the product is too larger, then there is no point
                    in going any larger*/
                }
            }
            if (a*b == palindromes[i]){
                break;
            }
            else if (a*b > palindromes[i]){
                break;
                /*Likewise, if the product is too small at b's largest,
                 then there is no reason a should continue decreasing*/
            }
        }
        if (a*b == palindromes[i]){
            break;
        }
    }
    
    printf("%d = %d * %d\n", palindromes[i], a, b);
}

The first part of this code simply generates an array of all the possible palindromes.  The rest of the code is what I used to find the factors of the palindrome.  It uses similar control points to the python code.  And the method of finding the factors is pretty similar to problem 2.  What the code says isn't really that interesting.  But what it does is.  This program does just the opposite of the python code.  Instead of taking factors and finding a palindrome, we are taking palindromes and finding factors.  I like to think that this code runs faster.  Generating the palindrome list effectively takes no time at all, and since we look from the high end of the list first we can disregard everything after we find a number with two palindromic products.

I did a little bit of math to find out how large of an array is needed, but the math isn't too hard.  It turns out that there are 1800 5 or 6 digit palindromes.  And I used 5 digit palindromes because two small 3 digit numbers can multiply together to get a 5 digit number, and an interesting thing to note is that there are exactly the number of 5 digit palindromes as 6 digit palindromes, 900 each.  I will let you figure out why.  And remember to keep tuning into this blog.  I don't update it often enough.  But the sizes of these posts really get up there.  And formatting stuff is not the easiest work.  Ta!


Friday, August 22, 2014

3 - Prime Factors and Foundations

The Problem

The prime factors for 13,195 are 5, 7, 13, and 29.

What is the largest prime factor of the number 600,851,475,143?

Background

Prime numbers hold a special place in mathematics.  There are super computers dedicated to calculating higher and higher primes.  And the distinction between prime and composite numbers was discovered early on.  There are indications that the ancient Egyptians knew about prime numbers, based on translations of the Rhind papyrus.  And by the ancient Greeks, around the time of Alexander the Great, people definitely knew about primes and were even crafting theorems about them.

Euclid, known as the father of Geometry, and famous for compiling almost all mathematical knowledge at the time into his great works Elements, has an interesting proof regarding the infinite nature of primes.

Lets assume that there aren't an infinite number of primes.  And somebody was able to give you list of prime numbers \(p_1, p_2, p_3, \ldots , p_n\).  Let's suppose you then multiply all the numbers on that list to get the product \(P = p_1\times p_2\times p_3 \ldots \times p_n\), and you add one to get \(Q = P + 1\).

\(Q\) can then either be prime, in which case there is at least one more prime,

or \(Q\) can be composite.  But none of numbers in the list of primes can divide \(Q\) evenly.  They are all factors of \(P\), but if you divide \(Q\) by one of the primes on the list you would get a remainder of 1.  But if \(Q\) is composite then there must be a prime factor that divides \(Q\).  That being the case there must be at least one prime number, not in the list that divides \(Q\).

This creates a contradiction, any list of primes of finite primes will reveal that there is at least one more prime than those listed, therefore, there must be an infinite number of primes.

This is all leading up to the Fundamental Theorem of Arithmetic.  Every branch of mathematics has its own fundamental theorem, and they can get pretty complex, but Arithmetic's is pretty simple.

Pretty much, any integer greater than 1 can be uniquely expressed as the product of one or more primes.  A product of one number is just itself.  So all primes have the trivial product of themselves.  And composite numbers can be expressed as primes.

For example:
$$ 10 = 2 \times 5 \\
12 = 2^2 \times 3 \\
14 = 2 \times 7$$

But don't take my word for it, here is the proof.

Proof by least counterexample:

Let's assume \(a\) is the lowest composite number which cannot be written as the product of primes.  \(a\) cannot be a prime number, because all primes numbers have the trivial product of themselves.  So there must exist at least two numbers \(b\) and \(c\) which are greater than \(1\) but smaller than \(a\), where \(a = bc\).

\(b\) and \(c\) must then be able to be written as the product of primes, since \(a\) is the smallest number which cannot be written as primes.  But, since \(a\) is the product of \(b\) and \(c\), which are themselves products of primes, \(a\) must therefore able to be written as the product of primes.  Since there can be no least composite number which cannot be written as the product of primes, all integers greater than 1 must be able to be written as a product of primes.


This proof isn't ground breaking, it doesn't reveal anything that isn't already intuitive.  Most kids learn prime factorization in school and quickly realize this without needing the proof.  And indeed, it may seem silly that such a proof is even needed.  But mathematics is a science that strives to make as few assumptions as possible.  It is founded on a few axioms, which cannot be proven to be true, but by reason they can be assumed.  But once a proof is made based on that axiom, other proofs can be created off of previous proofs.

There is a game I like to play called little alchemy that demonstrates this principle.  The game starts you off with four elements; earth, air, wind, and fire.  You can combine elements two at a time to form new things. Like dust, lava, and wind all the way down to zombies, cities, and sunglasses.  There are only sixteen ways to combine the beginning four elements.  But you can use what you made in the combination of these elements to combine with other objects.  This is similar to how simple axioms can be used to craft insane proofs, like there are infinite primes, or that there are no positive integers \(a, b, c\) such that \(a^4 + b^4 = c^4\).

Mathematics today uses what is called the Peano axioms for defining mathematics concerning the natural numbers.  These are complex, but they can be generalized like this.

  1. 0 is a natural number
  2. \(x = x\): A number is equal to itself
  3. if \(x = y\) then \(y = x\)
  4. if \(x = y\) and \(y = z\) then \(x = z\): This is called the transitive property
  5. if \(x\) is a natural number, and \(x = y\), then \(y\) is also a natural number.
  6. For every natural number \(n\), the next number \(S(n)\) is also a natural number.  \(S(n)\) is defined to be the successor function, and is equivalent to n + 1.
  7. \(S(n) = 0\) is false. There are no negative natural numbers.
  8. If \(S(n) = S(m)\) then \(n = m\)
  9. Induction holds, and the set of natural numbers contains \(0\), and \(S(n)\)

With these axioms we can prove that 1 is a natural number, the natural numbers are closed under addition, and all of number theory.  It's good to know that mathematics is founded on such simple concepts.

The Math

Finding primes is hard.  There is no prime number function where we can just plug in numbers and get the nth prime out of it.  Usually it is done by an algorithm which takes more and more time the larger the number is.  But not all algorithms are equal.  In programming we need to consider the order of the algorithm, which is basically the growth in the amount of time it takes to work on a larger input.  The way to describe the order is often called big O notation.  If we checked all the numbers below some given value for primes to determine if they divided our number it would be \(O(n)\), because we would a new value for each larger n, which isn't the best.  Even if we checked to half of 600 billion, and only checked the even numbers, it would still be \(O(n)\), because there is a linear growth rate, coefficients don't matter, even if that algorithm is 4 times faster.

We have another option.  We only really need to check up to the square root of a number to get prime factors.  If none of the numbers below, or including, the square root are factors, then that automatically makes the number prime.  If a number larger than the square root was a factor, it would have to be multiplied by a number smaller than the square root.

The main technique will be the same for both programs, they will both take the working number, divide out the lowest number which divides it, and make the dividend the new working number.  The difference is that one program will be O(n) and the other will be O(sqrt(n)).

The Code

Python:


The way we check in programming if a number is prime is to see if every number below the square root of that number doesn't divide into it.  Basically,

def isPrime(n):
    p = 2
    while n%p != 0 and p <= math.sqrt(n):
        p += 1

    if p > math.sqrt(n):
        return True

    else:
        return False

But there are improvements that could be made on it.  For one we are incrementing by one, which is slow and there is no purpose for.  We could save time instead by incrementing by 2, and only checking odd numbers, because no even number past two is prime.  But even if we do this we are checking numbers that we don't need to.  All the multiples of 3 and 5 and 7 don't need to even be there.  It would be so much more optimal if we could just check with a list of prime numbers that we have already generated, and passed along to the function.  An easy way to generate this list is using a technique called the seive of Erathmus.  Checking to the square root turns out to be fast enough for our purposes.


Code 1:

originalNum = 600851475143
maxPrime = math.ceil(originalNum/2)

#Check if number is divisible by two
n = 2
workingNum = originalNum
# a while loop is used in case the factor repeats
while workingNum % n == 0:
    workingNum /= n

#Check odd numbers
n = 3
while n < math.sqrt(workingNum):
    while workingNum%n == 0:
        workingNum /= n

    n += 2

print(workingNum)

The simplicity of this code is that we don't need to check if the factor is prime, only that it is a factor.  And in this case we were lucky because the largest prime is reletivily small.  Only a few thousand, even though it could have been a few hundred billion.  We got lucky, but it could have been the case that highest prime was much higher.  If that were the case we might want to skip more than the even numbers and we would do something like this.

Code 2:

import math
originalNum = 600851475143
maxPrime = math.ceil(originalNum/2)

#Check if number is divisible by two
n = 2
workingNum = originalNum
largestPrime = 0
# a while loop is used in case the factor repeats
while workingNum % n == 0:
    workingNum /= n
    largestPrime = 2

#Check odd numbers
n = 3
while n <= maxPrime:
    while workingNum%n == 0:
        workingNum /= n
        largestPrime = n

    n += 2

print(largestPrime)

You are probably interested in how these programs performed.  Both of them did pretty well.  Code 1 finished faster, but not by much.  I clocked it at about .0009999 seconds, while code 2 got about .002.  Twice as slow doesn't seem so bad, but that is because the answer to this problem is pretty low.  If we changed the original number by adding 1 the differences become more pronounced.  Code 1 finished in .001999 seconds, while Code 2 was much sloweer at 1.0999 seconds.  And if we chanced the input by adding 2, Code 1 finished in .11800 seconds, whereas Code 2 didn't finish, I left it running for over 2 minutes.

This shows a principle of flexibility.  Just because your code works for some values does not mean that it is good, or even works, for others.

C:

This is pretty much a clone of the python code, not much to add.  Except I will add the data type.  In C an int data type is usually between -2 billion and 2 billion.  The number we are working with is larger than this, so to prevent any overflow errors we are using a larger data type called a long long.  Which uses twice the space and can store numbers between -9 quintillion and 9 quintillion.  or \(-2^{63}, 2^{63}\).  We probably won't be needing a datatype larger than this.
#include <stdio.h>
#include <math.h>

#define ORIGINAL 600851475143

main()
{
    long long working = ORIGINAL; /*Cast as a double because too large for int*/
    int p = 2; /*The first prime, and the variable we will increment*/
    int max = ceil(sqrt(ORIGINAL));
    
    /*Check for case 2*/
    while (working%p == 0){
        working /= p;
    }
    p++;
    
    /*Check over odd numbers*/
    while (p < sqrt(working)){
        while (working%p == 0){
            working /= p;
        }
        
        p += 2; 
    }
    
    printf("%d\n", working);
    
}


Tuesday, August 5, 2014

2 - Fibonacci Numbers and the Start of Modern Mathematics

The Problem:

Link
Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:

1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...

By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.

Background:

When we think of great European mathematicians our minds tend to go to two places, either the the Greeks, like Euclid, Archimedes, or Pythagoras, who basically perfected the math of Geometry.  Or our minds go to the 16th and 17th century mathematicians, EulerLeibniz, or Newton.  But rarely do we think of people from from the High Middle Ages.  But without the work of Leonardo of Pisa, who you may also know as Fibonacci, we might not have seen the latter European mathematicians.

Fibonacci is probably most known for the famous Fibonacci sequence.  For those unaware this sequence traditionally starts with 0 and 1.  Each next term in the sequence is generated by adding the previous two. So you wind up with the following sequence of numbers \(0, 1, 1, 2, 3, 5, 8, 13, ...\)  The fibonacci sequence shows up a lot in nature and in places in mathematics where you wouldn't expect it.  However, I would argue that this sequence is probably one of his least important contribution to the field.  His biggest contribution was something that he didn't even invent.  In my opinion, Fibonacci's greatest achievement was in popularizing the Arabic numerals, and introducing zero to Europe.

The number 0 is an important number.  Technically its introduction only added one number over the previous system, and numerically it represents nothing.  But zero's impact is more about how number are thought of.  With 0, numbers become playthings.  They are more abstract, ethereal, but they become more like objects. Before zero was introduced numbers represented a count, a description of something.  A number could be a count of sheep in the field, or the acres of land owned by a lord, or the number of regiments in an army, or the salary that each one was paid.  There was no reason to have the number 0, because you didn't have to represent nothing as a number.  No one would have said I have zero sheep grazing in the field.  They would have said there is no number, because none of them were grazing.  Back at this time those who did math, merchants, bankers, and tax collectors, would use roman numerals.  This system, instead of using digits in a specific base, worked more like a tally system.

Num Numeral Num Numeral Num Numeral Num Numeral
1 I 6 VI 20 XX 500 D
2 II 7 VII 30 XXX 1000 M
3 III 8 VIII 40 XL 2014 MMXIV
4 IV 9 IX 50 L 1776 MDCCLXXVI
5 V 10 X 100 C 1202 MCCII

To be able to do math with Roman numerals with any sort of efficiency a person would need to use an abacus.  Adding was simple enough, it was more difficult to perform multiplication, and very difficult to exponentiate.  That might have been part of the reason why European mathematics didn't advance much before this time.

Allow me to deviate from the math of the times, to something a little more modern.  I recall a story from the autobiography of one of my favorite physicists, Surely You're Joking, Mr. Feynman, by Richard Feynman.  A cursory search on YouTube found this clip from the movie Infinity, though this movie takes artistic liberty with the version in the autobiography, it has the right spirit.  The actual story goes that one day, while in a restaurant Feynman came across a Chinese man trying to sell an abacus.  One thing led to another and Feynman found himself in a contest seeing who could tabulate the fastest him with a pen and paper, the salesman with an abacus.  One challenge was to add a bunch of numbers together, and the abacus won that in a landslide.  The next challenge was multiplication, and this round was much closer, though the man with the abacus won by a hair.  The last challenge was to find the solution to a cube root, and Feynman blew the salesman out of the water. By the time the man with the abacus answered, Feynman was figuring out what the fifth and sixth digits after the decimal were.

This story reflects what was happening in Europe regarding mathematics between 1200 and 1700.  Algorismists and abacists were at odds debating the best way to manipulate numbers, and it really wasn't until Leibniz that the algorismists won definitively.  The mathematics of the Renaissance and Enlightenment demanded a more flexible number system, and by the time calculus came around, math required it.  It was Fibonacci who first introduced algorism to Europe, treating numbers as something other than a count.  It would be a long transition, but Fibonacci can and should be credited with getting the ball rolling on it.

Fibonacci.jpgNot too much is known about the life of Leonardo of Pisa.  We can estimate that he was born around 1170 to a wealthy merchant in Pisa.  Because his father was a merchant Leonardo got to travel to various trading ports with him and help his father sell his wares.  One of the places his father traded was a North African trading post, in modern day Algeria.
We should remember the time period Fibonacci is operating in. When we think back to the early 13th century we think of the era that is backwards.  I won't attest to the veracity of this claim, I'm just a simple blogger, but the idea that the time after the fall of the Roman Empire in the 7th century up to the 15th century was a Dark Age has been with us since the Renaissance.  During this time, the Catholic Church dominated the life and politics of the age.  During 1202, when Fibonacci was writing his Liber Abaci, Europe was between the third and fourth crusade.  The infamous Enrico Dandolo was the Doge of Venice. There were knights and serfs, feudalism and manorialism.  The Black Death, which started in the 1340s, was still over a century away.


Algeria at this time was under the rule of a Muslim sultan of the Almohad dynasty.  The native merchants, and those traveling from the middle east used numbers which were very different than what Leonardo would have been accustomed to.  The Almohads used a number system which was given to them by the Arabs, which was introduced to them by the Hindus.  The system is what we now call Arabic numerals, or Hindu-Arabic numerals if you care to be more politically correct.  This is the number system we use today, using the digits 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9 to represent any conceivable number in base-10.  I assume you are familiar with it, so I won't explain it further, but if you care to see a documentary about the number system, narrated by Terry Jones, of Monty Python fame, check out this link.  At this point in history the Indians and the Arabs are centuries ahead of Europe mathematically.  They regarded negative numbers as numbers in their own right, not as absurd numbers as Europeans would regard them well into the 16th century.

I can imagine Leonardo walking through the Berber market, young and curious.  All of the merchants know him, he walks around often, and they call him "Fibonacci" meaning son of a simpleton.  He might ask to see the records of sales from one of the merchants, and be introduced to some strange system of math.  He asks what the symbols mean and is drawn to the logic and simplicity of them.  I can also imagine him staying awake by candle light after his father had packed up all his goods onto the trade ship.  He is a child, and he does what kids do, play.  He takes the numbers and adds them together in new patterns, he squares them and multiplies them.  It was at this point that the young Fibonacci might have asked his father permission to travel the Arab world and learn what there is to know about this new and beautiful math.  And he did travel, and he didn't return to Pisa until the turn of the century, in 1200.

In 1202 Fibonacci wrote his famous Liber Abaci.  He then toured Europe, going on one of the first book tours in Europe. He was pitching the Arabic numeral system like a salesman might pitch you a car.  One of the surprising parts of this story is that he was largely successful.  Could you imagine as a merchant at this time some guy who's name means "son of a simpleton" come up to you and says, "you know that way you and everyone else count, it's wrong.  And by the way, the Muslims have a much better system."  I'm not sure to what esteem the merchants held the Muslims, but there were ongoing crusades in Europe at this time.  Which might have been why the number system took so long to introduce.  To the Europeans at the time, this was the enemies of Christendom number system, and Roman numerals had worked just fine for the greatest empire the world had seen up to that point, which was the Roman Empire of course.  But Fibonacci was successful, merchants started using Arabic numbers; the number system stuck.  And his success just goes to show how much better it was for merchants to use Arabic numerals in their accounting.

Eventually the Holy Roman Emperor Frederick II took note of Fibonacci.  And Frederick II wasn't your typical emperor, at least, he wasn't the type of guy who comes to mind as Imperial.  He became King of Sicily when he was 4, King of the Germans by age 18, and was elected Holy Roman Emperor at age 26.  But, instead of spending his time in Germany he stayed in Sicily for most of his life.  He founded the first secular university in Naples, and he collected philosophers and poets like they were Pez dispensers.  He had good relations with the Islamic sultan in the Middle East, yet detested by the Pope. He was practically given the city of Jerusalem by the sultan Al-Kamil.  Possibly becoming the only person in history to peacefully take control of the region.  Yet he was excommunicated, twice by Pope Gregory. 

Fibonacci moves to the court of Emperor Frederick II where he is given a salary, and becomes one of the first state sponsored mathematician.  Fibonacci continued working until his death some time between 1240 and 1250, dedicating one of his last books, Liber quadratorum, aka The Book of Squares to the Emperor Frederick.

So, Fibonacci was one of the first mathematicians in Europe since the classical age.  And we can credit him, if not for the invention, then at least the revival of doing math for math's own sake in Europe, and the mathematical paper.  He did then what we are doing now.  Solving problems unknown to him using the tools that math gave him for no other reason than because he enjoyed it.  Unfortunately Fibonacci is really only remembered for a silly sequence for calculating the population of rabbits over.  This silly sequence could probably be thought up by a four year old just learning how to add, but it still has a few secrets.  And fortunately, there is another problem down the road where I can go very much into detail about the magic behind the sequence. This has the added benefit of sparing you from reading even more, I do tend to ramble on these things.  So in the spirit of Fibonacci, we can finally start the problem.

The Math:

The problem asks us to sum numbers in the Fibonacci sequence, and as it turns out there is a formula to help us find it.  As with the last problem, we could create all of the Fibonacci numbers, check if each is divisible by two, and add it to a rolling sum.  But as is often the case with these problems, there is another way to do it.

n F(n) Sum
1 1 1
2 1 2
3 2 4
4 3 7
5 5 12
6 8 20
7 13 33
8 21 54
9 34 88
10 55 143

If the pattern of isn't obvious then I'll just outright say it, the sum of Fibonacci numbers \(F_n\) is \(F_{n+2} -1\).  And there is a neat proof for this fact, but before I start, it might be worth talking about proof by induction.

Induction is a very poweful proof technique.  The premise of inductionis that if you can prove that the statement for n also implies n+1, and you can prove the statement for some number n, usually 1 or 0, then the proof will hold all the way down the line of natural numbers.  Induction has been comparted to dominos, if you can prove that a domino will push the domino in front of it down after it falls, and you can also prove that the first domino has been pushed, you can prove all the dominos will fall down.  It may be easier to figure out induction after seeing it.
First I'm going to define some numbers:
\( F_0 = 0, F_1 = 1, F_2 = 1, F_3 = 2\)
We want to prove that:
 $$\forall n \ge 1 : \sum\limits^{n}_{i=0}F_i = F_{n+2} - 1$$
So we prove the base case \(n = 0\)
$$F_0 = F_2 - 1 = 1 - 1 = 0$$
So the basis holds.

Now we prove the induction hypothesis:
$$\sum\limits^{k}_{i=0}F_{i} = F_{k+2} - 1 \implies \sum\limits^{k+1}_{i=0}F_{i} = F_{k+3} - 1$$
$$\begin{align}
\sum\limits^{k+1}_{i=0}F_{i} & = \sum\limits^{k}_{i=0}F_{i} + F_{k+1} \nonumber \\
& = (F_{k+2} - 1) + F_{k+1} \nonumber \\
& = (F_{k+1} + F_{nk+2}) -1 \nonumber \\
& = F_{k+3} - 1\nonumber \\
\end{align}
$$
 So \(P(k) \implies P(k + 1) \)

Therefore:
 $$\forall n \ge 1 : \sum\limits^{n}_{i=0}F_i = F_{n+2} - 1$$

Induction seems a bit like a magic trick to me.  You start out saying you want to prove some statement, you assume that it's true, do a bit of math, and then suddenly it becomes true.  It feels like we are using a word in the definition of that word.

When we look at the sums of the even Fibonacci numbers, there is no immediate patter that arrives, however, let's remember that each successive term in the Fibonacci sequence is equal to the sum of the two preceding terms.  By excluding every odd number we are really just dividing the sum of all the numbers in half.

$$\begin{align}
S & = 1 + 1 + 2 + 3 + 5 + 8 + 13 + 21 + 34 + \ldots \nonumber \\
S & = (1 + 1) + 2 + (3 + 5) + 8 + (13 + 21) + 34 + \ldots \nonumber \\
S & = (2) + 2 + (8) + 8 + (34) + 34 + \ldots \nonumber \\
S & = 2*2 + 2*8 + 2*34 + \ldots \nonumber \\
S/2 & = 2 + 8 + 34 + \ldots \nonumber \\
\end{align}
$$

n F(3n) Sum 2*Sum
1 2 2 4
2 8 10 20
3 34 44 88
4 144 188 376

In this table, I use F(3n) to denote the even Fibonacci numbers, which occur at every third index.  If we add 1 to twice the sum we get 5, 21, 89, and 377 which are the Fibonacci numbers of index 5, 8, 11, and 14 respectively.  Those indexes follow an arithmetic sequence, and can be described as \(F_{3n+2}\).  There is a proof for this, but it gets a little hairy, and there isn't much point relaying it here.  The formula for the sum of even Fibonacci numbers is: 
$$\sum\limits_{i = 0}^{n}F_{3i} = \dfrac{F_{3i + 2}-1}{2}$$

Unfortunately, this equation is useless to us.  I fooled you.  We don't know what position the index of the highest Fibonacci number below four million, and even if we did, adding numbers isn't hard for a computer to do, in fact, it's what a computer does best.  The amount of time you save computing the next two terms in the Fibonacci sequence as opposed to keeping a rolling sum, if any, is minimal.  Now, there is a way to calculate the nth Fibonacci number using only the index n, and knowing nothing else.  But that will have to wait for for the next Fibonacci post.

The Code

Python

Okay, even though I just said it was useless, I'm showing you the strategy for finding Fibonacci numbers.  One thing to keep in mind is that we don't know what the highest Fibonacci number under 4 million is.  There are three cases, that the highest Fibonacci number under 4 million is even, the one before that is even, or the one before that is even.

#Find the sum of the even Fibonacci numbers under 4000000
MAX = 4000000 #Highest number possible in the sequence
lastnum = 1
num = 1

while num < MAX:
    num += lastnum
    lastnum = num - lastnum

#num is even
if num & 1 == 0: 
    finalnum = num + (num + lastnum) #The Fibonacci number n+2
    print((finalnum -1)/2)

elif lastnum & 1 == 0:
    finalnum = num + lastnum
    print((finalnum-1)/2)

else:
    finalnum = num
    print((finalnum-1)/2)0

You might have noticed in my code that I'm not using a modulus operator (%) to check if a number is divisible by two, and therefor even.  Instead I'm using an ampersand (&) which is a bitwise and operator.  By 'anding' the number with one I'm effectively ignoring everything but the last digit of the number, which can either be 1 if the number is odd, or zero if the number is even.  This is slightly more efficient to use than a modulus operate, though not by much.  It would mean much more if I was checking evenness within a loop.  Just thought I would share some new notation.

My method for calculating fibonacci numbers might be a little confusing, but "num" changes its value before it is used to change the value of "lastnum."  So "num" becomes the next item in the sequence, and I am undoing that number to get teh original num, then assigning that value to last num.

Running a time benchmark, this code takes pretty much exactly 5 milliseconds to complete.  Not to shabby, but I won't be breaking any records.

C

As with the last problem, I did this problem slightly differently with C.  I'm keeping a running total of each instance where the sum is even.  Except, I'm not checking to see if a number is even, I already know that every third number is even.  I'm not doing the trick with the bitwise and, but the effect is still similar.
#include <stdio.h>

main(){
    int fibo, lastf;
    int summa;
    int i;
    lastf = 1;
    fibo = 2;
    
    i = 0;
    while (fibo < 4000000){
        if (i == 0){
            summa += fibo;
        }
        fibo += lastf;
        lastf = fibo - lastf;
        i = (i+1)%3;
    }
    printf("%d\n", summa);
}   

This program goes way faster, mostly because it is in C, about and doesn't have to deal with an interpreter. About 21 microseconds.  Comparing times from python to c is like comparing the lap time of a sprinter and a marathon runner.  They aren't competing in the same event, so it's pointless.  If you want to make something out of the times, try writing your own problem and see if you can do better.

Thursday, July 31, 2014

1 - Sums of Multiples

Problem 1:

If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9.  The sum of these multiples is 23.

Find the sum of all the multiples of 3 or 5 below 1000.

Background:

Mathematicians like to tell the story of a young Carl Gauss, a mathematician who made some very important advances in number theory, statistics, and electrostatics.  In some ways he has become mythologized, as is often the case with great historical figures.  A legend is told, passed down, and altered on each retelling.  The story becomes part of the culture of what ever group "owns" the story, and its members take pride in it.  There are dozens of such stories; King Arthur and his knights of the Round Table, Saint Benedict escaping being poisoned through divine intervention, George Washington refusing to lie after chopping down a cherry tree.  But the story I am about to tell regards a very young Carl Friedrich Gauss simply answering a question in math class.

When Carl Gauss was a child, we would call a tween by today's lingo, he attended school like any other boy his age. He lived in the Brunswick region of what was then the Holy Roman Empire. He was born in 1777, so by the time this event was taking place he would be about 13, making the year about 1790. This is a time where Europe is starting to enter what I consider to be the modern age. The United States had just won their Revolutionary war, and the French were in the throws of their own Revolution.

Carl Friedrich Gauss.jpgCurrently there are many stereotypes about Germans, one of the most notable being that they are very strict.  This stereotype also existed back in the 19th century, and it can also be inferred that the Germans were strict at the tail end of the 18th as well.  So, the young Carl Gauss was in class, and, as the story goes, the school master was fed up with his students goofing around.  As a punishment he told his students to add up the numbers from 1 to 100.  The school master expected the students to take some time with this problem.  At the very least a few minutes, but he was surprised when Carl Gauss, nearly instantly came up to him, and gave the answer 5050.  The school master was shocked one of his students found the answer so quickly.  He didn't know if this was correct off the top of his head, so he took out a very large book of problems and answers.  He found that Gauss was exactly correct in his calculation.  He hadn't missed carrying a digit or anything.

So how exactly did Gauss add up 100 numbers so quickly.  Was he a savant, like Rainman?  Well, no, he realized a very special pattern between the numbers.  All of the other kids in the classroom were doing what the school master intended.  They took one added two to get three, then added three to that and got six, added four and got ten, and so on.  Gauss realized that you could add the sum again, only in reverse order, to make the problem much easier.

$$ S = 1 + 2 + 3 + ... + 100 \\
S = 100 + 99 + 98 + ... + 1 \\
S+S = (100 + 1) + (2 + 99) + ( 3 + 98) + ... +(1 + 100) $$

Each of the sums in parentheses is clearly equal to 101, and since there are 100 instances of that sum we get the clean equation:
$$2S = 100*(101)$$
From here, it's trivial to solve, the product \(5050\) becomes easy to obtain.

More generally, the sequence is called an Arithmetic Sequence, i.e. a sequence in which any two consecutive terms share a common difference.  The sum of an Arithmetic Sequence is:
$$\sum\limits_{i = 1}^{n}a_i = \dfrac{n*(a_n+a_1)}{2}$$

The line of thinking Gauss used to get this answer so quickly is exactly the same line of thinking we need to solve Project Euler problems.  If each problem is a castle, then at the front of it will be walls, moats and ramparts, which will take time to get through.  Alternatively we could storm the castle by taking the secret entrance.  Gauss found that secret entrance to the problem of adding up arithmetic sequences, and in this problem we will put the same principle to use.

The Math:

The sum of a multiples of \(a\) is \(a*(1+2+3+...) = a*\frac{(n)(n+1)}{2}\) where \(n\) is the number of digits in the series.
So the sums of the multiples of 3 and 5 are:
$$ S_3 = 3 + 6 + 9 + 12 + 15 + ...  + 999\\
S_5 = 5 + 10 + 15 + 20 + ...  + 995 $$

As you might have noticed we cannot simple add these two sums together and get our answer, both of these sums include 15, in fact, they include all multiples of 15 less than 1000.

Thanks to what is known as the Inclusion-Exclusion Principle, which states that the union of two sets is equal to the sum of the two sets minus the intersection, we can solve the problem.  What this means in plain speak is we have twice as many multiples of 15 than we need, so we can subtract it out.

The basic formula for the sum of an arithmetic series is \( S = a * \dfrac{n*(n+1)}{2}\) where \(n\) is the number of numbers to add up.  The largest multiples of 3, 5, and 15 below 100 are 999, 995, and 990 respectively, so \(n\) for each would be 333, 199, and 66.

$$Ans = 3*\frac{333*334}{2} + 5*\frac{199*200}{2} - 15*\frac{66*67}{2}$$

To avoid divulging the answer to the puzzle, I will ignore explicitly stating it.

The Code:

Python:

Easy stuff here.  Basically just copying the line from above.

print(3*333*334/2 + 5*199*200/2 - 15*66*67/2)

Another cool python program that I found, note: I did not write this code, involves list comprehension.  there is a neat trick in python where a for loop statement can be used as an iterable object.

print(sum( x for x in range(1000) if x%3 == 0 or x%5 == 0))

This code automatically generates a list of multiples of 3 or 5 below 1000, and prints the sum.  In one line.  That is pretty wild.

If you don't recognise what the % sign means, it is called the modulo operator.  The expression x%n would give the remainder if you divided x by n.  For example 19%4 equals 3, because 19/4 is 4 with a remainder of 3.  If the remainder is 0, that means x would be divisible by n.  n times some number will give you x, meaning, by definition, x is a multiple of n.  Since this is what we want to find out, whether a number is a multiple of 3 or 5, it is used in the code.

Note, this kind of code is what many would consider to by "un-Pythonic."  It skirts understandability in favor of creating the shortest program possible.

My own code is pretty similar in that regard,  it would have been better if I defined the sums before instead of using numbers which seemingly come out of nowhere.  Those numbers are what are known in the programming world as "magic numbers."

Future problems will be much more complicated and I will do well to avoid them.

C:

I did something similar in C to that last python code.  But instead of calling the sum function, which there isn't in the default C, I had a variable called sum, which I added to if a number was a multiple of 3 or a multiple of 5.  When the loop terminates I print out the value of sum.

#include <stdio.h>

main()
{
    int sum;
    sum = 0;
    int i;
    for(i = 0; i<1000; ++i){
        if (i%3 == 0 || i%5 == 0){
            sum += i;
        }
    }
    printf("%d\n", sum);
}

Well, there it is, my first blog post.  I hope you enjoyed reading it as much as I did writing it.  I'm not exactly sure if I'll have a schedule.  All I can say is the next post will be out when it comes out.

0 - Introduction

About this Blog:

Recently I found out that Project Euler had been hacked.  While I found it terribly ironic that makers of a site dedicated to practicing programming skills fell victim to black-hat attack, the news of the outage also rekindled my interest in Project Euler.  I have played around with Project Euler on and off over the past three years, starting when I was just learning Python. Now that I am older, and know a thing or two more about programming, I want to try again.

So, I started doing the problems again, and on each new algorithm I wrote I found my comments getting longer and longer.  I pretty quickly realized that I had a lot to write about, and there might be other people interested in what I have to say.

I have always said that math is my first love, and math is largely what Project Euler is about.  Many of the problems can be solved using easy, brute force code style, but they might take minutes, if not longer to complete.  More often there is a little math trick which will create a short cut and let you solve the problem in an efficient manner.

Each blog post will contain the problem, the setup, and my code I used to solve the problem.  I will avoid explicitly stating the answer to the problem, because that defeats the purpose for those of you who haven't done PE.  I would also like to go into the theory, share anecdotes and derivations of formulae.  Actually, this section will most likely be the meat of the post, and what I will spend most of my time writing.  In the end, I want this blog will be less about the problems themselves than it is about the theory behind the problems.

About Project Euler:

Project Euler is a site for people who love to solve puzzles.  The puzzles range in difficulty from pretty gosh darn easy to graduate level mathematics.  Often times the problems will deal with special sequences of numbers, number theory, combinatorics, and linear algebra.  The problems are designed with a 1-minute rule.  That is, each solution should take less than one minute to complete.

The Project is named after one of the most prolific, and in my opinion, the greatest mathematician of all time, Leonhard Euler (Pronounced Oiler ).

According to Wikipedia, Project Euler was started in 2001 by Colin Hughs, since then the website has "gained notability and popularity worldwide."  On June 15th PE was temporarly shut down due to a security breach.  Shortly thereafter the site restarted in a stripped down state, as a read only website.

The Project Euler website is now back online in a limited fashion.  You can go there and look at the problems, and verify answers.  But there are no longer any badges and you can't keep any saved progress.  The owners of the website have said they plan on bringing the site back up to its full capacity soon though, just as soon as they work out the security issues.


About Me:

My name is Joseph Moore. I'm currently an undergraduate Computer Engineering major attending Northeastern University, and I have a passion for mathematics and computer science.  Years ago, I started programming with Python and have really grown to love the language and I am currently learning C.

My hobbies include running, reading, history, video games, especially Minecraft and Europa Universalis IV.  I'm currently working with a startup company based in Rochester as a summer intern.


Languages Used:

Pure Math:  In every area that is reasonable I will include a pure calculation, that is non-program assisted solution.  Some of the answers really are that easy to find, but not that many.

Python 3.4:  Keeping up to date with the latest version of python.  Code I may showcase from others might be based off of Python 2.x.  If it is too different from the counterpart in Python 3.x, I will provide an addition example.

C:  The lingua franca of the Linux/Unix community.  I'm still learning, so I don't know too much about it but feel free to point out how I could write it better.