Jsoftware
High-Performance Development Platform

APWJ exercises for the reader [1 of 4]

View: New views
5 Messages — Rating Filter:   Alert me  

APWJ exercises for the reader [1 of 4]

by Ian Clark-6 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

In At Play With J Edn 1, there were 4 questions left as exercises for
the reader. In Edn 2 we want to provide the answers in an Appendix.

Just so I don't get them wrong, could the forum please suggest what
the answers should be? You may have to refer to the Wiki page.

I'm putting each question in a separate thread.

+++++
In Chapter 5 Jacobi's method
http://www.jsoftware.com/jwiki/Doc/Articles/Play113 [see midway]

"Problem 1: Define a verb which takes as argument a positive even
integer n and yields a permutation which, repeatedly applied to a
conforming identity permutation, produces, in successive pairs of
items, all possible choices of 2 items from n, with no duplications.

Problem 2: How many of the !n permutations of even order n are
solutions to problem 1?"
+++++

Ian Clark
Subeditor, APWJ Edn 2
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Re: APWJ exercises for the reader [1 of 4]

by Roger Hui :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Solution to Problem 1:

magicperm=: C. @ < @ (|.@:>: , }.) @ (i.&.-:)

   magicperm 2
0 1
   magicperm 4
0 2 3 1
   magicperm 6
0 2 4 1 5 3
   magicperm 8
0 2 4 1 6 3 7 5

Check:

seq  =: 3 : 'y {^:(}:i.#y) i.#y'
pairs=: /:~ @ (>/"1 |."_1 ]) @ (_2 ]\ ,@seq)
NB. comb from  http://www.jsoftware.com/help/dictionary/cfor.htm

   (2&comb -: pairs@magicperm)"0 }. 2*i.8
1 1 1 1 1 1 1



----- Original Message -----
From: Ian Clark <earthspotty@...>
Date: Wednesday, November 11, 2009 3:56
Subject: [Jprogramming] APWJ exercises for the reader [1 of 4]
To: Programming forum <programming@...>

> In At Play With J Edn 1, there were 4 questions left as
> exercises for
> the reader. In Edn 2 we want to provide the answers in an Appendix.
>
> Just so I don't get them wrong, could the forum please suggest what
> the answers should be? You may have to refer to the Wiki page.
>
> I'm putting each question in a separate thread.
>
> +++++
> In Chapter 5 Jacobi's method
> http://www.jsoftware.com/jwiki/Doc/Articles/Play113 [see midway]
>
> "Problem 1: Define a verb which takes as argument a positive even
> integer n and yields a permutation which, repeatedly applied to a
> conforming identity permutation, produces, in successive pairs of
> items, all possible choices of 2 items from n, with no duplications.
>
> Problem 2: How many of the !n permutations of even order n are
> solutions to problem 1?"
> +++++
>
> Ian Clark
> Subeditor, APWJ Edn 2


----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Re: APWJ exercises for the reader [1 of 4]

by Roger Hui :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> Problem 2: How many of the !n permutations of even order n are
> solutions to problem 1?

Problem 2 probably does not have an easy solution
as the sequence 2 8 48 1152 34560 (for n=2 4 6 8 10)
is not a subsequence in the Online Encyclopedia of
Integer Sequences.

http://www.research.att.com/~njas/sequences/index.html

   +/ (2 comb n)&-:@pairs@(A.&(i.n))"0 i.!n=: 2
2
   +/ (2 comb n)&-:@pairs@(A.&(i.n))"0 i.!n=: 4
8
   +/ (2 comb n)&-:@pairs@(A.&(i.n))"0 i.!n=: 6
48
...



----- Original Message -----
From: Roger Hui <rhui000@...>
Date: Wednesday, November 11, 2009 11:03
Subject: Re: [Jprogramming] APWJ exercises for the reader [1 of 4]
To: Programming forum <programming@...>

