Sha256: 047a535e22d224e07bbb34963543ffaf7d5b348ff77b6d25a3fc15c6285b064e

Contents?: true

Size: 702 Bytes

Versions: 48

Compression:

Stored size: 702 Bytes

Contents

exercise: Luhn
version: 3
plan: 14
subs: is_luhn_valid
tests: |-
  is is_luhn_valid($_->{input}{value}), $_->{expected}, $_->{description} foreach @{$C_DATA->{cases}};

example: |-
  sub is_luhn_valid {
    my ($input) = @_;
    $input =~ s/\s+//g;
    if (length $input < 2 || $input =~ /\D+/) {return 0}

    my @num = split(//, $input);
    unshift @num, 0 if scalar @num % 2;

    my $count = 1;
    my $sum = 0;

    foreach (@num) {
      if ($count % 2) {
        $sum += $_ * 2;
        $sum -= 9 if $_ * 2 > 9;
      }
      else {
        $sum += $_;
      }
      $count += 1;
    }

    if ($sum % 10) {return 0};
    return 1;
  }

stub: |-
  sub is_luhn_valid {
    my ($input) = @_;
  }

Version data entries

48 entries across 48 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/perl5/exercises/luhn/.meta/exercise-data.yaml
trackler-2.2.1.179 tracks/perl5/exercises/luhn/.meta/exercise-data.yaml
trackler-2.2.1.178 tracks/perl5/exercises/luhn/.meta/exercise-data.yaml
trackler-2.2.1.177 tracks/perl5/exercises/luhn/.meta/exercise-data.yaml
trackler-2.2.1.176 tracks/perl5/exercises/luhn/.meta/exercise-data.yaml
trackler-2.2.1.175 tracks/perl5/exercises/luhn/.meta/exercise-data.yaml
trackler-2.2.1.174 tracks/perl5/exercises/luhn/.meta/exercise-data.yaml
trackler-2.2.1.173 tracks/perl5/exercises/luhn/.meta/exercise-data.yaml
trackler-2.2.1.172 tracks/perl5/exercises/luhn/.meta/exercise-data.yaml
trackler-2.2.1.171 tracks/perl5/exercises/luhn/.meta/exercise-data.yaml
trackler-2.2.1.170 tracks/perl5/exercises/luhn/.meta/exercise-data.yaml
trackler-2.2.1.169 tracks/perl5/exercises/luhn/.meta/exercise-data.yaml
trackler-2.2.1.167 tracks/perl5/exercises/luhn/.meta/exercise-data.yaml
trackler-2.2.1.166 tracks/perl5/exercises/luhn/.meta/exercise-data.yaml
trackler-2.2.1.165 tracks/perl5/exercises/luhn/.meta/exercise-data.yaml
trackler-2.2.1.164 tracks/perl5/exercises/luhn/.meta/exercise-data.yaml
trackler-2.2.1.163 tracks/perl5/exercises/luhn/.meta/exercise-data.yaml
trackler-2.2.1.162 tracks/perl5/exercises/luhn/.meta/exercise-data.yaml
trackler-2.2.1.161 tracks/perl5/exercises/luhn/.meta/exercise-data.yaml
trackler-2.2.1.160 tracks/perl5/exercises/luhn/.meta/exercise-data.yaml