Comments (10)
@taliafranco Oops, just noticed this issue.
From my understanding, (cc_number % 10 = digit1) is to obtain the last number(if im not mistaken)?
That's right.
But why is digit2 = digit1?
The key to understanding how this works lies right below that line — since digit1
is assigned AFTER its value's assigned to digit2
, it means it will always contain the value of digit1
from the previous loop iteration. Therefore, after completing all iterations it will hold last but one value processed — the second digit since we progress from the end to the start of the number.
and why sum_of_even += digit1?
I assume you're referring to the following lines of code:
Lines 33 to 36 in b2324e2
According to the algorithm description, point number 2 and the relevant portion of the point number 1:
- Multiply every other digit by 2, starting with the number’s second-to-last digit, and then add those products' digits together.
- Add the sum to the sum of the digits that weren’t multiplied by 2.
- If the total’s last digit is 0 (or, put more formally, if the total modulo 10 is congruent to 0), the number is valid!
We need to add all digits that weren't multiplied by 2. According to the definition, the other digits are odd and those that were not multiplied by two must be even thereof.
Hope it helps.
from cs50.
The problem I have with the explanation is that the generic word "it" is used too often. I cannot figure out which part "it" is referring to in each line. Some clarification here would help.
from cs50.
from cs50.
from cs50.
from cs50.
from cs50.
from cs50.
from cs50.
from cs50.
from cs50.
Related Issues (11)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cs50.