Re: [Jprogramming] A practical problem: minimum distance with penalties

2016-03-04 Thread Henry Rich
I have put my solution to this problem in http://code.jsoftware.com/wiki/Essays/PropagatingMinimum The details are a little different, but the basic idea is the same. Henry Rich On 3/2/2016 3:15 PM, Brian Schott wrote: Oops, I forgot to enter "the following sentence": expand;<./@lineup each

Re: [Jprogramming] J Challenge

2016-03-04 Thread Pascal Jasmin
sorry if this has been answered already, >@(~.@[ ; each To: programm...@jsoftware.com Sent: Friday, March 4, 2016 4:34 AM Subject: Re: [Jprogramming] J Challenge I don't think for a minute that this will be the most terse or most elegant but this is what I got: animals =: 'bird';'cow';'cow';'

Re: [Jprogramming] J Challenge

2016-03-04 Thread Joe Bogner
not as concise, but an alternative: makeTable =: ( ((<0;0)&{:: ; ( wrote: > I'd have used ;:inv instead of ;:^:_1 like EelVex used (same > operation, but slightly shorter and I think slightly easier to read). > > Generally, ;:inv is perfect for taking a boxed list of strings and > getting a space

Re: [Jprogramming] J Challenge

2016-03-04 Thread Raul Miller
I'd have used ;:inv instead of ;:^:_1 like EelVex used (same operation, but slightly shorter and I think slightly easier to read). Generally, ;:inv is perfect for taking a boxed list of strings and getting a space separated string. Commas are a bit more work (and if you want the last comma to be

Re: [Jprogramming] J Challenge

2016-03-04 Thread EelVex
(~.@{.,.<@(;:^:_1)/./)list2 ┌┬─┐ │bird│one eight fourteen │ ├┼─┤ │cow │two three five six seven │ ├┼─┤ │dog │four nine eleven thirteen│ ├┼─┤ │cat │ten │ ├───

Re: [Jprogramming] J Challenge

2016-03-04 Thread Skip Cave
Both Henry & ​ ​ Raul came up with ​what is ​ likely the shortest solution: (~.@[ ,. [/.)/ list ​I like ​Henry's second approach, even though it is a bit longer: (~.@[ ,. <@;/.)/ list ┌┬─┐ │bird│1 8 14 │ ├┼─┤ │cow │2 3 5 6 7│ ├┼─┤ │dog │4 9 11 1

Re: [Jprogramming] Reading text .csv files into a J array

2016-03-04 Thread John Baker
I use a verb called (readtd2) for this: The tacit defn is (all that follows is one line which email typically mangles): NB. read TAB delimited table files - faster than (readtd) - see long document readtd2=:[: <;._2&> (9{a.) ,&.>~ [: <;._2 [: (] , ((10{a.)"_ = {:) }. (10{a.)"_) (13{a.) -.~ 1!:1&(

Re: [Jprogramming] J Challenge

2016-03-04 Thread Raul Miller
I came up with basically the same thing Henry came up with: list=: (,: <@#\) ;:0 :0 -.LF bird cow cow dog cow cow cow bird dog cat dog pig dog bird pig ) (~.@[ ,. [/.)/list ┌┬──┬──┬──┬──┬─┐ │bird│1 │8 │14│ │ │ ├┼──┼──┼──┼──┼─┤ │cow │2 │3 │5 │6 │7│ ├┼──┼──┼──┼──┼─┤ │dog │4 │9 │11

Re: [Jprogramming] J Challenge

2016-03-04 Thread Henry Rich
animals =: 'bird';'cow';'cow';'dog';'cow';'cow';'cow';'bird';'dog';'cat';'dog';'pig';'dog';'bird';'pig' ids =: 1;2;3;4;5;6;7;8;9;10;11;12;13;14;15 t =. animals,:ids (~.@[ ,. ]/.)/ t ++--+--+--+--+-+ |bird|1 |8 |14| | | ++--+--+--+--+-+ |cow |2 |3 |5 |6 |7| ++--+--+--+--+-+ |

Re: [Jprogramming] J Challenge

2016-03-04 Thread 'Jon Hough' via Programming
I guess the input needs to be animals ,: ids so... ai =: animals ,: ids f2 =: (1&{) f (0&{) NB. f same as previous answer. f2 ai I guess that's not really "one expression" now, so f2 =: 1&{ (((1 ,~ #) $ ])@:~.@:] ,. ]/.~) 0&{ On Fri, 3/4/16, 'J

Re: [Jprogramming] J Challenge

2016-03-04 Thread 'Jon Hough' via Programming
I don't think for a minute that this will be the most terse or most elegant but this is what I got: animals =: 'bird';'cow';'cow';'dog';'cow';'cow';'cow';'bird';'dog';'cat';'dog';'pig';'dog';'bird';'pig' ids =: 1;2;3;4;5;6;7;8;9;10;11;12;13;14;15 f =: (((1,~ #) $])@:~.@:]) ,. (]/.)~ ids f ani

[Jprogramming] J Challenge

2016-03-04 Thread Skip Cave
​Well, the format of that last post was a bit messy. Here's a second try:​ ​ The animal control officer wants to keep track of the animals in a city. The officer tags all the animals with a serial number. He keeps a list of all the animals he has tagged, along with each serial number. list​

[Jprogramming] J Challenge

2016-03-04 Thread Skip Cave
​The animal control officer wants to keep track of the animals in a city. The officer tags all the animals with a serial number. He keeps a list of all the animals he has tagged, along with each serial number. list ┌┬───┬───┬───┬───┬───┬───┬┬───┬───┬───┬───┬───┬┬───┐ │ ​ ​ bird ​ ​