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 ways-to-add-up-to to "math" module #874

Merged
merged 1 commit into from
Jul 21, 2024

Conversation

amtoine
Copy link
Member

@amtoine amtoine commented Jun 8, 2024

at my job, i studied very quickly something that involved computing all the ways one can build a positive integer from the addition of other positive integers.

enters the ways-to-add-up-to command i've written and added to the math module in this PR.

example

ways-to-add-up-to 4 will be [[1, 1, 1, 1], [1, 1, 2], [1, 3], [2, 2], [4]]] because $4$
can be obtained as follows:

$$ 1 + 1 + 1 + 1 $$

$$ 1 + 1 + 2 = 1 + 2 + 1 = 2 + 1 + 1 $$

$$ 1 + 3 = 3 + 1 $$

$$ 2 + 2 $$

$$ 4 $$

Note
$1 + 1 + 2$ and $1 + 2 + 1$ are considered the same because addition is commutative and thus only [1, 1, 2] will be returned

@fdncred fdncred merged commit 6aa2700 into nushell:main Jul 21, 2024
1 check passed
@fdncred
Copy link
Collaborator

fdncred commented Jul 21, 2024

Thanks

@amtoine amtoine deleted the math_ways-to-add-up-to branch July 25, 2024 19:29
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