> Solution to Problem 1:
>
> magicperm=: C. @ < @ (|.@:>: , }.) @ (i.&.-:)
>
>    magicperm 2
> 0 1
>    magicperm 4
> 0 2 3 1
>    magicperm 6
> 0 2 4 1 5 3
>    magicperm 8
> 0 2 4 1 6 3 7 5
>
> Check:
>
> seq  =: 3 : 'y {^:(}:i.#y) i.#y'
> pairs=: /:~ @ (>/"1 |."_1 ]) @ (_2 ]\ ,@seq)
> NB. comb from  http://www.jsoftware.com/help/dictionary/cfor.htm
>
>    (2&comb -: pairs@magicperm)"0 }. 2*i.8
> 1 1 1 1 1 1 1
>
>
>
> ----- Original Message -----
> From: Ian Clark <earthspotty@...>
> Date: Wednesday, November 11, 2009 3:56
> Subject: [Jprogramming] APWJ exercises for the reader [1 of 4]
> To: Programming forum <programming@...>
>
> > In At Play With J Edn 1, there were 4 questions left as
> > exercises for
> > the reader. In Edn 2 we want to provide the answers in an Appendix.
> >
> > Just so I don't get them wrong, could the forum please suggest what
> > the answers should be? You may have to refer to the Wiki page.
> >
> > I'm putting each question in a separate thread.
> >
> > +++++
> > In Chapter 5 Jacobi's method
> > http://www.jsoftware.com/jwiki/Doc/Articles/Play113 [see midway]
> >
> > "Problem 1: Define a verb which takes as argument a positive even
> > integer n and yields a permutation which, repeatedly applied
> to a
> > conforming identity permutation, produces, in successive pairs of
> > items, all possible choices of 2 items from n, with no duplications.
> >
> > Problem 2: How many of the !n permutations of even order n are
> > solutions to problem 1?"
> > +++++
> >
> > Ian Clark
> > Subeditor, APWJ Edn 2
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Re: APWJ exercises for the reader [1 of 4]

by Roger Hui :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> pairs=: /:~ @ (>/"1 |."_1 ]) @ (_2 ]\ ,@seq)

pairs=: [: /:~ _2 /:~\ ,@seq



----- Original Message -----
From: Roger Hui <rhui000@...>
Date: Wednesday, November 11, 2009 11:30
Subject: Re: [Jprogramming] APWJ exercises for the reader [1 of 4]
To: Programming forum <programming@...>

> > Problem 2: How many of the !n permutations of even order n are
> > solutions to problem 1?
>
> Problem 2 probably does not have an easy solution
> as the sequence 2 8 48 1152 34560 (for n=2 4 6 8 10)
> is not a subsequence in the Online Encyclopedia of
> Integer Sequences.
>
> http://www.research.att.com/~njas/sequences/index.html
>
>    +/ (2 comb n)&-:@pairs@(A.&(i.n))"0 i.!n=: 2
> 2
>    +/ (2 comb n)&-:@pairs@(A.&(i.n))"0 i.!n=: 4
> 8
>    +/ (2 comb n)&-:@pairs@(A.&(i.n))"0 i.!n=: 6
> 48
> ...
>
>
>
> ----- Original Message -----
> From: Roger Hui <rhui000@...>
> Date: Wednesday, November 11, 2009 11:03
> Subject: Re: [Jprogramming] APWJ exercises for the reader [1 of 4]
> To: Programming forum <programming@...>
>
> > Solution to Problem 1:
> >
> > magicperm=: C. @ < @ (|.@:>: , }.) @ (i.&.-:)
> >
> >    magicperm 2
> > 0 1
> >    magicperm 4
> > 0 2 3 1
> >    magicperm 6
> > 0 2 4 1 5 3
> >    magicperm 8
> > 0 2 4 1 6 3 7 5
> >
> > Check:
> >
> > seq  =: 3 : 'y {^:(}:i.#y) i.#y'
> > pairs=: /:~ @ (>/"1 |."_1 ]) @ (_2 ]\ ,@seq)
> > NB. comb from  http://www.jsoftware.com/help/dictionary/cfor.htm
> >
> >    (2&comb -: pairs@magicperm)"0 }. 2*i.8
> > 1 1 1 1 1 1 1
> >
> >
> >
> > ----- Original Message -----
> > From: Ian Clark <earthspotty@...>
> > Date: Wednesday, November 11, 2009 3:56
> > Subject: [Jprogramming] APWJ exercises for the reader [1 of 4]
> > To: Programming forum <programming@...>
> >
> > > In At Play With J Edn 1, there were 4 questions left as
> > > exercises for
> > > the reader. In Edn 2 we want to provide the answers in an
> Appendix.> >
> > > Just so I don't get them wrong, could the forum please
> suggest what
> > > the answers should be? You may have to refer to the Wiki page.
> > >
> > > I'm putting each question in a separate thread.
> > >
> > > +++++
> > > In Chapter 5 Jacobi's method
> > > http://www.jsoftware.com/jwiki/Doc/Articles/Play113 [see midway]
> > >
> > > "Problem 1: Define a verb which takes as argument a positive even
> > > integer n and yields a permutation which, repeatedly applied
> > to a
> > > conforming identity permutation, produces, in successive
> pairs of
> > > items, all possible choices of 2 items from n, with no
> duplications.> >
> > > Problem 2: How many of the !n permutations of even order n are
> > > solutions to problem 1?"
> > > +++++
> > >
> > > Ian Clark
> > > Subeditor, APWJ Edn 2


