list - J: How to efficiently apply a verb to prefixes of suffixes? -


i have list

   n =: i.3 

and want have adverb a such u n applies u prefixes of suffixes of n:

   <a n ┌─────────────┬───────┬───┐ │┌─┬───┬─────┐│┌─┬───┐│┌─┐│ ││0│0 1│0 1 2│││1│1 2│││2││ │└─┴───┴─────┘│└─┴───┘│└─┘│ └─────────────┴───────┴───┘ 

i've written sentence produces desirable result verb <:

   ([: <@]\&.> <@]\.) n ┌─────────────┬───────┬───┐ │┌─┬───┬─────┐│┌─┬───┐│┌─┐│ ││0│0 1│0 1 2│││1│1 2│││2││ │└─┴───┴─────┘│└─┴───┘│└─┘│ └─────────────┴───────┴───┘ 

but cannot how make adverb use verb.

i see approach problem:

   =: \\.    <a n ┌─┬───┬─────┐ │0│0 1│0 1 2│ ├─┼───┼─────┤ │1│1 2│     │ ├─┼───┼─────┤ │2│   │     │ └─┴───┴─────┘    ([: < (a: ~: ]) # ])"1(<a n) ┌─────────────┬───────┬───┐ │┌─┬───┬─────┐│┌─┬───┐│┌─┐│ ││0│0 1│0 1 2│││1│1 2│││2││ │└─┴───┴─────┘│└─┴───┘│└─┘│ └─────────────┴───────┴───┘ 

but written <, , maybe not efficient. , still cannot how make adverb.

it better if can following result:

   <a n ┌─┬───┬─────┬─┬───┬─┐ │0│0 1│0 1 2│1│1 2│2│ └─┴───┴─────┴─┴───┴─┘ 

for example:

   (10&#.)a n 0 1 12 1 12 2 

help me please. in advance.

there (almost) adverb this. it's spread (s:) want apply level 0.

e.g.

<\ each <\. n ┌─────────────┬───────┬───┐ │┌─┬───┬─────┐│┌─┬───┐│┌─┐│ ││0│0 1│0 1 2│││1│1 2│││2││ │└─┴───┴─────┘│└─┴───┘│└─┘│ └─────────────┴───────┴───┘ < s:0 <\ each <\. n ┌─┬───┬─────┬─┬───┬─┐ │0│0 1│0 1 2│1│1 2│2│ └─┴───┴─────┴─┴───┴─┘  +/ s:0 <\ each <\. n 0 1 3 1 3 2  (10&#.)  s:0 <\ each <\. n 0 1 12 1 12 2 

in other words, a this:

a =: 1 :'u s: 0 ([: <\&.><\.) y' 

(edit) or, @tikkanz says in comments below, can avoid s: , use more efficient:

a=: 1 : ';@([: u\&.> <@]\.)' 

or

a=: 1 : ';@(<@(u\)\.)' 

Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -

php - $params->set Array between square bracket -