DEV Community

loading...

Discussion on: Daily Challenge #225 - Square'n'Sum

Collapse
citizen428 profile image
Michael Kohl • Edited

A GolfScript solution:

{{. *}%{+}*}:ssq;

[1 2 2]ssq
#=> 14

Explanation: map (%) the block {. *} over the input. . duplicates the element, * multiplies the top 2 stack elements. Then fold (*) a block performing addition {+} over the result.