----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Re: APWJ exercises for the reader [1 of 4]

by Ian Clark-6 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks, Roger.


On Wed, Nov 11, 2009 at 8:09 PM, Roger Hui <rhui000@...> wrote:

>> pairs=: /:~ @ (>/"1 |."_1 ]) @ (_2 ]\ ,@seq)
>
> pairs=: [: /:~ _2 /:~\ ,@seq
>
>
>
> ----- Original Message -----
> From: Roger Hui <rhui000@...>
> Date: Wednesday, November 11, 2009 11:30
> Subject: Re: [Jprogramming] APWJ exercises for the reader [1 of 4]
> To: Programming forum <programming@...>
>
>> > Problem 2: How many of the !n permutations of even order n are
>> > solutions to problem 1?
>>
>> Problem 2 probably does not have an easy solution
>> as the sequence 2 8 48 1152 34560 (for n=2 4 6 8 10)
>> is not a subsequence in the Online Encyclopedia of
>> Integer Sequences.
>>
>> http://www.research.att.com/~njas/sequences/index.html
>>
>>    +/ (2 comb n)&-:@pairs@(A.&(i.n))"0 i.!n=: 2
>> 2
>>    +/ (2 comb n)&-:@pairs@(A.&(i.n))"0 i.!n=: 4
>> 8
>>    +/ (2 comb n)&-:@pairs@(A.&(i.n))"0 i.!n=: 6
>> 48
>> ...
>>
>>
>>
>> ----- Original Message -----
>> From: Roger Hui <rhui000@...>
>> Date: Wednesday, November 11, 2009 11:03
>> Subject: Re: [Jprogramming] APWJ exercises for the reader [1 of 4]
>> To: Programming forum <programming@...>
>>
>> > Solution to Problem 1:
>> >
>> > magicperm=: C. @ < @ (|.@:>: , }.) @ (i.&.-:)
>> >
>> >    magicperm 2
>> > 0 1
>> >    magicperm 4
>> > 0 2 3 1
>> >    magicperm 6
>> > 0 2 4 1 5 3
>> >    magicperm 8
>> > 0 2 4 1 6 3 7 5
>> >
>> > Check:
>> >
>> > seq  =: 3 : 'y {^:(}:i.#y) i.#y'
>> > pairs=: /:~ @ (>/"1 |."_1 ]) @ (_2 ]\ ,@seq)
>> > NB. comb from  http://www.jsoftware.com/help/dictionary/cfor.htm
>> >
>> >    (2&comb -: pairs@magicperm)"0 }. 2*i.8
>> > 1 1 1 1 1 1 1
>> >
>> >
>> >
>> > ----- Original Message -----
>> > From: Ian Clark <earthspotty@...>
>> > Date: Wednesday, November 11, 2009 3:56
>> > Subject: [Jprogramming] APWJ exercises for the reader [1 of 4]
>> > To: Programming forum <programming@...>
>> >
>> > > In At Play With J Edn 1, there were 4 questions left as
>> > > exercises for
>> > > the reader. In Edn 2 we want to provide the answers in an
>> Appendix.> >
>> > > Just so I don't get them wrong, could the forum please
>> suggest what
>> > > the answers should be? You may have to refer to the Wiki page.
>> > >
>> > > I'm putting each question in a separate thread.
>> > >
>> > > +++++
>> > > In Chapter 5 Jacobi's method
>> > > http://www.jsoftware.com/jwiki/Doc/Articles/Play113 [see midway]
>> > >
>> > > "Problem 1: Define a verb which takes as argument a positive even
>> > > integer n and yields a permutation which, repeatedly applied
>> > to a
>> > > conforming identity permutation, produces, in successive
>> pairs of
>> > > items, all possible choices of 2 items from n, with no
>> duplications.> >
>> > > Problem 2: How many of the !n permutations of even order n are
>> > > solutions to problem 1?"
>> > > +++++
>> > >
>> > > Ian Clark
>> > > Subeditor, APWJ Edn 2
>
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm