[Jprogramming] Splitting an integer into its digits
Dan Bron
j at bron.us
Sat Aug 14 04:22:57 HKT 2010
10&#.^:_1
-----Original Message-----
From: programming-bounces at jsoftware.com
[mailto:programming-bounces at jsoftware.com] On Behalf Of Alex Gian
Sent: Friday, August 13, 2010 4:07 PM
To: Programming forum
Subject: [Jprogramming] Splitting an integer into its digits
This is a fairly common requirement, especially in mathematical puzzles
or, for example, in regard to oddities like "happy numbers", and so on.
There are two possible approaches, either the Perl-like conversion to a
string which is then split or "exploded", or the more common repeated
integer division.
What would be considered a good, efficient J implementation, forgoing
explicit loops, etc? Basically I'm looking for a verb "explode" which
will return a string comprising the digits of a positive integer.
I am still pretty much learning J, so a few hints rather than a full,
exhaustive solution would be appreciated.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
More information about the Programming
mailing list