Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more solutions to Project Euler problems #2695

Open
aceking007 opened this issue Oct 3, 2020 · 16 comments
Open

Add more solutions to Project Euler problems #2695

aceking007 opened this issue Oct 3, 2020 · 16 comments

Comments

@aceking007
Copy link

@aceking007 aceking007 commented Oct 3, 2020

Project Euler has about 700 problems, but the current repository hosts solutions for only about 60-70 problems.
I'm willing to work on the issue and also if someone wants to help they can join in.
We can create guidelines on how many minimum solutions a PR should have to prevent spammy PRs with just one or two easy solutions. (open to discussion)

@dhruvmanila
Copy link
Member

@dhruvmanila dhruvmanila commented Oct 3, 2020

UPDATE: Only submit solution to problems which doesn't exists in this repository.

As of now, we are only accepting PRs with one algorithm in it as it is easier to review one file at a time.
Feel free to open PR for whichever problem you have solved provided the answer is correct.

Anyone reading this can join and open PRs as well. We accept multiple solutions to a problem as everyone has their own approach to problem-solving but it should be their own and unique compared to other solutions.

NOTE: Please give us time to review as there are so many to go through. If possible submit one PR at a time and when that is merged provided it passes all the automatic tests, you can submit another PR. Also, please read the contributing guidelines before opening a PR.

One step at a time

Please follow the points mentioned below regarding Project Euler solutions. This is done to maintain consistency throughout the directory and to run this script which checks all the solutions:

  • There should be a function called solution() which, when called without any arguments, returns the answer to the problem.
  • If you wish to include parameters for the solution() function then the default value for the parameters should be the question input so that when the function is called without any arguments, it returns the answer to the problem.

Example:

def solution():                               # function without any parameters
    # ... calculations ...
    return answer

# If we call this function without passing any arguments, it will return the answer
solution()  # -> answer

def solution(input: "default value"):         # function with parameters having default value
    # ... calculations ...
    return answer

# If we call this function without passing any arguments, it will return the answer
solution()  # -> answer

For problems which needs to work with large data, put the data in a separate file and import it.
Refer: #2695 (comment)

@RGarg2002
Copy link

@RGarg2002 RGarg2002 commented Oct 4, 2020

Where can I get the problems from?

@berry-thawson
Copy link

@berry-thawson berry-thawson commented Oct 4, 2020

https://projecteuler.net/
Hope this helps

@RGarg2002
Copy link

@RGarg2002 RGarg2002 commented Oct 4, 2020

Thanks it helped🙂

akshat235 added a commit to akshat235/Python that referenced this issue Oct 4, 2020
Added problem_38 folder with solution file sol.py. TheAlgorithms#2695
@akshat235 akshat235 mentioned this issue Oct 4, 2020
7 of 13 tasks complete
akshat235 added a commit to akshat235/Python that referenced this issue Oct 4, 2020
kalpanajangra added a commit to kalpanajangra/Python that referenced this issue Oct 5, 2020
kalpanajangra added a commit to kalpanajangra/Python that referenced this issue Oct 5, 2020
@sarthaka1310 sarthaka1310 mentioned this issue Oct 5, 2020
11 of 14 tasks complete
@hbarovertwo
Copy link

@hbarovertwo hbarovertwo commented Oct 6, 2020

I would love to join and contribute. Project Euler was always fun to me back in college :)

@berry-thawson
Copy link

@berry-thawson berry-thawson commented Oct 6, 2020

Hi,
When there is a program for which input is presented as a file, how should the input be coded?
Should it be hardcoded in the file or should it be reading from a file relative to the directory?

@dhruvmanila
Copy link
Member

@dhruvmanila dhruvmanila commented Oct 6, 2020

@berry-thawson Please refer to problem_54#L367-L369

import os  # with other imports
...

def solution():
    script_dir = os.path.abspath(os.path.dirname(__file__))
    <file_name_without_extension> = os.path.join(script_dir, "<file_name>")
    with open(<file_name_without_extension> , "r") as file_hand:
        # ... your code ...
  • Instead of <file_name> add the name of the file you want to import.
  • Instead of <file_name_without_extension> add the variable name which is descriptive. If possible choose the name as the file name but without the extension.
  • Then using with do whatever you want to do with the contents of the file.

I hope this clears your doubt. If you still have any problem, don't hesitate to ask.

@berry-thawson
Copy link

@berry-thawson berry-thawson commented Oct 6, 2020

Thanks @dhruvmanila
This is helpful

@sarthaka1310 sarthaka1310 mentioned this issue Oct 6, 2020
11 of 14 tasks complete
@appsx13
Copy link

