Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Challenges

Post History

75%
+4 −0
Challenges Evaluate a single variable polynomial equation

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...

posted 4y ago by Jo King‭  ·  edited 4y ago by Jo King‭

Answer
#2: Post edited by user avatar Jo King‭ · 2020-11-15T12:21:04Z (about 4 years ago)
  • # [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 by user avatar Jo King‭ · 2020-11-15T12:14:54Z (about 4 years ago)
# [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
~~~