[Jprogramming] Beginner's Question: How to reverse a number's digits?
Devon McCormick
devonmcc at gmail.com
Tue Apr 9 20:23:26 UTC 2019
To elaborate on Raul's answer: the "format" verb ": formats a number,
simply converting a number to a character vector when used monadically; its
inverse is the "do" verb ". which executes a character string as a J
expression, so the character representation of a number is turned into the
number represented.
On Tue, Apr 9, 2019 at 4:12 PM Raul Miller <rauldmiller at gmail.com> wrote:
> Probably the simplest approach would be:
>
> |.&.": 123
> 321
>
> If you're doing something unusual, though, maybe we'd need to do something
> else?
>
> Thanks,
>
> --
> Raul
>
> On Tue, Apr 9, 2019 at 4:07 PM Thomas Bulka <thomas.bulka at posteo.de>
> wrote:
> >
> > Hi everyone,
> >
> > while working my way through the problems on Project Euler, I stumbled
> > over a question which might be completely trivial - however, I have not
> > been able to find an answer, yet.
> >
> > Say, I want to reverse the digits of a number (that is, I want to turn
> > 123 into 321) - how do I do that? Of course, |. does not work, since 123
> > is not an array. Is there a way to turn a number into a string (and the
> > other way round). Or is there a better way?
> >
> > Probably I've been looking in the wrong direction, so I'd very much
> > appreciate any help on that topic.
> >
> > Thank you very much in advance!
> >
> > Regards,
> >
> > Thomas
> >
> > ----------------------------------------------------------------------
> > For information about J forums see http://www.jsoftware.com/forums.htm
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
--
Devon McCormick, CFA
Quantitative Consultant
More information about the Programming
mailing list