I think the trailing : /: is misleading. Ian Clark said
he "cheated" and it seems to have come from the verb "sort"
which is provided in J scripts for monadic and dyadic use.
Only the monad /:~ is needed here.
Also, for understanding, let's drop the "each" idiom, &.> ,
and consider just one number.
/:~ @ ": a NB. sort the character representation of a
01123
The "atop" binds the monadic sort and format. If you don't
like atop, you can replace it by "cap", [: .
Brackets now appear to be necessary to bind the elements
together:
[:/:~": a
|domain error
| [:/:~":a
but
([:/:~":) a NB. replace atop with cap
01123
So finally (?), we seem to have
([:/:~":)&.> a,b NB. sort each of a and b under format
+-----+-----+
|01123|01123|
+-----+-----+
However, that still might not be quite right. Consider
d =: 01213
([:/:~":)&.> a,b,d
+-----+-----+----+
|01123|01123|1123|
+-----+-----+----+
So d's leading zero gets lost!
If David Vaughan regards d as equivalent to a and b,
more care is needed.
Perhaps this would then be a reasonable approach:
\:~@":"0 a,b,d NB. dec. sort forces zeros to the right.
32110
32110
3211
It would be easy enough to regard 0 and blank as
equivalent.
Mike
On 29/09/2011 10:45 AM, Linda Alvord wrote:
> The only difference between the correct and the incorrect result is a space
> before the second : . Should a space make a difference ever? In the
> correct result I can't understand what it is, what it does and why it does
> it.
>
> /:~ :/:@":&.>a,b
> ------T-----┐
> │01123│01123│
> L-----+------
>
>
> /:~:([:/:": )&.>a,b
> 0 1
>
> Since I set out originally to remove "atop", how can I do it?
>
> /:~ :([: /: ":)&.>a,b
> ------T-----┐
> │10123│32110│
> L-----+------
>
> Hope you can help. Thanks. Linda
>
> -----Original Message-----
> From: [email protected]
> [mailto:[email protected]] On Behalf Of Ian Clark
> Sent: Thursday, September 22, 2011 9:13 PM
> To: Programming forum
> Subject: Re: [Jprogramming] Permutations
>
> Off-the-cuff...
>
> a=: 10123
> b=: 32110
> c=: 32100
> -:/ /:~ :/:@":&.> a,b
> 1
> -:/ /:~ :/:@":&.> a,c
> 0
>
>
> On Thu, Sep 22, 2011 at 10:41 PM, David Vaughan
> <[email protected]> wrote:
>> Hi, what is the best (fastest) way to check whether a number is a
> permutation of another number?
>> I've tried listing all permutations of one number and checking whether the
> other number is in the list of permutations. This seems pretty slow, so I
> was hoping for a faster method.
>> Thanks.
>> ----------------------------------------------------------------------
>> For information about J forums see http://www.jsoftware.com/forums.htm
>>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm