 So for this week's assignment, we're actually using something known as the loon's check algorithm So loon Hans loon from IBM developed this algorithm back in 1950-1954 ish to basically validate Credit cards validate Cards, I'll just shorthand that and we can prove this we can look at it And here's a valid credit card look my camera zoom and focus on that. Don't worry It is empty But we're gonna go ahead and use this card to sort of prove the loon algorithm So I'm gonna just write it out here for a second for a skip ahead. I gotta write 3529 eight nine two six three zero four nine four So how does the loon check work one of the things that we have to do is we have to think about How we're presenting our numbers. These aren't just kind of this isn't a math. I'm not separating things by Commas, it's not a numerical value it we think about it in at least programming as more of a string And so if we looked at the position of these cards, we actually start counting at zero And that means if I keep counting up one two three four five six seven eight nine Ten eleven twelve thirteen fourteen fifteen Okay, so we've laid them out from zero to fifteen even though there are sixteen digits. I know so What we can do with this is we can do something first known as the sum of Odd places. I just counted out a bunch of numbers Everywhere I have an odd number. I'm gonna add that now one of the things I do have to point out is I'm going to go Right to left. I know that may not seem like a big deal when we're dealing with say Visa However, if we're looking at different cards like master card or American Express or discover this actually sort of matters So I'm gonna start and I'm gonna start counting from Yeah, from sort of my 15 slot four plus zero plus six plus nine plus nine plus five Plus seven plus eight plus seven plus eight So all I do is I add these together. I'll just add them so four and zero that's four But a four and a six is gonna produce a ten Ten and nine produces nineteen nine and nine are nineteen and nine produces twenty eight twenty-eight thirty three forty forty eight So by adding all of these not these odd placed numbers I get Forty eight all right simple enough nothing too terribly crazy going on there But what about those even spots? I haven't done anything with those. Well, let me go ahead and just write them out first nine three two eight two three Four four Now I purposely did not put the plus sign in between them And there's a good reason for it because one of the things I'm gonna have to do is I'm actually gonna have to double every number But that's not just it sure for something like four right here. I Can double it and that's gonna be fine same with this one. I can double this one However, I'm gonna come back over here to this nine When I double this number I get an 18 make that a little bit more obvious. I get an 18. I Don't add the 18. However, what I do is I actually break it down and I say well, I'm gonna add one And I'm gonna add eight That eight again This is going to produce Nine I know that seems odd now I'm gonna put it down here in a different color just to kind of keep it in Track I produce a nine Well, I do The same algorithm I double the three this gives me a six the six is perfectly fine The six is not a double digit so I can just go ahead and add that to my equation. I Can do the exact same thing with the two I double the two I get a four I add the four However, when I get to this 18, I double the 18 And I get a 16 or I double the eight and I get a 16 I do the exact same thing I did with the nine. I'm gonna have to add the one and the six so one plus six equals seven I Keep going luckily all three of our all four of these numbers can get doubled Without having to kind of run through that second part so four six eight eight Four six eight eight So if I take those numbers and I'm gonna move them a little up here So it's a little easier for us to see so nine plus six that produces 15 15 plus four that produces 19 19 plus 7 that's 26 26 plus 4 equals 30 Trying to avoid my head as you can imagine 30 plus 6 equals 36 36 plus 8 is gonna equal 44 and 44 plus 8 equals 52 Okay, so why does any of this matter? I'm gonna delete a few things Now that I've taken all this math And I'm just going to write that out. I'm going to state now that I've got the sum of odd places in the sum of even places 52 If I take these two numbers and I add them together I get 100 now The Lewin check basically says that if when I've won these two sums if I sum the odds and I sum the evens Using the double approach if the number that I get is Divisible by 10 I have a valid card Let's say for example, I didn't have a valid card because we just you know, yes We prove that this is a valid card if however, I had changed let's say for example this four had been a Five well everything would have been completely off my odd digits would have been 49. I would have added that together I would have produced 101 and let me actually do this and said I would have went 101 Modulus 10 and when I checked to see if it was Divisible by zero this is not true. Thus it would have been an invalid card