Skip to content

Instantly share code, notes, and snippets.

@digitalBush
Created April 18, 2012 01:58
Show Gist options
  • Save digitalBush/2410522 to your computer and use it in GitHub Desktop.
Save digitalBush/2410522 to your computer and use it in GitHub Desktop.
F# Luhny Bin
let luhn chars =
let rec luhn even sum digits =
match digits, even with
| [], _ -> sum % 10 = 0
| head :: tail, false when head > 4 -> luhn true (sum + head*2-9) tail
| head :: tail, false -> luhn true (sum + head*2) tail
| head :: tail, true -> luhn false (sum + head) tail
chars
|> List.rev
|> List.map(fun (c:char) -> int c - int '0')
|> luhn true 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment