Huh.. somehow google did not show me Loius de Forcrand's reply to your
other message until *after* i came back to check that thread, after
replying to it. And yet it tells me he sent it three hours ago.

So, thinking about this, you've probably already figured this out.
Still, you did ask... Anyways, here's how I'd approach this:

boxer=:(0;(S=:]\~&_2@".;._2]0 :0);<<"0'abc')&;:
  1 1   2 1   3 1   0 0
  1 0   2 2   3 2
  1 2   2 0   3 2
  1 2   2 2   3 0
)

replacer=:3 :0
  X=. boxer y
  ref=. {.@> X
  a=. I.'a'=ref
  b=. I.'b'=ref
  ;(<'alpha')a} (<'beta')b} X
)

   replacer 'abbbbaaacccaaaaabbbb'
alphabetaalphacccalphabeta

Thanks,

-- 
Raul


On Sun, Feb 18, 2018 at 3:38 AM, Arnab Chakraborty <arnab...@gmail.com> wrote:
> Hello,
>
>    I use state machines a lot in my programs (in other
>    languages). I am trying to understand how I can use J for
>    those purposes. I have read the Sequential Machines and
>    Huffman Coding labs. But I am unable to see how to solve this
>    toy problem (without using regexp):
>
>    Input alphabet {a,b,c}
>    I want to replace runs of 'a' with the word 'alpha', runs of 'b'
>    with the word 'beta', and leave the 'c's unchanged.
>
>    For example, abbbbaaacccaaaaabbbb becomes alphabetaalphacccalphabeta.
>
>    The state diagram is like this, where the arcs are labelled as
>    inp/out.
>
>
> [Cannot inline image]
>
>    I have created the input map successfully (not sure if it is a
>    good way, though):
>
>    makemap =. 3 : '+/ (>:i.#y) *"0 1 a.="1 0 y'
>    m=.makemap 'abc'
>
>    I guess that this can be achieved using only outputs 0 and
>    2, since I am just interested in the runs.
>
>
>    Also, since the output is not just a part of the input, f
>    must be 2 or 3 or 4.
>
>    But I am stuck at this point. If I use f=.2, then I can get
>    a list of boundaries of all the runs. If I have to write another
>    verb that will convert this list to the desired output, then
>    basically I have to implement a simplified version of the same
>    state machine inside that verb, which does not look good.
>
>    f=.3 does not look promising either, since for 'c' I need to
>    know the length of the run.
>
>    How should I proceed?
>
>
> Thanks and regards,
>
> Arnab
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to