Sha256: 053e50f8845cd791c53e2c6ef548ae12ed91928f0fb297089fac226bccc38c7d

Contents?: true

Size: 582 Bytes

Versions: 323

Compression:

Stored size: 582 Bytes

Contents

package Example;

use strict;
use warnings;

my @com_strings = ('wink', 'double blink', 'close your eyes', 'jump');

sub new {
    my ($class, $number) = @_;
    return bless { number => $number };
}

sub commands {
    my $self = shift;

    return [] if $self->{number} !~ /\d/;
    
    my @commands;
    my @binary = split '' => reverse( substr( sprintf("%b", $self->{number}), -5) );

    foreach my $on (0..$#binary) {
        push @commands => $com_strings[$on] if $binary[$on] and $on < 4;
    }

    return [reverse @commands] if $binary[4];

    return \@commands;
}

1;

Version data entries

323 entries across 323 versions & 1 rubygems

Version Path
trackler-2.2.1.105 tracks/perl5/exercises/secret-handshake/Example.pm
trackler-2.2.1.104 tracks/perl5/exercises/secret-handshake/Example.pm
trackler-2.2.1.103 tracks/perl5/exercises/secret-handshake/Example.pm
trackler-2.2.1.102 tracks/perl5/exercises/secret-handshake/Example.pm
trackler-2.2.1.101 tracks/perl5/exercises/secret-handshake/Example.pm
trackler-2.2.1.100 tracks/perl5/exercises/secret-handshake/Example.pm
trackler-2.2.1.99 tracks/perl5/exercises/secret-handshake/Example.pm
trackler-2.2.1.98 tracks/perl5/exercises/secret-handshake/Example.pm
trackler-2.2.1.97 tracks/perl5/exercises/secret-handshake/Example.pm
trackler-2.2.1.96 tracks/perl5/exercises/secret-handshake/Example.pm
trackler-2.2.1.95 tracks/perl5/exercises/secret-handshake/Example.pm
trackler-2.2.1.94 tracks/perl5/exercises/secret-handshake/Example.pm
trackler-2.2.1.93 tracks/perl5/exercises/secret-handshake/Example.pm
trackler-2.2.1.92 tracks/perl5/exercises/secret-handshake/Example.pm
trackler-2.2.1.91 tracks/perl5/exercises/secret-handshake/Example.pm
trackler-2.2.1.90 tracks/perl5/exercises/secret-handshake/Example.pm
trackler-2.2.1.89 tracks/perl5/exercises/secret-handshake/Example.pm
trackler-2.2.1.88 tracks/perl5/exercises/secret-handshake/Example.pm
trackler-2.2.1.87 tracks/perl5/exercises/secret-handshake/Example.pm
trackler-2.2.1.86 tracks/perl5/exercises/secret-handshake/Example.pm