@appsx13 appsx13 commented Oct 7, 2020

Hi, can we add solution to any problem?

@peteryao7 peteryao7 mentioned this issue Oct 8, 2020
10 of 14 tasks complete
peteryao7 added a commit to peteryao7/Python that referenced this issue Oct 8, 2020
@peteryao7 peteryao7 mentioned this issue Oct 8, 2020
10 of 14 tasks complete
peteryao7 added a commit to peteryao7/Python that referenced this issue Oct 8, 2020
@peteryao7 peteryao7 mentioned this issue Oct 8, 2020
9 of 14 tasks complete
ksr1122 pushed a commit to ksr1122/Python that referenced this issue Oct 10, 2020
Ravi Kandasamy Sundaram
Name: Digit power sum

Problem Statement: The number 512 is interesting because it is equal to the sum of its digits raised to some power: 5 + 1 + 2 = 8, and 83 = 512. Another example of a number with this property is 614656 = 284.
We shall define an to be the nth term of this sequence and insist that a number must contain at least two digits to have a sum.
You are given that a2 = 512 and a10 = 614656.
Find a30

Reference: https://projecteuler.net/problem=119

reference: TheAlgorithms#2695
ksr1122 pushed a commit to ksr1122/Python that referenced this issue Oct 10, 2020
Name: Digit power sum

Problem Statement: The number 512 is interesting because it is equal to the sum of its digits raised to some power: 5 + 1 + 2 = 8, and 83 = 512. Another example of a number with this property is 614656 = 284.
We shall define an to be the nth term of this sequence and insist that a number must contain at least two digits to have a sum.
You are given that a2 = 512 and a10 = 614656.
Find a30

Reference: https://projecteuler.net/problem=119

reference: TheAlgorithms#2695
ksr1122 pushed a commit to ksr1122/Python that referenced this issue Oct 10, 2020
Name: Prime square remainders

Let pn be the nth prime: 2, 3, 5, 7, 11, ..., and
let r be the remainder when (pn−1)^n + (pn+1)^n is divided by pn^2.

For example, when n = 3, p3 = 5, and 43 + 63 = 280 ≡ 5 mod 25.
The least value of n for which the remainder first exceeds 10^9 is 7037.

Find the least value of n for which the remainder first exceeds 10^10.

Reference: https://projecteuler.net/problem=123

reference: TheAlgorithms#2695
@Satyamkumarai Satyamkumarai mentioned this issue Oct 10, 2020
12 of 14 tasks complete
ksr1122 pushed a commit to ksr1122/Python that referenced this issue Oct 10, 2020
Name: Palindromic sums

The palindromic number 595 is interesting because it can be written as
the sum of consecutive squares: 6^2 + 7^2 + 8^2 + 9^2 + 10^2 + 11^2 + 12^2.
There are exactly eleven palindromes below one-thousand that can be written as
consecutive square sums, and the sum of these palindromes is 4164.

Note that 1 = 0^2 + 1^2 has not been included as this problem is concerned with
the squares of positive integers.

Find the sum of all the numbers less than 10^8
that are both palindromic and can be written as the sum of consecutive squares.

Reference: https://projecteuler.net/problem=125

Fixes: TheAlgorithms#2695
@Satyamkumarai Satyamkumarai mentioned this issue Oct 10, 2020
9 of 14 tasks complete
ksr1122 pushed a commit to ksr1122/Python that referenced this issue Oct 10, 2020
Name: Digit power sum

Problem Statement: The number 512 is interesting because it is equal to the sum of its digits raised to some power: 5 + 1 + 2 = 8, and 83 = 512. Another example of a number with this property is 614656 = 284.
We shall define an to be the nth term of this sequence and insist that a number must contain at least two digits to have a sum.
You are given that a2 = 512 and a10 = 614656.
Find a30

Reference: https://projecteuler.net/problem=119

reference: TheAlgorithms#2695
ksr1122 pushed a commit to ksr1122/Python that referenced this issue Oct 10, 2020
Name: Prime square remainders

Let pn be the nth prime: 2, 3, 5, 7, 11, ..., and
let r be the remainder when (pn−1)^n + (pn+1)^n is divided by pn^2.

For example, when n = 3, p3 = 5, and 43 + 63 = 280 ≡ 5 mod 25.
The least value of n for which the remainder first exceeds 10^9 is 7037.

Find the least value of n for which the remainder first exceeds 10^10.

Reference: https://projecteuler.net/problem=123

reference: TheAlgorithms#2695
ksr1122 pushed a commit to ksr1122/Python that referenced this issue Oct 10, 2020
Name: Digit power sum

