project_euler/problem_10 by itsvinayak · Pull Request #1089 · TheAlgorithms/Python · GitHub
Skip to content

project_euler/problem_10 - #1089

Merged
cclauss merged 4 commits into
TheAlgorithms:masterfrom
itsvinayak:master
Jul 31, 2019
Merged

cclauss merged 4 commits into
TheAlgorithms:masterfrom
itsvinayak:master

Conversation

@itsvinayak

Copy link
Copy Markdown
Member

edit new solution using sieve-of-eratosthenes to solve problem 10 of project Euler

@cclauss cclauss left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool! Thanks for your contribution. A few minor requests...

  • Longer variable names because l, i, j, s look kinda old school. Can you please expand at least some of these into words that help to explain your intent to the reader?
  • Could you please return s instead of printing s at the end of prime_sum()? This would require your main to change to print(prime_sum(2000000)) but it allows others to use your function in larger scripts. It also allows us to do automated testing...
  • Please also consider adding doctests with a large positive number, small positive number, zero, a negative number, a floating point number, and a string just to see how prime_sum() deals with bad data.
  • Python type hints also help if you are so inclined... https://docs.python.org/3/library/typing.html

Comment thread project_euler/problem_10/sol3.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry to be a pain but... Let's simplify and just use input() and range() because this repo no longer supports legacy Python.

Comment thread project_euler/problem_10/sol3.py Outdated
#import doctest
#doctest.testmod()

print(prime_sum(int(raw_input())))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

print(prime_sum(int(input().strip()))) will ensure that your code will gracefully deal with leading and/or trailing whitespace in user input.

Comment thread project_euler/problem_10/sol3.py Outdated

"""

list = [0 for i in xrange(n+1)]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

list should not be used as a variable name in Python because there is list is a builtin that we should avoid shadowing. https://docs.python.org/3/library/functions.html

Comment thread project_euler/problem_10/sol3.py Outdated
>>> prime_sum(10000)
5736396
>>> prime_sum(7)
10

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests for negative number, floating point number, string? This will ensure that your code is robust and predictable.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's not for a negative number, floating-point number, string. it only works for positive numbers,
it a question base problem if anyone uses it, should only enter positive numbers.

thank you,

@cclauss
cclauss merged commit 4a5589f into TheAlgorithms:master Jul 31, 2019
@cclauss

cclauss commented Jul 31, 2019

Copy link
Copy Markdown
Member

stokhos pushed a commit to stokhos/Python that referenced this pull request Jan 3, 2021
* project_euler/problem_10

* update project_euler/problem_10

* update project_euler/problem_10

* Negative user tests added.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants