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.119 tracks/perl5/exercises/secret-handshake/.meta/solutions/SecretHandshake.pm
trackler-2.2.1.118 tracks/perl5/exercises/secret-handshake/.meta/solutions/SecretHandshake.pm
trackler-2.2.1.117 tracks/perl5/exercises/secret-handshake/.meta/solutions/SecretHandshake.pm
trackler-2.2.1.116 tracks/perl5/exercises/secret-handshake/.meta/solutions/SecretHandshake.pm
trackler-2.2.1.115 tracks/perl5/exercises/secret-handshake/.meta/solutions/SecretHandshake.pm
trackler-2.2.1.114 tracks/perl5/exercises/secret-handshake/.meta/solutions/SecretHandshake.pm
trackler-2.2.1.113 tracks/perl5/exercises/secret-handshake/.meta/solutions/SecretHandshake.pm
trackler-2.2.1.111 tracks/perl5/exercises/secret-handshake/.meta/solutions/SecretHandshake.pm
trackler-2.2.1.110 tracks/perl5/exercises/secret-handshake/.meta/solutions/SecretHandshake.pm
trackler-2.2.1.109 tracks/perl5/exercises/secret-handshake/.meta/solutions/SecretHandshake.pm
trackler-2.2.1.108 tracks/perl5/exercises/secret-handshake/.meta/solutions/SecretHandshake.pm
trackler-2.2.1.107 tracks/perl5/exercises/secret-handshake/.meta/solutions/SecretHandshake.pm
trackler-2.2.1.106 tracks/perl5/exercises/secret-handshake/.meta/solutions/SecretHandshake.pm