your select function ev can be replaced with
ev =: (9 3$'A XA YA ZB XB YB ZC XC YC Z')&(4 8 3 1 5 9 7 2 6 { ~ i.)
ev 'A X'
4
On Friday, December 2, 2022 at 12:40:53 p.m. EST, Jaume <[email protected]>
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