Automatic commit performed through alias...

This commit is contained in:
Shaun Setlock
2020-08-02 21:06:44 -04:00
parent b7bfa36d06
commit d543702af9
8 changed files with 611 additions and 0 deletions

View File

@@ -0,0 +1,44 @@
# # Problem 9:
#
# [Euler Project #9](https://projecteuler.net/problem=9)
#
#
#
# >A Pythagorean triplet is a set of three natural numbers, a < b < c, for which,
# a2 + b2 = c2
#
# >For example, 3^2 + 4^2 = 9 + 16 = 25 = 5^2.
#
# >There exists exactly one Pythagorean triplet for which a + b + c = 1000.
# Find the product abc.
#
#
#
# ---
import os
import pprint
import time # Typically imported for sleep function, to slow down execution in terminal.
import typing
import decorators # Typically imported to compute execution duration of functions.
import math
import numpy
def get_c(a,b):
c = math.sqrt(a*a+b*b)
return c
def check_constraint(a,b,c,limit):
return (a+b+c)==limit
exit=False
for a in range(1,1000):
for b in range(a,1000):
c = get_c(a,b)
if check_constraint(a,b,c,1000):
#print(a,b,c)
#print(not_done)
exit=True
break
if exit:
break
print(a,b,c,a+b+c,a*b*c)

View File

@@ -0,0 +1,135 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Problem 9:\n",
"\n",
"[Euler Project #9](https://projecteuler.net/problem=9)\n",
"\n",
"\n",
"\n",
">A Pythagorean triplet is a set of three natural numbers, a < b < c, for which,\n",
"a2 + b2 = c2\n",
"\n",
">For example, 3^2 + 4^2 = 9 + 16 = 25 = 5^2.\n",
"\n",
">There exists exactly one Pythagorean triplet for which a + b + c = 1000.\n",
"Find the product abc.\n",
"\n",
"\n",
"\n",
"---"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Reserved Space For Imports\n",
"---"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"import pprint\n",
"import time # Typically imported for sleep function, to slow down execution in terminal.\n",
"import typing\n",
"import decorators # Typically imported to compute execution duration of functions.\n",
"import math\n",
"import numpy"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Reserved Space For Method Definition\n",
"---"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"def get_c(a,b):\n",
" c = math.sqrt(a*a+b*b)\n",
" return c"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"def check_constraint(a,b,c,limit):\n",
" return (a+b+c)==limit"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Brute Force!"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"200 375 425.0 1000.0 31875000.0\n"
]
}
],
"source": [
"exit=False\n",
"for a in range(1,1000):\n",
" for b in range(a,1000):\n",
" c = get_c(a,b)\n",
" if check_constraint(a,b,c,1000):\n",
" #print(a,b,c)\n",
" #print(not_done)\n",
" exit=True\n",
" break\n",
" if exit:\n",
" break\n",
"print(a,b,c,a+b+c,a*b*c)\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.3"
}
},
"nbformat": 4,
"nbformat_minor": 4
}