Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Luhn algorithm snippet rejected #93

Open
MarneeDear opened this issue May 21, 2019 · 4 comments
Open

Luhn algorithm snippet rejected #93

MarneeDear opened this issue May 21, 2019 · 4 comments

Comments

@MarneeDear
Copy link

MarneeDear commented May 21, 2019

I tried to submit a snippet but I keep getting an error. On the entry page I get a message that it parsed and seemed ok.

It is an implementation of the Luhn algorithm
https://en.wikipedia.org/wiki/Luhn_algorithm#C#

This is my code

open System.Text.RegularExpressions
open System

let input = "378282246310005"

let digits = input |> Seq.filter System.Char.IsNumber |> Seq.map (string >> int)
if (digits |> Seq.length) <> 0 then
    let multiply i n = 
        match i % 2 with 
        | 1 when n < 5 -> n * 2 
        | 1 -> (n * 2) - 9 
        | _ -> n
    let sum = digits |> Seq.rev |> Seq.mapi multiply |> Seq.sum
    sum % 10 = 0   
else
    false
@tpetricek
Copy link
Member

I just tried uploading a snippet and it worked: http://fssnip.net/7Wl

I'm not sure what could be going wrong - the only thing I can think of is the Captcha, which might be perhaps blocked somehow on some more sensitive browsers?

@MarneeDear
Copy link
Author

Thanks, Tomas.

Sorry I didn't put in the error message.

Inserting snippet failed!

Some of the inputs for the snippet were not valid,
but the client-side checking did not catch that. Please consider opening a bug issue!

I have tried on Chrome and Firefox (Nightly). I get the same error on both.

@tpetricek
Copy link
Member

This is strange! I tried again, with a public snippet, and it worked: http://fssnip.net/7Wn/title/Phantom-type-example Here is what my page looked like after filling all the fields (using recent Firefox):

screen

Can you share a similar screenshot of your thing?

@MarneeDear
Copy link
Author

I just got it to work, but not sure why. The only difference, I think, is that I made the description shorter.

Instead of

The Luhn algorithm or Luhn formula, also known as the "modulus 10" or "mod 10" algorithm, named after its creator, IBM scientist Hans Peter Luhn, is a simple checksum formula used to validate a variety of identification numbers, such as credit card numbers, IMEI numbers, National Provider Identifier numbers in the United States, Canadian Social Insurance Numbers, Israel ID Numbers, Greek Social Security Numbers (ΑΜΚΑ), and survey codes appearing on McDonald's, Taco Bell, and Tractor Supply Co. receipts. It is described in U.S. Patent No. 2,950,048, filed on January 6, 1954, and granted on August 23, 1960. 

I put this

The Luhn algorithm or Luhn formula, also known as the "modulus 10" or "mod 10" algorithm, is a simple checksum formula used to validate a variety of identification numbers, such as credit card numbers.

This is what I did and it worked:

image

Thank you for your help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants