Perl Weekly Challenge 149: Fibonacci Digit Sum and Largest Square
These are some answers to the Week 149 of the Perl Weekly Challenge organized by Mohammad S. Anwar.
Spoiler Alert: This weekly challenge deadline is due in a few days from now (on January 30, 2022 at 24:00). This blog post offers some solutions to this challenge, please don’t read on if you intend to complete the challenge on your own.
Task 1: Fibonacci Digit Sum
Given an input $N
, generate the first $N
numbers for which the sum of their digits is a Fibonacci number.
Example:
f(20)=[0, 1, 2, 3, 5, 8, 10, 11, 12, 14, 17, 20, 21, 23, 26, 30, 32, 35, 41, 44]
Fibonacci Digit Sum in Raku
We first populate a Set (for fast look-up) with the Fibonacci numbers up to 1000. Note that we could choose a much smaller maximum value, but it doesn’t cost much and it will work with very large sequences.