Project Euler # 1 "Multiples of 3 and 5" in Python

Problem 1 "Multiples of 3 and 5"

Of the natural numbers less than 10, there are four that are multiples of 3 or 5, and the sum of these is 23. In the same way, find the sum of the numbers that are multiples of 3 or 5 less than 1000.

Python


seq = range(1000)

result = 0
for i in seq:
  if i % 3 == 0 or i % 5 == 0:
    result += i
print result
print result == 233168

result


233168
True

Recommended Posts

Project Euler # 1 "Multiples of 3 and 5" in Python
Project Euler # 5 "Minimum Multiples" in Python
Project Euler # 16 "Sum of Powers" in Python
Project Euler # 17 "Number of Characters" in Python
Project Euler # 13 "Sum of Large Numbers" in Python
Project Euler # 6 "Difference in sum of squares" in Python
Functional programming in Python Project Euler 1
[Note] Project Euler in Python (Problem 1-22)
Functional programming in Python Project Euler 2
Project Euler # 15 "Lattice Path" in Python
Project Euler # 4 "Maximum Palindrome" in Python
Project Euler # 3 "Maximum Prime Factors" in Python
Project Euler # 11 "Maximum Product in Grid" in Python
Project Euler # 7 "1000 1st prime number" in Python
Project Euler # 9 "Special Pythagorean Triple" in Python
Project Euler # 14 "Longest Collatz Sequence" in Python
Project Euler # 2 "Even Fibonacci Numbers" in Python
Project Euler # 12 "High Divisibility Triangular Number" in Python
Explanation of edit distance and implementation in Python
"Linear regression" and "Probabilistic version of linear regression" in Python "Bayesian linear regression"
Calculation of standard deviation and correlation coefficient in Python
Difference between Ruby and Python in terms of variables
Equivalence of objects in Python
[python] Calculation of months and years of difference in datetime
Stack and Queue in Python
Unittest and CI in Python
Overview of generalized linear models and implementation in Python
Implementation of quicksort in Python
Source installation and installation of Python
Summary of date processing in Python (datetime and dateutil)
Sort and output the elements in the list as elements and multiples in Python.
What I learned by solving 30 questions of python Project Euler
Reference order of class variables and instance variables in "self. Class variables" in Python
Comparison of how to use higher-order functions in Python 2 and 3
[Python] Strengths and weaknesses of DataFrame in terms of time required
Environment construction of python and opencv
Pixel manipulation of images in Python
Project Euler 10 "Sum of Prime Numbers"
The story of Python and the story of NaN
MIDI packages in Python midi and pretty_midi
Difference between list () and [] in Python
Difference between == and is in python
Installation of SciPy and matplotlib (Python)
View photos in Python and html
Sorting algorithm and implementation in Python
Division of timedelta in Python 2.7 series
MySQL-automatic escape of parameters in python
About dtypes in Python and Cython
Assignments and changes in Python objects
Implementation of life game in Python
Waveform display of audio in Python
Check and move directories in Python
This and that of python properties
Ciphertext in Python: IND-CCA2 and RSA-OAEP
Hashing data in R and Python
Create Python project documentation in Sphinx
Function synthesis and application in Python
Export and output files in Python
Law of large numbers in python
Implementation of original sorting in Python
Project Euler 11 "Maximum product in grid"