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.159 tracks/perl5/exercises/secret-handshake/.meta/solutions/SecretHandshake.pm
trackler-2.2.1.158 tracks/perl5/exercises/secret-handshake/.meta/solutions/SecretHandshake.pm
trackler-2.2.1.157 tracks/perl5/exercises/secret-handshake/.meta/solutions/SecretHandshake.pm
trackler-2.2.1.156 tracks/perl5/exercises/secret-handshake/.meta/solutions/SecretHandshake.pm
trackler-2.2.1.155 tracks/perl5/exercises/secret-handshake/.meta/solutions/SecretHandshake.pm
trackler-2.2.1.154 tracks/perl5/exercises/secret-handshake/.meta/solutions/SecretHandshake.pm
trackler-2.2.1.153 tracks/perl5/exercises/secret-handshake/.meta/solutions/SecretHandshake.pm
trackler-2.2.1.152 tracks/perl5/exercises/secret-handshake/.meta/solutions/SecretHandshake.pm
trackler-2.2.1.151 tracks/perl5/exercises/secret-handshake/.meta/solutions/SecretHandshake.pm
trackler-2.2.1.150 tracks/perl5/exercises/secret-handshake/.meta/solutions/SecretHandshake.pm
trackler-2.2.1.149 tracks/perl5/exercises/secret-handshake/.meta/solutions/SecretHandshake.pm
trackler-2.2.1.148 tracks/perl5/exercises/secret-handshake/.meta/solutions/SecretHandshake.pm
trackler-2.2.1.147 tracks/perl5/exercises/secret-handshake/.meta/solutions/SecretHandshake.pm
trackler-2.2.1.146 tracks/perl5/exercises/secret-handshake/.meta/solutions/SecretHandshake.pm
trackler-2.2.1.145 tracks/perl5/exercises/secret-handshake/.meta/solutions/SecretHandshake.pm
trackler-2.2.1.144 tracks/perl5/exercises/secret-handshake/.meta/solutions/SecretHandshake.pm
trackler-2.2.1.143 tracks/perl5/exercises/secret-handshake/.meta/solutions/SecretHandshake.pm
trackler-2.2.1.142 tracks/perl5/exercises/secret-handshake/.meta/solutions/SecretHandshake.pm
trackler-2.2.1.141 tracks/perl5/exercises/secret-handshake/.meta/solutions/SecretHandshake.pm
trackler-2.2.1.140 tracks/perl5/exercises/secret-handshake/.meta/solutions/SecretHandshake.pm