Actually, I originally had LF,LF until someone pointed out that LF2
was in stdlib.

That said, other parsing approaches for the day 1 data are perfectly viable.

For example:

   +/|:".@;S:1 cutLF each cutpara data

-- 
Raul

On Fri, Dec 2, 2022 at 7:25 PM 'Mike Day' via Programming
<programm...@jsoftware.com> wrote:
>
> LF2 ... new to me!  I was a bit thrown by the parsing of the trivial example 
> being different from that for the data file;  however that's likely a 
> by-product of copy&paste on the example versus downloading the file. Anyway,  
> I wasn't expecting LF,LF (or LF2);  the usual
>  LF cut ...
> missed the empty lines.
>
> The parsing method I eventually used was far from elegant, so I won't share 
> it!
>
> Mike
>
> Sent from my iPad
>
> > On 2 Dec 2022, at 19:42, Raul Miller <rauldmil...@gmail.com> wrote:
> >
> > Here's the parsing routine I used for day 1:
> >
> > parse=: {{ +/@(__&".;._2);._2 (y,LF) rplc LF2;LF,'/'}}
> >
> > Its y argument would be the raw text of the input.txt provided for day 1.
> >
> > I hope this makes sense,
> >
> >
> > --
> > Raul
> >
> >> On Fri, Dec 2, 2022 at 11:36 AM Jaume <greenni...@gmail.com> wrote:
> >>
> >> Hello all
> >>
> >> I've been trying to dabble in J for quite some time, but I still haven't
> >> got the hang of it, so I'm trying (not for the first time) to go in deep
> >> trying to solve each day.
> >>
> >> Alas sometimes it feels like hitting my head against the wall, and so I
> >> come to you with what I tried and what I lack to end the problem. Let's
> >> start.
> >>
> >> On day 1 we have an heterogeneous array, and we have to get the elf who
> >> carries the most calories.
> >>
> >> Using the example I can solve it for both parts of the day, using a boxed
> >> array.
> >>
> >> in=: 1000 2000 3000;4000;5000 6000;7000 8000 9000;10000
> >>
> >> {. \:~>+/ each in
> >>
> >> 24000
> >>
> >> +/ 3 {. \:~>+/ each in
> >>
> >> 45000
> >>
> >> I can read the data from a file and I can also format it like in the
> >> instruction above
> >>
> >> p =: 1!:1<'test.input'
> >>
> >> p rplc (LF,LF);';';LF;' '
> >>
> >> 1000 2000 3000;4000;5000 6000;7000 8000 9000;10000
> >>
> >> But how do I go from one representation to the other? Or if there's another
> >> way to do this transformation I'm all eyes.
> >>
> >> I know that that is a string, and I know that numbers are different and I
> >> know of ". to transform to numbers. I don't know how to partition the input
> >> on something.
> >>
> >> Thanks.
> >> ----------------------------------------------------------------------
> >> For information about J forums see http://www.jsoftware.com/forums.htm
> > ----------------------------------------------------------------------
> > For information about J forums see http://www.jsoftware.com/forums.htm
> ----------------------------------------------------------------------
> 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