Re: [Jprogramming] Writing dyadic function with left/right parameters swapped

2017-06-05 Thread Michael Rice
@ Bill Lam C-style. That's funny. I know just enough C to get around. It's not that I dislike it, just never went in that direction. I actually modeled my flip function after the hailstone example at the top of Chapter 10 in Learning J: http://www.jsoftware.com/help/learning/10.htm halve =: -:

Re: [Jprogramming] Writing dyadic function with left/right parameters swapped

2017-06-05 Thread Raul Miller
I guess, if I were implementing what I think you are trying to implement, I might do it like this: move_table=: <:(,|."1)(#~0<*/"1)~.,/,/_3&{.\@/:~"1(,|:"2)>|:((;|.)@(1++)+/)\i.5 flip=: ~: (i.15)&e. legal_moves=: [ #~ 6 = 2 #. { search=:3 :0 ((15#1) flip y) search i.0 3 NB. x: board; y: moves

Re: [Jprogramming] Writing dyadic function with left/right parameters swapped

2017-06-05 Thread Michael Rice
2) Is the move list associated with each board 3) Is the move path, also a list, you want returned (printed?) if you reach a winning board state, i.e., just one peg remaining on the board. On Mon, Jun 5, 2017 at 2:18 AM, Raul Miller wrote: > What is the difference between 2 (a list of moves

Re: [Jprogramming] Writing dyadic function with left/right parameters swapped

2017-06-05 Thread bill lam
Thank you for explanation. I think code will be easier to read if you had written in a c-style, because your j-ish code is not the J that I am familiar with. eg, the flip. flip =: (~: 3 : 'if. ((< & 2) @: #) y do. ({ & id) y else. (+./ @: ({ & id)) y end. ') since +. is idempotent so there is no

Re: [Jprogramming] Writing dyadic function with left/right parameters swapped

2017-06-04 Thread Raul Miller
What is the difference between 2 (a list of moves for the current board) and 3 (a path list for the solution, initially empty) in this description? Thanks, -- Raul On Mon, Jun 5, 2017 at 12:39 AM, Michael Rice wrote: > The gap between J and most computer languages is pretty wide. > > Maybe t

Re: [Jprogramming] Writing dyadic function with left/right parameters swapped

2017-06-04 Thread Michael Rice
@Raul Miller Sorry about the typo. It's pretty late now. Will revisit your message in the morning. On Sun, Jun 4, 2017 at 12:19 PM, Raul Miller wrote: > > For example, what's the difference between > > > > 2 3 <@, 3 4 and 1 2 <@:, 3 4 > > > > when the result is the same? > > Well... the result

Re: [Jprogramming] Writing dyadic function with left/right parameters swapped

2017-06-04 Thread Michael Rice
The gap between J and most computer languages is pretty wide. Maybe this will help. The board, a noun, is represented by a 15 element binary array with 1s for full positions and 0s for empty ones. It is initially all 1s. Id, a noun, is a 15x15 identity matrix. Function flip, given a board and po

Re: [Jprogramming] Writing dyadic function with left/right parameters swapped

2017-06-04 Thread Raul Miller
That's a nice idea. Leads also to this rephrasing of that part: |:((;|.)@(1++)+/)\i.5 Or, in context: move_table=: <:(,|."1)(#~0<*/"1)~.,/,/_3&{.\@/:~"1(,|:"2)>|:((;|.)@(1++)+/)\i.5 flip=: ~: (i.15)&e. legal_moves=: [ #~ 6 = 2 #. { Thanks, -- Raul On Sun, Jun 4, 2017 at 6:28 PM, Jose Mari

Re: [Jprogramming] Writing dyadic function with left/right parameters swapped

2017-06-04 Thread Jose Mario Quintana
"There ought to be a more elegant way of building move_table," I would replace the fragment (,:|.&.>)(;1{.&.>~1+i.5)<;.1>:i.15 by |:(>:@:(+/\)(;|.)@:+&><\)i.5 or, if you prefer, by |:(>:@(+/\)(;|.)@:+&><\)i.5 . On Sun, Jun 4, 2017 at 1:35 PM, Raul Miller wrote: > Actually, after furth

Re: [Jprogramming] Writing dyadic function with left/right parameters swapped

2017-06-04 Thread Raul Miller
Actually, after further thought, I think I'd define some of your words this way: move_table=: <:(,|."1)(#~0<*/"1)~.,/,/_3&{.@/:~\"1(,|:"2)>(,:|.&.>)(;1{.&.>~1+i.5)<;.1>:i.15 flip=: ~: (i.15)&e. legal_moves=: [ #~ 6 = 2 #. { There ought to be a more elegant way of building move_table, but I'm n

Re: [Jprogramming] Writing dyadic function with left/right parameters swapped

2017-06-04 Thread Raul Miller
Actually, after further thought, I think I'd define some of your words this way: move_table=: <:(,|."1)(#~0<*/"1)~.,/,/_3&{.@/:~\"1(,|:"2)>(,:|.&.>)(;1{.&.>~1+i.5)<;.1>:i.15 flip=: ~: (i.15)&e. legal_moves=: [ #~ 6 = 2 #. { It seems like there ought to be a more elegant way of building move_ta

Re: [Jprogramming] Writing dyadic function with left/right parameters swapped

2017-06-04 Thread Raul Miller
> For example, what's the difference between > > 2 3 <@, 3 4 and 1 2 <@:, 3 4 > > when the result is the same? Well... the result is not the same here, because 2 3 is different from 1 2. That said, <@, produces the same result as <@:, for the same arguments. The difference between @ and @: would

Re: [Jprogramming] Writing dyadic function with left/right parameters swapped

2017-06-04 Thread bill lam
I have difficulty in reading your code, perhaps you want to make everything looks functional. To that end, you may replace the if/then with @. (agenda) (+./ @: ({ & id))`({ & id)@.((< & 2) @: #) (untested and not sure if this is a simplication) Вс, 04 июн 2017, Michael Rice написал(а): > Two thi

Re: [Jprogramming] Writing dyadic function with left/right parameters swapped

2017-06-04 Thread Michael Rice
Two things come to mind: 1) *reductio ad absurdum* and 2) a Dustin Hoffman film, wherein he says to a man, "I going to explain something so you'll understand it!" and then shoots him. I already had a function that does what I needed (see below) but was musing about left/right parameter style, when

Re: [Jprogramming] Writing dyadic function with left/right parameters swapped

2017-06-04 Thread Raul Miller
Like this? (#~ 5=2#.@:|])z 3 4 5 -- Raul On Sun, Jun 4, 2017 at 9:43 AM, Michael Rice wrote: > How about >1 0 1 0 1 0 (#~ ((-: & 0 1 0)"1 @: ({~ & z)))~ z > ? > > Odd, that's the KISS way, the way that always works, and the one way I > hadn't considered. > > On to your "simplifications

Re: [Jprogramming] Writing dyadic function with left/right parameters swapped

2017-06-04 Thread Michael Rice
How about 1 0 1 0 1 0 (#~ ((-: & 0 1 0)"1 @: ({~ & z)))~ z ? Odd, that's the KISS way, the way that always works, and the one way I hadn't considered. On to your "simplifications." On Sat, Jun 3, 2017 at 10:16 PM, Louis de Forcrand wrote: > How about >1 0 1 0 1 0 (#~ ((-: & 0 1 0)"1 @:

Re: [Jprogramming] Writing dyadic function with left/right parameters swapped

2017-06-03 Thread Louis de Forcrand
How about 1 0 1 0 1 0 (#~ ((-: & 0 1 0)"1 @: ({~ & z)))~ z ? You can then "simplify": First the hook (and {~&z) ([ #~ -:&0 1 0"1@:(z&{)@])~ ([ #~ -:&0 1 0"1@:(z&{)@])~ Then ~ can be "distributed" over the resulting fork: [~ #~ -:&0 1 0"1@:(z&{)@(]~) ] #~ -:&0 1 0"1@:(z&{)@[ You can keep going

Re: [Jprogramming] Writing dyadic function with left/right parameters swapped

2017-06-03 Thread Ric Sherlock
I would write the original as: z ([ #~ 0 1 0 -:"1 {) 1 0 1 0 1 0 3 4 5 ​Then to reverse the arguments you could do one of the following: 1 0 1 0 1 0 ([ #~ 0 1 0 -:"1 {)~ z 3 4 5 1 0 1 0 1 0 (] #~ 0 1 0 -:"1 {~) z 3 4 5 On Sun, Jun 4, 2017 at 1:45 PM, Michael Rice wrote: >z

[Jprogramming] Writing dyadic function with left/right parameters swapped

2017-06-03 Thread Michael Rice
z =: 2 3 $ i.6 z 0 1 2 3 4 5 z { 1 0 1 0 1 0 1 0 1 0 1 0 (-: & 0 1 0) z { 1 0 1 0 1 0 0 (-: & 0 1 0)"1 z { 1 0 1 0 1 0 0 1 ((-: & 0 1 0)"1 z { 1 0 1 0 1 0) # z 3 4 5 z #~ ((-: & 0 1 0)"1 z { 1 0 1 0 1 0) 3 4 5 z #~ ((-: & 0 1 0)"1 (1 0 1 0 1 0 {~ z)) 3 4 5 z #~ ((-: & 0 1