NB. For
nums=. 0 1 11 101 1234
NB. Convert to character:
":&.>nums
+-+-+--+---+----+
|0|1|11|101|1234|
+-+-+--+---+----+
NB. So
(<'0123456789')i.&.>":&.>nums
+-+-+---+-----+-------+
|0|1|1 1|1 0 1|1 2 3 4|
+-+-+---+-----+-------+
NB. or
".&>&.>":&.>nums
+-+-+---+-----+-------+
|0|1|1 1|1 0 1|1 2 3 4|
+-+-+---+-----+-------+
On Fri, Aug 13, 2010 at 4:06 PM, Alex Gian <[email protected]>wrote:
> 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
>
--
Devon McCormick, CFA
^me^ at acm.
org is my
preferred e-mail
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm