I'm not familiar with Clojure so I can't give you a code example of Clojure. But here in pseudocode
boolean checkdigit(int digit,int checksum):
int sum = converttooctal(digit) % 9 //% is the modulo operator
if(sum == 0):
sum = 9
return checksum - sum == 0
You can also consider 0 and 9 equal and spare the conversion from 0 to 9:
boolean checkdigit(int digit,int checksum):
int sum = converttooctal(digit) % 9 //% is the modulo operator
return checksum - sum == 0 || checksum - sum == 9
Or you could modulo the difference through 9. If it's 0 the result is 0, if it's 9 the result is also 0.
boolean checkdigit(int digit,int checksum):
int sum = converttooctal(digit) % 9 //% is the modulo operator
return (checksum - sum) % 9 == 0
You can also use modulo. You calculate the iterative digit sum with number % 9. If 0 comes out the sum is 9.
sjsu.edu/faculty/watkins/Digitsum0...
I'm not familiar with Clojure so I can't give you a code example of Clojure. But here in pseudocode
You can also consider 0 and 9 equal and spare the conversion from 0 to 9:
Or you could modulo the difference through 9. If it's 0 the result is 0, if it's 9 the result is also 0.
So in one line it would look like this
Thank you for contribution.
I have really tried my best to understand, but have failed.
Could you use examples?
Actually I had an error. You shouldn't convert the digit. And instead modulo through 7.
For 9999|8
The end result isn't 0, so the digit isn't valid
For 1234|2
The end result is 0, so the digit is valid
For 1169|7
1.1169 % 7 = 0 //If you modulo through 7, when the digit sum is 7 instead 0 comes out, so you can consider 0=7.
The end result is 0, so the digit is valid
Updated code
You can also consider 0 and 7 equal and spare the conversion from 0 to 7:
Or you could modulo the difference through 7. The difference must be either 7 or 0 and both have the same result for modulo 7.
So in one line it would look like this
Thank you for clarifying. I have now understood.
It is actually a really neat solution it basically reduces the code to just two functions.
I have learnt something, thank you.