Skip to content

Added solution for Project Euler problem 101 #4033

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

Merged
merged 7 commits into from
Dec 22, 2020
Merged

Added solution for Project Euler problem 101 #4033

merged 7 commits into from
Dec 22, 2020

Conversation

fpringle
Copy link
Contributor

Describe your change:

Project Euler problem 101: Optimum polynomial

If we are presented with the first k terms of a sequence it is impossible to say with certainty the value of the next term, as there are infinitely many polynomial functions that can model the sequence.

As an example, let us consider the sequence of cube numbers. This is defined by the generating function,
un = n3: 1, 8, 27, 64, 125, 216, ...

Suppose we were only given the first two terms of this sequence. Working on the principle that "simple is best" we should assume a linear relationship and predict the next term to be 15 (common difference 7). Even if we were presented with the first three terms, by the same principle of simplicity, a quadratic relationship should be assumed.

We shall define OP(k, n) to be the nth term of the optimum polynomial generating function for the first k terms of a sequence. It should be clear that OP(k, n) will accurately generate the terms of the sequence for n ≤ k, and potentially the first incorrect term (FIT) will be OP(k, k+1); in which case we shall call it a bad OP (BOP).

As a basis, if we were only given the first term of sequence, it would be most sensible to assume constancy; that is, for n ≥ 2, OP(1, n) = u1.

Hence we obtain the following OPs for the cubic sequence:

OP(1, n) = 1: 1, 1, 1, 1, ...
OP(2, n) = 7n−6: 1, 8, 15, ...
OP(3, n) = 6n2−11n+6: 1, 8, 27, 58, ...
OP(4, n) = n3: 1, 8, 27, 64, 125, ...
Clearly no BOPs exist for k ≥ 4.

By considering the sum of FITs generated by the BOPs (indicated in red above), we obtain 1 + 15 + 58 = 74.

Consider the following tenth degree polynomial generating function:

un = 1 − n + n2 − n3 + n4 − n5 + n6 − n7 + n8 − n9 + n10

Find the sum of FITs for the BOPs.

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Documentation change?

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass the automated testing.
  • All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation.
  • If this pull request resolves one or more open issues then the commit message contains Fixes: #{$ISSUE_NO}.

@ghost ghost added awaiting reviews This PR is ready to be reviewed require descriptive names This PR needs descriptive function and/or variable names labels Dec 13, 2020
Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

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

Click here to look at the relevant links ⬇️

🔗 Relevant Links

Repository:

Python:

Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.

algorithms-keeper commands and options

algorithms-keeper actions can be triggered by commenting on this PR:

  • @algorithms-keeper review to trigger the checks for only added pull request files
  • @algorithms-keeper review-all to trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will only modify the labels accordingly.

NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.

@ghost ghost added awaiting reviews This PR is ready to be reviewed and removed awaiting reviews This PR is ready to be reviewed require descriptive names This PR needs descriptive function and/or variable names labels Dec 13, 2020
Copy link
Member

@dhruvmanila dhruvmanila left a comment

Choose a reason for hiding this comment

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

Please update all the one letter variable to be a bit more descriptive. That would help the reader understand what the variable means.

@ghost ghost added awaiting changes A maintainer has requested changes to this PR and removed awaiting reviews This PR is ready to be reviewed labels Dec 18, 2020
@fpringle fpringle requested a review from l3str4nge as a code owner December 18, 2020 10:33
@ghost ghost added the require type hints https://docs.python.org/3/library/typing.html label Dec 18, 2020
Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

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

Click here to look at the relevant links ⬇️

🔗 Relevant Links

Repository:

Python:

Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.

algorithms-keeper commands and options

algorithms-keeper actions can be triggered by commenting on this PR:

  • @algorithms-keeper review to trigger the checks for only added pull request files
  • @algorithms-keeper review-all to trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will only modify the labels accordingly.

NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.

@ghost ghost added awaiting reviews This PR is ready to be reviewed require tests Tests [doctest/unittest/pytest] are required and removed awaiting changes A maintainer has requested changes to this PR require type hints https://docs.python.org/3/library/typing.html labels Dec 18, 2020
Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

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

Click here to look at the relevant links ⬇️

🔗 Relevant Links

Repository:

Python:

Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.

algorithms-keeper commands and options

algorithms-keeper actions can be triggered by commenting on this PR:

  • @algorithms-keeper review to trigger the checks for only added pull request files
  • @algorithms-keeper review-all to trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will only modify the labels accordingly.

NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.

@ghost ghost added tests are failing Do not merge until tests pass and removed require tests Tests [doctest/unittest/pytest] are required tests are failing Do not merge until tests pass labels Dec 18, 2020
@dhruvmanila
Copy link
Member

I think you accidentally added the latest commit from master in this pull request. You should rebase instead of merge. If you want to keep your pull request in sync with master: git rebase master <your PR branch name>

Copy link
Member

@dhruvmanila dhruvmanila left a comment

Choose a reason for hiding this comment

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

LGTM! 🎉

@ghost ghost removed the awaiting reviews This PR is ready to be reviewed label Dec 22, 2020
@dhruvmanila dhruvmanila merged commit 2ff2ccb into TheAlgorithms:master Dec 22, 2020
@fpringle fpringle deleted the problem_101 branch December 22, 2020 13:47
stokhos pushed a commit to stokhos/Python that referenced this pull request Jan 3, 2021
* Added solution for Project Euler problem 101

* Got rid of map functions

* updating DIRECTORY.md

* Better function/variable names

* Better variable names

* Type hints

* Doctest for nested function

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
peRFectBeliever pushed a commit to peRFectBeliever/Python that referenced this pull request Apr 1, 2021
* Added solution for Project Euler problem 101

* Got rid of map functions

* updating DIRECTORY.md

* Better function/variable names

* Better variable names

* Type hints

* Doctest for nested function

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
Panquesito7 pushed a commit to Panquesito7/Python that referenced this pull request May 13, 2021
* Added solution for Project Euler problem 101

* Got rid of map functions

* updating DIRECTORY.md

* Better function/variable names

* Better variable names

* Type hints

* Doctest for nested function

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
shermanhui pushed a commit to shermanhui/Python that referenced this pull request Oct 22, 2021
* Added solution for Project Euler problem 101

* Got rid of map functions

* updating DIRECTORY.md

* Better function/variable names

* Better variable names

* Type hints

* Doctest for nested function

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
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