# ðŸ“˜ Computing powers of two using Perl 6

Print the first ten powers of two.

The naÃ¯ve loop for calculating powers of two can be created similar to the solution of the Task 22, Print squares:

`say 2 ** \$_ for 0..9;`

It prints the values 1, 2, 4, etc. up to 512.

In Perl 6, thereâ€™s another way of generating sequences withÂ the defined rule of calculating its elements:

`my @power2 = 1, 2, {\$_ * 2} ... *;.say for @power2[^10];`

The rule here isÂ `{\$_ * 2}`, so each next number is twice as big as the previous one. TheÂ `@power2` array gets the values of the infinite lazy list, and only the first ten elements are used for printing. TheÂ `^10` construction at the place of array index creates a rangeÂ `0..9`, and the corresponding slice ofÂ `@power2` is taken.

Perl 6 also can deduct the rule if you provide the first few elements of the list:

`my @power2 = 1, 2, 4 ... *;.say for @power2[^10];`

In the less obvious cases, youâ€™d better prefer an explicit generator for lazy lists.