Here's a cleaned up version of how I approached that (here 'input'
held the raw text of input.txt provided by the aoc website).

parsed=: ('ABC',:'XYZ') i."1 |:-.&' ';._2 input
part1=: {{ +/1+y+3*3|(1+y)-x }}/
part2=: {{ +/(3*y)+4|&.<:x+y }}/

Note that my original implementations were a bit different. For
example, for part 1, I had

scor=: {{
  'op me'=. y
  (1+me)+ 3*op {{ (x |. 2 0 1)i.y}}"0 me
}}

and used
   +/scor parsed

I hope this makes sense,

-- 
Raul

On Fri, Dec 2, 2022 at 12:40 PM Jaume <greenni...@gmail.com> wrote:
>
> Hello again
> I managed to solve it, but I don't like it much, so feel free to educate me.
>
> Reading the file, and evaluating the result is something that looked nice:
>
> p =. 1!:1<'day02.input'
>
> +/>ev each cutopen p
>
> xxxx
>
> +/>ev2 each cutopen p
>
> xxxx
>
> Now are the evaluating functions. I really don't like how they are done.
> I'd even prefer to create a table and search in it, but I don't know how.
> So a select. is used.
>
>
> ev=: 3 : 0
>
> select. y
>
> case. 'A X' do.
>
> 4
>
> case. 'A Y' do.
>
> 8
>
> case. 'A Z' do.
>
> 3
>
> case. 'B X' do.
>
> 1
>
> case. 'B Y' do.
>
> 5
>
> case. 'B Z' do.
>
> 9
>
> case. 'C X' do.
>
> 7
>
> case. 'C Y' do.
>
> 2
>
> case. 'C Z' do.
>
> 6
>
> end.
>
> )
>
>
> And the same with different numbers for ev2.
>
> Would this be an appropriate way to approach the problem? Is there a
> "better" way?
>
>
> 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

Reply via email to