Given a long number, write a function to return all possible pairs of addends and the sum of each pair.
For example, 12,345
: all of the addends from that number are:
[ 1 + 2, 1 + 3, 1 + 4, 1 + 5, 2 + 3, 2 + 4, 2 + 5, 3 + 4, 3 + 5, 4 + 5 ]
Therefore the result must be:
[ 3, 4, 5, 6, 5, 6, 7, 7, 8, 9 ]
Test Cases
156
81596
3852
3264128
999999
Good luck!
This challenge comes from Zorianff9 on CodeWars. Thank you to CodeWars, who has licensed redistribution of this challenge under the 2-Clause BSD License!
Want to propose a challenge idea for a future post? Email yo+challenge@dev.to with your suggestions!
Top comments (8)
Scala
Small JavaScript answer - trying to think how I would do this with a reduce for fun:
something like this maybe
My first daily challenge :)
Javascript
Live demo codesandbox.io/s/festive-sun-8eno0
In Python.
you will have duplicated pairs
Haskell! Uses the
TupleSections
extension to the compiler to make thepairs
function nicer.Sorry if this is off topic, but does everyone usually code answers for small things like this? Local? Codepen? Other sites?