Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iterate over string (UAX #29)

Tags:

raku

say $s.substr($_, 1) for 0..^$s.chars

is the shortest I can find. Can you golf it to a reasonable size and avoid the repetition?

Perl 5 is shorter: say for split /\b{g}/, $s

like image 745
daxim Avatar asked Dec 23 '18 01:12

daxim


1 Answers

The comb method without an argument will pick out every character, thus:

.say for $s.comb;

Will do what is desired (and is shorter than the Perl 5 version too :-)).

like image 80
Jonathan Worthington Avatar answered Nov 09 '22 06:11

Jonathan Worthington