PROBLEM 88
Hard

Number Palindrome

Programming Basics · JavaScript

</>
STATUS Not solved

TASK

Problem

#88

Given a positive four-digit integer, print `YES` if it is a palindrome.

EXAMPLE

Example

Input
1221
Output
YES

LIMITS

Constraints

1000 ≤ n ≤ 9999
📖
LEARN Theory for this problem
+

### Number Palindrome

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.', 'First decide whether the task operates on characters, words, or the whole string; that determines the correct way to split the data.']

ANSWER Solution
+
const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trimEnd();
let n = Number(input);
let a = Math.floor((n) / (1000));
let b = (((Math.floor((n) / (100))) % (10)) + (10)) % (10);
let c = (((Math.floor((n) / (10))) % (10)) + (10)) % (10);
let d = (((n) % (10)) + (10)) % (10);
if (((a) === (d)) && ((b) === (c))) {
    console.log("YES");
} else {
    console.log("NO");
}