Course of Raku / Addendum 🆕 / Flow and functions / Subroutines and functional style / Exercises / Sum of even squares
Solution: Sum of even squares
Here is a possible solution to the task.
Code
say [+] (1..10).grep(* %% 2).map(* ** 2);🦋 You can find the source code in the file sum-even-squares.raku.
Output
220Comments
The chain reads left to right:
.grep(* %% 2)keeps the even numbers,.map(* ** 2)squares each, and[+]reduces the squares to their sum.The even numbers
2 4 6 8 10square to4 16 36 64 100, which add up to220.