Skip to content

Instantly share code, notes, and snippets.

@pybokeh
Last active January 3, 2016 20:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pybokeh/8513531 to your computer and use it in GitHub Desktop.
Save pybokeh/8513531 to your computer and use it in GitHub Desktop.
Project_Euler_1
{
"metadata": {
"name": ""
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"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",
"collapsed": false,
"input": [
"multiplesof3_or_5 = []\n",
"sum_numbers = 0\n",
"for num in range(1,1000):\n",
" if num%3==0 or num%5==0:\n",
" sum_numbers = sum_numbers + num\n",
"\n",
"sum_numbers = 0\n",
"for number in multiplesof3_or_5:\n",
" sum_numbers = sum_numbers + number\n",
"\n",
"print(sum_numbers)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"233168\n"
]
}
],
"prompt_number": 79
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"sum(multiplesof3_or_5)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 81,
"text": [
"233168"
]
}
],
"prompt_number": 81
}
],
"metadata": {}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment