fssnippets / fssnip-website

Source code for the F# Snippets web site
http://fssnip.net
103 stars 36 forks source link

Luhn algorithm snippet rejected #93

Open MarneeDear opened 5 years ago

MarneeDear commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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!