Sha256: d57e86ff129b8f18b02373c63fa70af401d0ec82393e71b36428bd3ee5194b6a

Contents?: true

Size: 590 Bytes

Versions: 73

Compression:

Stored size: 590 Bytes

Contents

package SecretHandshake;

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

73 entries across 73 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/perl5/exercises/secret-handshake/.meta/solutions/SecretHandshake.pm
trackler-2.2.1.179 tracks/perl5/exercises/secret-handshake/.meta/solutions/SecretHandshake.pm
trackler-2.2.1.178 tracks/perl5/exercises/secret-handshake/.meta/solutions/SecretHandshake.pm
trackler-2.2.1.177 tracks/perl5/exercises/secret-handshake/.meta/solutions/SecretHandshake.pm
trackler-2.2.1.176 tracks/perl5/exercises/secret-handshake/.meta/solutions/SecretHandshake.pm
trackler-2.2.1.175 tracks/perl5/exercises/secret-handshake/.meta/solutions/SecretHandshake.pm
trackler-2.2.1.174 tracks/perl5/exercises/secret-handshake/.meta/solutions/SecretHandshake.pm
trackler-2.2.1.173 tracks/perl5/exercises/secret-handshake/.meta/solutions/SecretHandshake.pm
trackler-2.2.1.172 tracks/perl5/exercises/secret-handshake/.meta/solutions/SecretHandshake.pm
trackler-2.2.1.171 tracks/perl5/exercises/secret-handshake/.meta/solutions/SecretHandshake.pm
trackler-2.2.1.170 tracks/perl5/exercises/secret-handshake/.meta/solutions/SecretHandshake.pm
trackler-2.2.1.169 tracks/perl5/exercises/secret-handshake/.meta/solutions/SecretHandshake.pm
trackler-2.2.1.167 tracks/perl5/exercises/secret-handshake/.meta/solutions/SecretHandshake.pm
trackler-2.2.1.166 tracks/perl5/exercises/secret-handshake/.meta/solutions/SecretHandshake.pm
trackler-2.2.1.165 tracks/perl5/exercises/secret-handshake/.meta/solutions/SecretHandshake.pm
trackler-2.2.1.164 tracks/perl5/exercises/secret-handshake/.meta/solutions/SecretHandshake.pm
trackler-2.2.1.163 tracks/perl5/exercises/secret-handshake/.meta/solutions/SecretHandshake.pm
trackler-2.2.1.162 tracks/perl5/exercises/secret-handshake/.meta/solutions/SecretHandshake.pm
trackler-2.2.1.161 tracks/perl5/exercises/secret-handshake/.meta/solutions/SecretHandshake.pm
trackler-2.2.1.160 tracks/perl5/exercises/secret-handshake/.meta/solutions/SecretHandshake.pm