Skip to content

Instantly share code, notes, and snippets.

@scmorrison
Last active January 14, 2017 14:29
Show Gist options
  • Save scmorrison/cdbb14130283f763ed6094de3f03efd3 to your computer and use it in GitHub Desktop.
Save scmorrison/cdbb14130283f763ed6094de3f03efd3 to your computer and use it in GitHub Desktop.
Step through string, x characters at a time, sliding rule
#!/usr/bin/env perl6
use v6;
my $input = 'While there was a brief hiatus in the development of the open firmware for Raspberry Pi, we can now boot Linux straight from bootcode.bin (note, this does require an initrd built in with zImage as there are still issues with eMMC working reliably at boot).';
my @input_arr = $input.comb;
my $i = 0;
my %working_set;
# example 1: rotor
my $now = now;
@input_arr.rotor(5 => -4).map: -> @set {
%working_set{'a', 'b', 'c', 'd', 'e'} = @set;
say %working_set.perl;
}
say "Example 1 runtime: {now - $now}";
# example 2: while
$now = now;
while $i < @input_arr.elems {
%working_set{'a', 'b', 'c', 'd'} = @input_arr[$i..$i+3];
say %working_set.perl;
$i++;
}
say "Example 2 runtime: {now - $now}";
# Example 1 runtime: 0.0605445
# Example 2 runtime: 0.0288781
# %working_set example output
{:a("W"), :b("h"), :c("i"), :d("l"), :e("e")}
{:a("h"), :b("i"), :c("l"), :d("e"), :e(" ")}
{:a("i"), :b("l"), :c("e"), :d(" "), :e("t")}
{:a("l"), :b("e"), :c(" "), :d("t"), :e("h")}
{:a("e"), :b(" "), :c("t"), :d("h"), :e("e")}
{:a(" "), :b("t"), :c("h"), :d("e"), :e("r")}
{:a("t"), :b("h"), :c("e"), :d("r"), :e("e")}
{:a("h"), :b("e"), :c("r"), :d("e"), :e(" ")}
{:a("e"), :b("r"), :c("e"), :d(" "), :e("w")}
{:a("r"), :b("e"), :c(" "), :d("w"), :e("a")}
{:a("e"), :b(" "), :c("w"), :d("a"), :e("s")}
{:a(" "), :b("w"), :c("a"), :d("s"), :e(" ")}
{:a("w"), :b("a"), :c("s"), :d(" "), :e("a")}
{:a("a"), :b("s"), :c(" "), :d("a"), :e(" ")}
{:a("s"), :b(" "), :c("a"), :d(" "), :e("b")}
...
...
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment