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 -: pa...@magicperm)"0 }. 2*i.8
1 1 1 1 1 1 1
----- Original Message -----
From: Ian Clark <[email protected]>
Date: Wednesday, November 11, 2009 3:56
Subject: [Jprogramming] APWJ exercises for the reader [1 of 4]
To: Programming forum <[email protected]>
> 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