https://code.jsoftware.com/wiki/ShareMyScreen/AdventOfCode/2023/01/Trebuchet/rdm
offers one approach.

But it could be golfed to be more concise.

-- 
Raul

On Fri, Dec 1, 2023 at 9:29 PM David Pinchbeck <dpinc...@gmail.com> wrote:
>
> I'm trying to improve my J using Advent of Code, but am already a bit
> stuck on the second part of day 1.  It seems late enough in the day now to
> ask this question without spoiling anything.
>
> On the example code one needs to turn the string 'eightwothree' into '8wo3'
> I tried the following, which fails because the priority of stringreplace
> comes from the left argument ordering:
>
> digs=:'0123456789'
>
> s=:'zero';'one';'two';'three';'four';'five';'six';'seven';'eight';'nine'
>
> substr=:(s,. <"0 digs)
>
> g=:{{ substr stringreplace y}}
>
> g 'eightwothree'
>
> eigh23
>
> How can I get the earliest appearance on the right side to be replaced
> first instead?
>
> Thanks,
> David
> --
> David Pinchbeck
> Associate Professor of Mathematics
> St. Joseph's College
> Standish, ME
> ----------------------------------------------------------------------
> 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