A very clever gimmick I saw from https://xpqz.github.io/AoC-day1/
is replace the following composite words:

'oneight' 'eightwo' 'nineight' 'twone' 'sevenine' 'eighthree'

by

'18' '82' '98' '21' '79' '83'

And it totally works XD

>>>>> In <camw+kcrhcen_ntks0h50qbulrt-2ctxzapjr-uxqjafref0...@mail.gmail.com> 
>>>>>   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