Lucky Ticket Number
Programming Basics · JavaScript
TASK
Problem
Given a six-digit string (leading zero allowed), print `LUCKY` if the sum of first three digits equals the sum of last three.
EXAMPLE
Example
123321
LUCKY
LIMITS
Constraints
exactly 6 digits
LEARN
Theory for this problem
+
### Lucky Ticket Number
Integer division separates higher decimal/time units, while `%` returns the remainder. These two operations let a program isolate digits or split a total number of seconds/minutes into components.
NEED HELP?
Hints
+
['Decide which part comes from division and which part comes from the remainder.', 'Check the first and last characters separately, and preserve meaningful spaces or letter case when the statement requires it.']
ANSWER
Solution
+
const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trimEnd();
let s = input;
let a = ((Number(s[0]) + Number(s[1])) + Number(s[2]));
let b = ((Number(s[3]) + Number(s[4])) + Number(s[5]));
if ((a) === (b)) {
console.log("LUCKY");
} else {
console.log("NO");
}