Sha256: e8a4ab0a9d59ef3d8161c06aaefeb45e07186cf80cdb4a5a8f5c722ef1536c78

Contents?: true

Size: 584 Bytes

Versions: 323

Compression:

Stored size: 584 Bytes

Contents

package Example;

use strict;
use warnings;

sub new {
    my ($class, $strand) = @_;
    my $self = bless {} => $class;
    $self->{strand} = $strand;
    $self->{len} = length $strand;
    return $self;
}

sub hamming_distance {
    my ($self, $strand) = @_;
    my $distance;
    
    my $len = length $strand;
    $len = $self->{len} if $len > $self->{len};

    my @orig = split // => $self->{strand};
    my @inp  = split // => $strand;

    foreach my $index (0..$len-1) {
        $distance++ if $orig[$index] ne $inp[$index];
    }

    return $distance || 0;
}

__PACKAGE__;

Version data entries

323 entries across 323 versions & 1 rubygems

Version Path
trackler-2.2.1.105 tracks/perl5/exercises/point-mutations/Example.pm
trackler-2.2.1.104 tracks/perl5/exercises/point-mutations/Example.pm
trackler-2.2.1.103 tracks/perl5/exercises/point-mutations/Example.pm
trackler-2.2.1.102 tracks/perl5/exercises/point-mutations/Example.pm
trackler-2.2.1.101 tracks/perl5/exercises/point-mutations/Example.pm
trackler-2.2.1.100 tracks/perl5/exercises/point-mutations/Example.pm
trackler-2.2.1.99 tracks/perl5/exercises/point-mutations/Example.pm
trackler-2.2.1.98 tracks/perl5/exercises/point-mutations/Example.pm
trackler-2.2.1.97 tracks/perl5/exercises/point-mutations/Example.pm
trackler-2.2.1.96 tracks/perl5/exercises/point-mutations/Example.pm
trackler-2.2.1.95 tracks/perl5/exercises/point-mutations/Example.pm
trackler-2.2.1.94 tracks/perl5/exercises/point-mutations/Example.pm
trackler-2.2.1.93 tracks/perl5/exercises/point-mutations/Example.pm
trackler-2.2.1.92 tracks/perl5/exercises/point-mutations/Example.pm
trackler-2.2.1.91 tracks/perl5/exercises/point-mutations/Example.pm
trackler-2.2.1.90 tracks/perl5/exercises/point-mutations/Example.pm
trackler-2.2.1.89 tracks/perl5/exercises/point-mutations/Example.pm
trackler-2.2.1.88 tracks/perl5/exercises/point-mutations/Example.pm
trackler-2.2.1.87 tracks/perl5/exercises/point-mutations/Example.pm
trackler-2.2.1.86 tracks/perl5/exercises/point-mutations/Example.pm