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.139 tracks/perl5/exercises/secret-handshake/.meta/solutions/SecretHandshake.pm
trackler-2.2.1.138 tracks/perl5/exercises/secret-handshake/.meta/solutions/SecretHandshake.pm
trackler-2.2.1.137 tracks/perl5/exercises/secret-handshake/.meta/solutions/SecretHandshake.pm
trackler-2.2.1.136 tracks/perl5/exercises/secret-handshake/.meta/solutions/SecretHandshake.pm
trackler-2.2.1.135 tracks/perl5/exercises/secret-handshake/.meta/solutions/SecretHandshake.pm
trackler-2.2.1.134 tracks/perl5/exercises/secret-handshake/.meta/solutions/SecretHandshake.pm
trackler-2.2.1.133 tracks/perl5/exercises/secret-handshake/.meta/solutions/SecretHandshake.pm
trackler-2.2.1.132 tracks/perl5/exercises/secret-handshake/.meta/solutions/SecretHandshake.pm
trackler-2.2.1.131 tracks/perl5/exercises/secret-handshake/.meta/solutions/SecretHandshake.pm
trackler-2.2.1.130 tracks/perl5/exercises/secret-handshake/.meta/solutions/SecretHandshake.pm
trackler-2.2.1.129 tracks/perl5/exercises/secret-handshake/.meta/solutions/SecretHandshake.pm
trackler-2.2.1.128 tracks/perl5/exercises/secret-handshake/.meta/solutions/SecretHandshake.pm
trackler-2.2.1.127 tracks/perl5/exercises/secret-handshake/.meta/solutions/SecretHandshake.pm
trackler-2.2.1.126 tracks/perl5/exercises/secret-handshake/.meta/solutions/SecretHandshake.pm
trackler-2.2.1.125 tracks/perl5/exercises/secret-handshake/.meta/solutions/SecretHandshake.pm
trackler-2.2.1.124 tracks/perl5/exercises/secret-handshake/.meta/solutions/SecretHandshake.pm
trackler-2.2.1.123 tracks/perl5/exercises/secret-handshake/.meta/solutions/SecretHandshake.pm
trackler-2.2.1.122 tracks/perl5/exercises/secret-handshake/.meta/solutions/SecretHandshake.pm
trackler-2.2.1.121 tracks/perl5/exercises/secret-handshake/.meta/solutions/SecretHandshake.pm
trackler-2.2.1.120 tracks/perl5/exercises/secret-handshake/.meta/solutions/SecretHandshake.pm