aboutsummaryrefslogtreecommitdiff
path: root/day13.k
blob: fc3cde03c97925750778d25343ef86c0d1c99b38 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
d:0:"day13";

d:-1 _' d;

ss:{1 _' (&y=y,x) _ y,x}; / split x at y
l:ss[;" "]' d;

perm: {:[1<x;,/(>:'(x,x)#1,x#0)[;0,'1+_f x-1];,!x]};

happy:[];
{
 .[`happy;`$x[0 10];:; :["gain"~x[2];1;-1]*0$x[3]]
}'l;

ppl: !happy;
hs:{(+/happy':x,*x)+(+/happy':|x,*x)}'ppl@perm@#ppl;
|/hs / maximize happiness

{.[`happy;`Me,x;:; 0];
 .[`happy;x,`Me;:; 0]}'ppl

ppl: `Me,ppl;
hs:{(+/happy':x,*x)+(+/happy':|x,*x)}'ppl@perm@#ppl;
|/hs / maximize happiness