> (p#n)&> applies (p#n) to each atom of t.
Yeah, and even if some results are empty, it's obliged to return the same
number of elements that were on the input, so the result was filled with
zeros.
Another approach could be to left-pad all the items to the same length, so
that 'open' would give a good char matrix.
m=.>_63&{.@((63$'-')&,)&.> t NB. max len of items is 63 in my case
echo (p"1 # n"1) m
That looks more like what I wanted. But again, "1 doesn't look pretty. So,
ok, the issue is closed :)
(p&> # n&>) t will do.
On Sun, Dec 4, 2016 at 9:26 PM, Henry Rich <[email protected]> wrote:
> (p#n)&> applies (p#n) to each atom of t.
>
> (p&> # n&>) applies # to the results of p&> and n&> on the entirety of t.
>
> Both forms are valid J, but they do different things.
>
> Henry Rich
>
>
>
>
> On 12/4/2016 2:10 PM, Moon S wrote:
>
>> (p&> # n&>) t NB. is ok too. So... why (p#n)&>t is not? And how to deal
>> with this kind of problems?
>>
>> On Sun, Dec 4, 2016 at 8:18 PM, Moon S <[email protected]> wrote:
>>
>> OK, simple case
>>>
>>> t NB. three boxed strings
>>>
>>> ┌──┬──┬──┐
>>>
>>> │22│33│44│
>>>
>>> └──┴──┴──┘
>>>
>>> p NB. test for all two's
>>>
>>> *./@('2' = ])
>>>
>>> n NB. append zero and cvt to number
>>>
>>> ".@('0' ,~ ])
>>>
>>> (p&>t)#(n&>t) NB. ok
>>>
>>> 220
>>>
>>> (p # n)&>t NB. zero-padded
>>>
>>> 220
>>>
>>> 0
>>>
>>> 0
>>>
>>> dissect doesn't show anything for p and n in the second case; and what's
>>> "3 1(1)" for '#'?
>>>
>>> http://mas.orgfree.com/adventofcode2016/diss1.png
>>>
>>>
>>>
>>> On Sun, Dec 4, 2016 at 6:14 PM, Henry Rich <[email protected]> wrote:
>>>
>>> I have no time to help, other than to suggest you use dissect to see
>>>> what's happening.
>>>>
>>>> Henry Rich
>>>>
>>>>
>>>> On 12/4/2016 11:02 AM, Moon S wrote:
>>>>
>>>> I have this code:
>>>>>
>>>>> t =: cutLF CR-.~fread '04.dat'
>>>>> a =: a.{~97+i.26 NB. 'abc...z'
>>>>> c =: 5{.a\:[:+/"1 a=/[:/:~_10}.'-'-.~] NB. calculate checksum string
>>>>> v =: c -: _1}._6&{. NB. checksums match = good
>>>>> string
>>>>> n =: [:".3{._10{.] NB. extract number (id)
>>>>> s =: 4 :'((26|x+])&.(_97+a.i.]))"0 y' NB. shift cypher, n s 'str'
>>>>> p =. +./@('north' E. n s ]) NB. if decrypted string
>>>>> contains
>>>>> 'north'
>>>>> echo +/(n*v)&> t NB. sum of ids of good strings
>>>>> echo +/(n*p)&> t NB. sum of ids of strings with
>>>>> 'north'
>>>>> exit 0 NB. ^^^ we assume such
>>>>> string
>>>>> is only one
>>>>>
>>>>> It works, but I planned to use '#' instead of +/...*... for the second
>>>>> task.
>>>>>
>>>>> Verb n takes a number from a string.
>>>>> Verb p decrypts a string using the number and tells if it contains
>>>>> 'north'.
>>>>> So far so good.
>>>>> Noun t is the input data as boxed strings.
>>>>> n&> t gives numbers (like 111 222 333 444)
>>>>> p&> t gives a boolean vector (like 0 0 1 0)
>>>>> The idea was to have something like "(p # n)&> t" but that didn't work.
>>>>> (p&> t)#(n&> t) is ok
>>>>> (p # n)&> t is not
>>>>> Something wrong with ranks, I guess. Any idea how to use (p # n)?
>>>>>
>>>>> Thank you.
>>>>> Georgiy Pruss
>>>>> ----------------------------------------------------------------------
>>>>> For information about J forums see http://www.jsoftware.com/forums.htm
>>>>>
>>>>> ----------------------------------------------------------------------
>>>> For information about J forums see http://www.jsoftware.com/forums.htm
>>>>
>>>
>>>
>>> ----------------------------------------------------------------------
>> For information about J forums see http://www.jsoftware.com/forums.htm
>>
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm