2018-02-01 16:45:03 +01:00
|
|
|
{
|
|
|
|
"cells": [
|
|
|
|
{
|
|
|
|
"cell_type": "markdown",
|
|
|
|
"metadata": {},
|
|
|
|
"source": [
|
|
|
|
"# Euler Problem 1\n",
|
|
|
|
"\n",
|
|
|
|
"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.\n",
|
|
|
|
"\n",
|
|
|
|
"Find the sum of all the multiples of 3 or 5 below 1000."
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
|
|
|
"execution_count": 1,
|
|
|
|
"metadata": {
|
|
|
|
"collapsed": true
|
|
|
|
},
|
|
|
|
"outputs": [],
|
|
|
|
"source": [
|
|
|
|
"def get_sum_of_natural_dividable_by_3_and_5_below(m):\n",
|
|
|
|
" return sum([x for x in range(m) if x % 3 == 0 or x % 5 == 0])"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "markdown",
|
|
|
|
"metadata": {},
|
|
|
|
"source": [
|
|
|
|
"Test example provided in problem statement:"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
|
|
|
"execution_count": 2,
|
2018-02-04 16:54:28 +01:00
|
|
|
"metadata": {
|
|
|
|
"collapsed": true
|
|
|
|
},
|
2018-02-01 16:45:03 +01:00
|
|
|
"outputs": [],
|
|
|
|
"source": [
|
|
|
|
"assert(get_sum_of_natural_dividable_by_3_and_5_below(10) == 23)"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
|
|
|
"execution_count": 3,
|
2018-02-04 16:54:28 +01:00
|
|
|
"metadata": {
|
|
|
|
"collapsed": false
|
|
|
|
},
|
2018-02-01 16:45:03 +01:00
|
|
|
"outputs": [
|
|
|
|
{
|
|
|
|
"name": "stdout",
|
|
|
|
"output_type": "stream",
|
|
|
|
"text": [
|
|
|
|
"233168\n"
|
|
|
|
]
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"source": [
|
|
|
|
"print(get_sum_of_natural_dividable_by_3_and_5_below(1000))"
|
|
|
|
]
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"metadata": {
|
2018-02-04 16:54:28 +01:00
|
|
|
"completion_date": "Tue, 19 Aug 2014, 20:11",
|
2018-02-01 16:45:03 +01:00
|
|
|
"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",
|
2018-02-04 16:54:28 +01:00
|
|
|
"version": "3.5.4"
|
|
|
|
},
|
|
|
|
"tags": [
|
2018-02-04 21:00:20 +01:00
|
|
|
"brute force"
|
2018-02-04 16:54:28 +01:00
|
|
|
]
|
2018-02-01 16:45:03 +01:00
|
|
|
},
|
|
|
|
"nbformat": 4,
|
|
|
|
"nbformat_minor": 2
|
|
|
|
}
|