Skip to content

Instantly share code, notes, and snippets.

@heyajulia
Created May 30, 2021 11:07
Show Gist options
  • Save heyajulia/7bb6f451edfb10f7d94d2338d989c3eb to your computer and use it in GitHub Desktop.
Save heyajulia/7bb6f451edfb10f7d94d2338d989c3eb to your computer and use it in GitHub Desktop.
# Usage: echo words | raku scrambler.raku
sub scramble-word(Str $word --> Str) {
if $word.chars <= 3 {
return $word;
}
my @letters = $word.comb;
my $first-letter = @letters[0];
my $last-letter = @letters[*-1];
my @middle-letters = @letters[1..*-2];
my @scrambled-word = @middle-letters.pick(@middle-letters);
@scrambled-word.prepend: $first-letter;
@scrambled-word.push: $last-letter;
return @scrambled-word.join;
}
slurp()
.words
.map(-> $word { scramble-word $word })
.join(" ")
.print;
@holli-holzer
Copy link

[*;*] flattens the list. It can be replaced by .flat. But why does it work that way?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment