Skip to main content
3 of 4
added 421 characters in body
DavidC
  • 25.4k
  • 2
  • 52
  • 105

#Mathematica 77 43

IntegerDigits[n,b] represents n as a list of digits in base b. Each base-b digit is expressed decimally.

For example, 16781313 is not a palindrome in base 17:

IntegerDigits[16781313, 17]

{11, 13, 15, 11, 14, 1}

However, it is a palindrome in base 16:

IntegerDigits[16781313, 16]

{1, 0, 0, 1, 0, 0, 1}


If the ordered pairs in the above examples were entered,

(x=Input[]~IntegerDigits~Input[])==Reverse@x

would return

False (* (because {11, 13, 15, 11, 14, 1} != {1, 14, 11, 15, 13, 11} ) *)

True (* (because {1, 0, 0, 1, 0, 0, 1} is equal to {1, 0, 0, 1, 0, 0, 1} ) *)

DavidC
  • 25.4k
  • 2
  • 52
  • 105