# Description
Write a function that checks whether a credit card number is correct or not, using the Luhn algorithm.

The algorithm is as follows:

* From the rightmost digit, which is the check digit, moving left, double the value of every second digit; if the product of this doubling operation is greater than 9 (e.g., 8 × 2 = 16), then sum the digits of the products (e.g., 16: 1 + 6 = 7, 18: 1 + 8 = 9) or alternatively subtract 9 from the product (e.g., 16: 16 - 9 = 7, 18: 18 - 9 = 9).
* Take the sum of all the digits.
* If the total modulo 10 is equal to 0 (if the total ends in zero) then the number is valid according to the Luhn formula; else it is not valid.

The input is a string with the full credit card number, in groups of 4 digits separated by spaces, i.e. "1234 5678 9012 3456"  
Don´t worry about wrong inputs, they will always be a string with 4 groups of 4 digits each separated by space.

# Examples

`valid_card?("5457 6238 9823 4311") # True`

`valid_card?("5457 6238 9323 4311") # False`

for reference check: https://en.wikipedia.org/wiki/Luhn_algorithm

Difficulty: introductory

Starter code:

def valid_card(card):
	

Solutions:
def valid_card(card):
    s = list(map(int, str(card.replace(' ', ''))))
    s[0::2] = [d * 2 - 9 if d * 2 > 9 else d * 2 for d in s[0::2]]
    return sum(s) % 10 == 0

def valid_card(card_number):
    total = 0
    for i, a in enumerate(reversed(card_number.replace(' ', ''))):
        if i % 2:
            current = int(a) * 2
            total += current - 9 if current > 8 else current
        else:
            total += int(a)
    return total % 10 == 0

def valid_card(card):
    li = []
    print(card)
    digits = card.replace(' ', '')[::-1]
    for i, d in enumerate(digits):
        di = int(d)
        if i % 2 != 0:
            di = di * 2
            if di > 9:
                di = di - 9
            li.append(di)
        else:
            li.append(di)
    return True if sum(li) % 10 == 0 else False

valid_card=lambda c:sum(sum(divmod(int(d)<<i%2,10))for i,d in enumerate(c.replace(' ','')[::-1]))%10<1

def valid_card(card):    
    card=str(card.replace(' ',''))
    return (sum(map(int, str(card)[1::2])) + \
            sum(sum(map(int, str(i*2))) for i in \
            map(int, str(card)[0::2]))) % 10 == 0

def valid_card(card):
    return sum([2*c,2*c-9][2*c>9] if i%2 else c for i,c in enumerate(map(int,card.replace(" ","")[::-1])))%10==0

def valid_card(card):
    card_str = card.replace(' ', '')

    index = 0
    sum_card = 0
    while index < len(card_str):
        number = 0
        if index % 2 == 0:
            number = int(card_str[index]) * 2
        else:
            number = int(card_str[index])
        
        if number >= 10:
            number_arr = list(str(number))
            number = 0
            for num in number_arr:
                number += int(num)

        sum_card += number

        index += 1

    return sum_card % 10 == 0