Re: [Jprogramming] String replacement question

2023-12-02 Thread Raul Miller
That approach has a dependence on the user's input text. For example, consider nineightwo That said, another approach I have been told of was putting the digit name before and after the digit in the replacement text. -- Raul On Sat, Dec 2, 2023 at 12:28 PM LdBeth wrote: > > A very clever gimm

Re: [Jprogramming] String replacement question

2023-12-02 Thread LdBeth
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 > David Pinchbeck wrote: > I'm trying to improve

Re: [Jprogramming] String replacement question

2023-12-02 Thread Jan-Pieter Jacobs
The replace trick of Raul is nice. After my initially failed (like Aaron's) attempt to use replace, I solved the problem in a more array oriented way: p1 =: [: +/ ".@({.,{:)@:(#~e.&Num_j_);._2 num =: ;:'zero one two three four five six seven eight nine' fix =: [: ([: i:&1"1@|: 1,num

Re: [Jprogramming] String replacement question

2023-12-01 Thread Aaron Ash
I initially hit the same issue and then changed my approach to avoid using stringreplace. The logic I ended up with was: find the first and last match of any of the digits or number words, combine those two into a single string and now replace words with digits on those knowing that there's no chan

Re: [Jprogramming] String replacement question

2023-12-01 Thread Raul Miller
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 wrote: > > I'm trying to improve my J using Advent of Code, but am already a bit > stuck on th

[Jprogramming] String replacement question

2023-12-01 Thread David Pinchbeck
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 fai