[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

[QUIZ] #122 Credit Card Validator (solution

Pieter V.

5/3/2007 3:03:00 AM

It's a hack job, nothing terribly pretty or well abstracted, but it
certainly hits the 80% mark.

----
num = ARGV.join

def luhn(number)
double = true
luhn = 0
number.scan(/./) do |digit|
n = digit.to_i * (double ? 2 : 1)
luhn += n % 10 + n / 10
double = !double
end
(luhn % 10) == 0
end

def type(number)
case number
when /^34|37[0-9]{13}/ then "AMEX"
when /^6011[0-9]{12}/ then "Discover"
when /^5[1-5][0-9]{14}/ then "MasterCard"
when /^4([0-9]{12}|[0-9]{15})/ then "Visa"
else "Unknown"
end
end

puts "Type: %s" % type(num)
puts "Valid: %s" % (luhn(num) ? :true : :false)

1 Answer

koolfireiv

8/2/2010 7:26:00 AM

0

On Aug 1, 9:12 am, Aviroce <dudaras...@gmail.com> wrote:
> On Jul 31, 12:48 pm, koolfireiv <koolfireii...@gmail.com> wrote:
>
> > On Jul 31, 11:33 pm, Aviroce <dudaras...@gmail.com> wrote:
>
> > > GREAT MARTYR ISSA BATRAN WAS ASSASSINATED BY MILITANT AND ATROCIOUS
> > > SAVAGE JEWS RAINING MISSILES ON HIS LOCATION
> > > By Aviroce
>
> > Palestinians should act namelessly, formlessly, and
> > .....exactly what on earth is it you want them to do,the last
> > word suicidely,does not exist,and to achieve the first two acts,they
> > have to commit suicide,at least give them some sensible advice.
>
> Look at this site.  Someone else seems to have the same idea.http://dictionary.reference.com/browse...
>
> What the dictionary posts is noun and verb.  I used it as an adjective
> as the same flows so easily from it.
>
> Nameless could mean just a symbol not real name and family name, #3
> for example.  Formless, no grouping to be recognized yet sent on
> mission.  To understand this terminology, you need to read "The Art of
> War" by Tsun Tzu.  They have a recording of the book.  It is good to
> listen to it in your car.
>
> The advice, a suicide bomber comes from no where with a target and
> blows himself up taking along all there around him.  May Allah Bless
> His Soul and his community can never forget his contribution to
> protect it..

su·i·cid·al is the adjective of suicide.........suicidely no way you
can use this word as an adjective in English of suicide