Search code examples
reversedigitsparipari-gp

How to reverse the digits of an integer in PARI/GP?


As part of a mini-project I'm doing, I need a way to reverse the digits of an integer in PARI/GP (the project is mainly on palindromic numbers and digit sums).

What I'm trying to achieve in code form is fun(13453) giving 35431.

For example, I've tried doing the following:

  • Vecrev(digits(13453)) gives out [3,5,4,3,1] but I don't know how to concatenate each consecutive element in this list.

  • I don't think there is a preset function for this, as rev, reverse, or digitrev are not defined in PARI/GP.

Could someone show me how this can be done? Preferably, loops are undesirable as I want a simple function to put into, say, an if statement or a for loop.


Solution

  • Or: fromdigits(Vecrev(digits(13453)))