[Jprogramming] an inverse to oblique
Pascal Jasmin
godspiral2000 at yahoo.ca
Wed Feb 17 23:24:17 UTC 2016
The reason I asked, was to make this seemingly useful adverb that lends well to J patterns. The pattern is applying a verb 8 distinct directions across a table (rows cols 2 diagonals front and back)
unoblique =: 4 : ' (;y) (;</.{i.&.> x)} (x $ 0)'
eightdirs =: 1 : '[: |:@:(|."1) $ unoblique [: u&.|. each@:(</.)@:(|."1)@:|: [: |:@:(|."1) $ unoblique [: u each@:(</.)@:(|."1)@:|: $ unoblique [: u&.|. each@:(</.) $ unoblique [: u each@:(</.) [: u"1&.|."1 [: u"1&.|."1&.|: [: u"1 u"1&.|:'
An example use is solving legal moves for othello,
a =. '-OX' i. > cutLF 0 : 0
--------
--------
---OX---
--XXXO--
--XOO---
---O----
--------
--------)
legal x moves,
'-OX_*' {~ 2&(4 : ' (({:y) , 2 {.`4:@.( (0 , 2 1 {~ 2=x)&-:)\ ])^:(x&e.) y') eightdirs a
--------
--***---
--*OX---
--XXXO*-
--XOO**-
--*O**--
---**---
--------
legal o moves,
'-OX_*' {~ 1&(4 : ' (({:y) , 2 {.`4:@.( (0 , 2 1 {~ 2=x)&-:)\ ])^:(x&e.) y') eightdirs a
--------
---**---
-**OX*--
-*XXXO--
-*XOO*--
---O----
--------
--------
2dirs and 4dirs adverbs are just shorter versions of this that many of us have likely used without naming the pattern. More complex 3d versions, if you need them, shouldn't be insanely hard, and useful if you have a verb to use the pattern.
----- Original Message -----
From: Roger Hui <rogerhui.canada at gmail.com>
To: Programming forum <programming at jsoftware.com>
Sent: Wednesday, February 17, 2016 2:48 PM
Subject: Re: [Jprogramming] an inverse to oblique
Instead of portrait and landscape matrices, I myself use tall and wide
matrices, terminology I first heard used by Eugene McDonnell.
On Wed, Feb 17, 2016 at 11:18 AM, Mike Day <mike_liz.day at tiscali.co.uk>
wrote:
> I started with the rectangular case, so have this rather more complicated
> monad:
>
> deo =: 13 : 's$i{;y[ i =. /:;</.i.s =. (((+/(],%)>./)@:(#every)))y'
>
> I was a bit surprised that the result is tacit.
> deo
> (+/ (% , ]) >./)@:(#&>) $ ; {~ [: /: [: ; [: </. [: i. (+/ (] , %)
> >./)@:(#&>)
>
> As Marshall observes, it's not possible to deduce the orientation of
> the rectangle. The verb here assumes a landscape shape.
>
> Unfortunately, the result is wrong if the original was portrait...
>
> eg
> [land =: </.(a.{~97+i.25){~i.3 8
> +-+--+---+---+---+---+---+---+--+-+
> |a|bi|cjq|dkr|els|fmt|gnu|hov|pw|x|
> +-+--+---+---+---+---+---+---+--+-+
>
> [port =: </.(a.{~97+i.25){~i.8 3
> +-+--+---+---+---+---+---+---+--+-+
> |a|bd|ceg|fhj|ikm|lnp|oqs|rtv|uw|x|
> +-+--+---+---+---+---+---+---+--+-+
>
> deo land NB. ok
> abcdefgh
> ijklmnop
> qrstuvwx
>
> deo port NB. !!!
> abcfilor
> dehknqtu
> gjmpsvwx
>
> This dyad allows us to specify landscape or portrait with the
> optional left argument; explicit odd x forces portrait; the default
> is landscape.
>
> deod =: 3 : 0
> 0 deod y
> :
> s =. (((+/(] (x |.,) %)>./)@:(#every)))y
> i =. /:;</.i.s
> s$i{;y
> )
>
> deod land
> abcdefgh
> ijklmnop
> qrstuvwx
>
> 1 deod port
> abc
> def
> ghi
> jkl
> mno
> pqr
> stu
> vwx
>
> I've assumed that the input is properly derived from oblique
> boxing of a rectangular array.
>
> Mike
>
>
>
> On 17/02/2016 17:42, Marshall Lochbaum wrote:
>
>> deoblique =: ($:~ [: ((1+i.,i:)>./) #@>) : ([ $ (/:&; </.@:i.)~)
>>
>
>
> ---
> This email has been checked for viruses by Avast antivirus software.
> https://www.avast.com/antivirus
>
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
More information about the Programming
mailing list