Course of Raku / Advanced / More about built-in types / Sequences / Exercises

Powers of two

Problem

Describe the powers of two as an infinite geometric sequence (ending in Inf), then take just the first eight values from it with head. Thanks to laziness, the endless sequence is never fully computed.

Example

The program prints:

(1 2 4 8 16 32 64 128)

Solution

See the solution

Course navigation

Solution: Odd numbers   |   Solution: Powers of two