Post History
Raku, 19 bytes (*Z*(*X**0..*)).sum Try it online! Is it concerning that my solution is over 30% asterisks? Explanation ( ).sum # Get the sum of *Z*( ) # The inp...
Answer
#2: Post edited
- # [Raku], 19 bytes
- <!-- language-all: lang-perl6 -->
- (*Z*(*X**0..*)).sum
- [Try it online!][TIO-khj2txnr]
- [Raku]: https://github.com/nxadm/rakudo-pkg
- [TIO-khj2txnr]: https://tio.run/##PYyxDoIwGIT3PsU/SVvh0lZqNIYmDm7OxkgYGCAhASVUB56@ghiW73KXL9dXQ7sP3bips8DlQ3J5l1IBUgj4TxdOzJcj1Ry5KnC5na8xcl0IyhxtkZuC6tdAbfOsvHPwfdu8eZS4SAQNRYkjfTC/YFOPySxjOuPIDOw6Kdg5drCrGU9tQvo/WgSTwtgv "Perl 6 – Try It Online"
- Is it concerning that my solution is over 30% asterisks?
- ### Explanation
- ~~~
- ( ).sum # Get the sum of
- *Z*( ) # The input list zip multiplied by
- *X** # The second input to the power of
- 0..* # 0 to infinity
~~~
- # [Raku], 19 bytes
- <!-- language-all: lang-perl6 -->
- (*Z*(*X**0..*)).sum
- [Try it online!][TIO-khj2txnr]
- [Raku]: https://github.com/nxadm/rakudo-pkg
- [TIO-khj2txnr]: https://tio.run/##PYyxDoIwGIT3PsU/SVvh0lZqNIYmDm7OxkgYGCAhASVUB56@ghiW73KXL9dXQ7sP3bips8DlQ3J5l1IBUgj4TxdOzJcj1Ry5KnC5na8xcl0IyhxtkZuC6tdAbfOsvHPwfdu8eZS4SAQNRYkjfTC/YFOPySxjOuPIDOw6Kdg5drCrGU9tQvo/WgSTwtgv "Perl 6 – Try It Online"
- Is it concerning that my solution is over 30% asterisks?
- ### Explanation
- ~~~
- ( ).sum # Get the sum of
- *Z*( ) # The input list zip multiplied by
- *X** # The second input to the power of
- 0..* # 0 to infinity
- ~~~
- An alternate curried solution for 19 bytes is:
- <!-- language-all: lang-perl6 -->
- {*.reduce(*×$_+*)}
- [Try it online!][TIO-khj365hj]
- [Perl 6]: https://github.com/nxadm/rakudo-pkg
- [TIO-khj365hj]: https://tio.run/##K0gtyjH7n1uplmb7v1pLryg1pTQ5VUPr8HSVeG0tzdr/1lzFiZUKaRp60YaxmkDSIFbPNczRB6iwLLWoOFVTwdZOQVsv2ihWIS2/SCEnMy@12M5Or7ggJ7NEQ13XTl3T@r@hnoGCrp2CoYURmOIC8nUUjCCCJiDCkstIzxQuZKBnCqKM9UzhKnWAPCBhAjUIosDIRM/IFAA "Perl 6 – Try It Online"
#1: Initial revision
# [Raku], 19 bytes <!-- language-all: lang-perl6 --> (*Z*(*X**0..*)).sum [Try it online!][TIO-khj2txnr] [Raku]: https://github.com/nxadm/rakudo-pkg [TIO-khj2txnr]: https://tio.run/##PYyxDoIwGIT3PsU/SVvh0lZqNIYmDm7OxkgYGCAhASVUB56@ghiW73KXL9dXQ7sP3bips8DlQ3J5l1IBUgj4TxdOzJcj1Ry5KnC5na8xcl0IyhxtkZuC6tdAbfOsvHPwfdu8eZS4SAQNRYkjfTC/YFOPySxjOuPIDOw6Kdg5drCrGU9tQvo/WgSTwtgv "Perl 6 – Try It Online" Is it concerning that my solution is over 30% asterisks? ### Explanation ~~~ ( ).sum # Get the sum of *Z*( ) # The input list zip multiplied by *X** # The second input to the power of 0..* # 0 to infinity ~~~