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
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
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
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
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
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