exercism-perl5

Repository for my Perl 5 Exercism exercises
git clone git://git.samirparikh.com/exercism-perl5
Log | Files | Refs | README

README.md (1738B) - raw


      1 # Luhn
      2 
      3 Welcome to Luhn on Exercism's Perl 5 Track.
      4 If you need help running the tests or submitting your code, check out `HELP.md`.
      5 
      6 ## Instructions
      7 
      8 Given a number determine whether or not it is valid per the Luhn formula.
      9 
     10 The [Luhn algorithm](https://en.wikipedia.org/wiki/Luhn_algorithm) is
     11 a simple checksum formula used to validate a variety of identification
     12 numbers, such as credit card numbers and Canadian Social Insurance
     13 Numbers.
     14 
     15 The task is to check if a given string is valid.
     16 
     17 ## Validating a Number
     18 
     19 Strings of length 1 or less are not valid. Spaces are allowed in the input,
     20 but they should be stripped before checking. All other non-digit characters
     21 are disallowed.
     22 
     23 ### Example 1: valid credit card number
     24 
     25 ```text
     26 4539 3195 0343 6467
     27 ```
     28 
     29 The first step of the Luhn algorithm is to double every second digit,
     30 starting from the right. We will be doubling
     31 
     32 ```text
     33 4_3_ 3_9_ 0_4_ 6_6_
     34 ```
     35 
     36 If doubling the number results in a number greater than 9 then subtract 9
     37 from the product. The results of our doubling:
     38 
     39 ```text
     40 8569 6195 0383 3437
     41 ```
     42 
     43 Then sum all of the digits:
     44 
     45 ```text
     46 8+5+6+9+6+1+9+5+0+3+8+3+3+4+3+7 = 80
     47 ```
     48 
     49 If the sum is evenly divisible by 10, then the number is valid. This number is valid!
     50 
     51 ### Example 2: invalid credit card number
     52 
     53 ```text
     54 8273 1232 7352 0569
     55 ```
     56 
     57 Double the second digits, starting from the right
     58 
     59 ```text
     60 7253 2262 5312 0539
     61 ```
     62 
     63 Sum the digits
     64 
     65 ```text
     66 7+2+5+3+2+2+6+2+5+3+1+2+0+5+3+9 = 57
     67 ```
     68 
     69 57 is not evenly divisible by 10, so this number is not valid.
     70 
     71 ## Source
     72 
     73 ### Created by
     74 
     75 - @bistik
     76 
     77 ### Contributed to by
     78 
     79 - @alexkalderimis
     80 - @kytrinyx
     81 - @m-dango
     82 - @pgraemer
     83 - @rfilipo
     84 
     85 ### Based on
     86 
     87 The Luhn Algorithm on Wikipedia - http://en.wikipedia.org/wiki/Luhn_algorithm