[back]

Palindromic Integers

An integer is palindromic if it's the same as itself with its digits written in reverse order. For example 12321 is a palindromic integer. Note that negative numbers are not palindromic.

Implement the function

val is_palindromic : int -> bool

so that is_palindromic n is true if and only if n is palindromic. You may only use arithmetic operations. In particular, you may not convert n into a string.

Examples

let _ = assert (is_palindromic 0)
let _ = assert (is_palindromic 7)
let _ = assert (is_palindromic 12321)
let _ = assert (not (is_palindromic 12345))
let _ = assert (not (is_palindromic (-121)))