Sha256: 3aaf1abc80ad87080f6501fd416120e6c5917ebd6db2e99642dd36e1689441f2

Contents?: true

Size: 294 Bytes

Versions: 34

Compression:

Stored size: 294 Bytes

Contents

class Binary {
    method to_decimal ($binary) {
        return 0 if $binary ~~ /<-[^01]>/;

        my $decimal = 0;
        my $index = $binary.chars;

        for $binary.split('',:skip-empty) -> $bit {
           $decimal += $bit * 2 ** --$index;
        }
        return $decimal;
    }
}

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
trackler-2.0.5.16 tracks/perl6/exercises/binary/Example.pm
trackler-2.0.5.15 tracks/perl6/exercises/binary/Example.pm
trackler-2.0.5.14 tracks/perl6/exercises/binary/Example.pm
trackler-2.0.5.13 tracks/perl6/exercises/binary/Example.pm
trackler-2.0.5.12 tracks/perl6/exercises/binary/Example.pm
trackler-2.0.5.11 tracks/perl6/exercises/binary/Example.pm
trackler-2.0.5.10 tracks/perl6/exercises/binary/Example.pm
trackler-2.0.5.9 tracks/perl6/exercises/binary/Example.pm
trackler-2.0.5.8 tracks/perl6/exercises/binary/Example.pm
trackler-2.0.5.7 tracks/perl6/exercises/binary/Example.pm
trackler-2.0.5.6 tracks/perl6/exercises/binary/Example.pm
trackler-2.0.5.5 tracks/perl6/exercises/binary/Example.pm
trackler-2.0.5.4 tracks/perl6/exercises/binary/Example.pm
trackler-2.0.5.3 tracks/perl6/exercises/binary/Example.pm
trackler-2.0.5.2 tracks/perl6/exercises/binary/Example.pm
trackler-2.0.5.1 tracks/perl6/exercises/binary/Example.pm
trackler-2.0.5.0 tracks/perl6/exercises/binary/Example.pm
trackler-2.0.4.0 tracks/perl6/exercises/binary/Example.pm
trackler-2.0.3.9 tracks/perl6/exercises/binary/Example.pm
trackler-2.0.3.8 tracks/perl6/exercises/binary/Example.pm