Creating JN for Problem 11.
This commit is contained in:
135
problems/011_problem_jnotebook.ipynb
Normal file
135
problems/011_problem_jnotebook.ipynb
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user