Problem Statement: The number 512 is interesting because it is equal to the sum of its digits raised to some power: 5 + 1 + 2 = 8, and 83 = 512. Another example of a number with this property is 614656 = 284.
We shall define an to be the nth term of this sequence and insist that a number must contain at least two digits to have a sum.
You are given that a2 = 512 and a10 = 614656.
Find a30

Reference: https://projecteuler.net/problem=119

reference: TheAlgorithms#2695
ksr1122 pushed a commit to ksr1122/Python that referenced this issue Oct 10, 2020
Name: Digit power sum

Problem Statement: The number 512 is interesting because it is equal to the sum of its digits raised to some power: 5 + 1 + 2 = 8, and 83 = 512. Another example of a number with this property is 614656 = 284.
We shall define an to be the nth term of this sequence and insist that a number must contain at least two digits to have a sum.
You are given that a2 = 512 and a10 = 614656.
Find a30

Reference: https://projecteuler.net/problem=119

reference: TheAlgorithms#2695
dhruvmanila pushed a commit that referenced this issue Oct 10, 2020
Name: Digit power sum

Problem Statement: The number 512 is interesting because it is equal to the sum of its digits raised to some power: 5 + 1 + 2 = 8, and 83 = 512. Another example of a number with this property is 614656 = 284.
We shall define an to be the nth term of this sequence and insist that a number must contain at least two digits to have a sum.
You are given that a2 = 512 and a10 = 614656.
Find a30

Reference: https://projecteuler.net/problem=119

reference: #2695

Co-authored-by: Ravi Kandasamy Sundaram <rkandasamysundaram@luxoft.com>
ksr1122 pushed a commit to ksr1122/Python that referenced this issue Oct 10, 2020
Name: Divisor Square Sum

For a positive integer n, let σ2(n) be the sum of the squares of its divisors.
For example, σ2(10) = 1 + 4 + 25 + 100 = 130.

Find the sum of all n, 0 < n < 64,000,000 such that σ2(n) is a perfect square.

reference: TheAlgorithms#2695
ksr1122 pushed a commit to ksr1122/Python that referenced this issue Oct 10, 2020
Name: Divisor Square Sum

For a positive integer n, let σ2(n) be the sum of the squares of its divisors.
For example, σ2(10) = 1 + 4 + 25 + 100 = 130.

Find the sum of all n, 0 < n < 64,000,000 such that σ2(n) is a perfect square.

reference: TheAlgorithms#2695
@ksr1122 ksr1122 mentioned this issue Oct 10, 2020
12 of 14 tasks complete
ksr1122 pushed a commit to ksr1122/Python that referenced this issue Oct 10, 2020
Name: Prime square remainders

Let pn be the nth prime: 2, 3, 5, 7, 11, ..., and
let r be the remainder when (pn−1)^n + (pn+1)^n is divided by pn^2.

For example, when n = 3, p3 = 5, and 43 + 63 = 280 ≡ 5 mod 25.
The least value of n for which the remainder first exceeds 10^9 is 7037.

Find the least value of n for which the remainder first exceeds 10^10.

Reference: https://projecteuler.net/problem=123

reference: TheAlgorithms#2695
@dhruvmanila
Copy link
Member

@dhruvmanila dhruvmanila commented Oct 11, 2020

Please don't submit PRs for the solutions which already exist in the repository. This issue is meant to increase the number of solved problems and not to increase the number of solutions in a problem.

Open ONLY one PR at a time and when that is merged, open another one.

ksr1122 pushed a commit to ksr1122/Python that referenced this issue Oct 11, 2020
Name: Divisor Square Sum

For a positive integer n, let σ2(n) be the sum of the squares of its divisors.
For example, σ2(10) = 1 + 4 + 25 + 100 = 130.

Find the sum of all n, 0 < n < 64,000,000 such that σ2(n) is a perfect square.

reference: TheAlgorithms#2695
amy-graham-js pushed a commit to amy-graham-js/Python that referenced this issue Oct 11, 2020
amy-graham-js pushed a commit to amy-graham-js/Python that referenced this issue Oct 11, 2020
@flick-23
Copy link

@flick-23 flick-23 commented Oct 12, 2020

I want to submit my solutions. How do i submit ?

@shubhranshubhoi78
Copy link

@shubhranshubhoi78 shubhranshubhoi78 commented Oct 12, 2020

I'm a keen Euler solver.please let me help in providing efficient solutions to the problems.

heyyviv added a commit to heyyviv/Python that referenced this issue Oct 12, 2020
heyyviv added a commit to heyyviv/Python that referenced this issue Oct 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

You can’t perform that action at this time.