{
 "metadata": {
  "name": "",
  "signature": "sha256:0e20205326f04a5e99ede5d8b94b7c200c695a2b3e838b8a3cea1225057fbe26"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "The sum of the squares of the first ten natural numbers is,\n",
      "\n",
      "12 + 22 + ... + 102 = 385\n",
      "The square of the sum of the first ten natural numbers is,\n",
      "\n",
      "(1 + 2 + ... + 10)2 = 552 = 3025\n",
      "Hence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is 3025 \u2212 385 = 2640.\n",
      "\n",
      "Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum."
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "def squares(num):\n",
      "    for x in range(1, num, 1):\n",
      "        yield x ** 2"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 2
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "sum([i for i in squares(11)])"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 10,
       "text": [
        "385"
       ]
      }
     ],
     "prompt_number": 10
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "def total(num):\n",
      "    for x in range(1, num, 1):\n",
      "        yield x"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 7
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "sum([i for i in total(11)]) ** 2"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 12,
       "text": [
        "3025"
       ]
      }
     ],
     "prompt_number": 12
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "def square_difference(num):\n",
      "    x = sum([i for i in squares(num)])\n",
      "    y = sum([i for i in total(num)]) ** 2\n",
      "    \n",
      "    print y - x"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 15
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "square_difference(101)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "25164150\n"
       ]
      }
     ],
     "prompt_number": 17
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [],
     "language": "python",
     "metadata": {},
     "outputs": []
    }
   ],
   "metadata": {}
  }
 ]
}