In the coding, only the second number of 6144 will return true. This is because that 6144 is the only value that makes both rem and checkDigit equal the same values, being 4. Furthermore, the variable nRemaining is used to simplify the statements for d3, d2, and d1. Because nRemaining initially equals the equation “n ÷ 10”, d3 can be rewritten as “(n / 10) % 10”. nRemaining’s value is again divided by 10; thus, d2 could be rewritten as “((n / 10) / 10) % 10”. Again, nRemaining is redefined by ¹⁄10th of itself; d1 can be rewritten as “(((n / 10) / 10) / 10) % 10”. However, it is easier to write d1 as “nRemaining % 10”, which is why it is used.
−Phoenix
Spot on, Phoenix. Concise and accurate.
ReplyDelete