{ "metadata": { "name": "", "signature": "sha256:9c59c68f373bfe20158abcb1cb5cca26b5671a13af43cb3e21284cd42d2b2abd" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "A Pythagorean triplet is a set of three natural numbers, a < b < c, for which,\n", "\n", "a2 + b2 = c2\n", "\n", "For example, 32 + 42 = 9 + 16 = 25 = 52.\n", "\n", "There exists exactly one Pythagorean triplet for which a + b + c = 1000.\n", "Find the product abc." ] }, { "cell_type": "code", "collapsed": false, "input": [ "def py_trip(num):\n", " for a in range(0, num, 1):\n", " for b in range(a+1, num, 1):\n", " for c in range(b+1, num, 1):\n", " if a**2 + b**2 == c**2 and a+b+c == num:\n", " return a, b, c, a*b*c" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 13 }, { "cell_type": "code", "collapsed": false, "input": [ "py_trip(1000)" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 14, "text": [ "(200, 375, 425, 31875000)" ] } ], "prompt_number": 14 }, { "cell_type": "code", "collapsed": false, "input": [], "language": "python", "metadata": {}, "outputs": [] } ], "metadata": {} } ] }