-
Notifications
You must be signed in to change notification settings - Fork 164
/
ad.k
147 lines (119 loc) · 3.61 KB
/
ad.k
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/ adventofcode.com nick, ryan, peter, walter, attila, christian, ..
/ simple solutions. not necessarily shortest or fastest.
rd:{0:0N!x};tok:{" "\:'rd x};lst:{{.*|x}'tok x};col:{(tok y)[;x]} / read tokens lastvals columns
vs:{(1_r)-x*-1_r:|(_%)\(,y),|x};odo:{vs[x;!*/x]};sets:{odo x#2} / decode odometer powerset
prm:{x{,/(>:'t=/:t:*x)@\:x:0,'1+x}/,!0} / permutations
cmb:{$[0>@y;,/(+,+,!y-:x){(x+z){,/x,''y}'x#\:y}[1+!y]/!x-:1;y cmb[x]@#y]} / combinations
x:1 -1"()"?*rd`p1
+/x
1+(+\x)?-1
x:.:''"x"\:'rd`p2
+/{+/7#x*1_x,*x}'x:{x@<x}'x
+/{(*/x)+2*+/2#x}'x
x:"^>v<"?*rd`p3
#?0,+\a:(x,-x:1,#x)x
#?0,/++\0N 2#a
x:*rd`p4
(15<16/:3#-15!x,$:)(1+)/1
(16/:3#-15!x,$:)(1+)/1
x:rd`p5
+/{(2<+/x in"aeiou")&(|/=':x)&~|/(p:,':x)in$`ba`dc`qp`yx}'x
+/{(|/(-2_p)in'(!#r)_\:r:2_p:,':x)&|/(-2_x)=2_x}'x
x:{.:'(|x)2 0}'tok`p6
f:"fn "?(0:`p6)@'6;x:{x+!:'1+y-x}/'x
+//./[1000 1000#0;x;(0&;1|;1-)f]
+//./[1000 1000#0;x;(0|-1+;1+;2+)f]
x:((*|:)'x)!x:tok`p7
A:&;O:|;L:{y_x,0>!y:0b/:y};R:{|L[|x;y]};e:{$["a">*x;0b\:. x;@a:d x;a;d[x]:$[3=#a;e@*a;4=#a;~e a 1;(.*a 1)/e'a 0 2]]}
d:x;0b/:r:e@,"a"
d:x;d[,"b"]:r;0b/:e@,"a"
x:rd`p8
+/{2+/(1+2*"x"=1_x)*<\"\\"=-1_x}'x
+/{2+/x in"\"\\"}'x
m|:+m:@[;!8]'(0,+\!7)_|lst`p9
&/x:(+/m':)'prm 8
|/x
x:*rd`p10
#40{,/{($#x),*x}'(&~=':x)_x}/x
#50{,/{($#x),*x}'(&~=':x)_x}/x
x:-97+"j"$*rd`p11 / (run of three;~any"oil"in;2 doubles)
f:&/(|/&':1=-':;~|/8 11 14 in;1<+/<\=':)@\:;n:vs[8#26]1+26/:
"c"$97+x:(~f@)n/x
"c"$97+(~f@)n/n x
x:*rd`p12
+/"I"$1_'(&x in",:[]}")_x
{$[0>t:@x;x;10=t;0;t&|/"red"~/:x;0;+/.z.s'x]}.j.k x
x:col[2 3]`p13
m:((!8)_/:!8)@[8#0;;:;]'8 7#{(-1 1"g"=*x)*. y}/'x
|/{+/m':x,|x,:*x}'prm 8
|/{+/m':x,|x}'prm 8
x:.:''col[3 6 13]`p14
|/+/x:+{2503#(*x)*~&1_x}'x
|/+/a=|/'a:+\x
x:{. x@&~","=x}''col[2+2*!5]`p15
d:{$[x=1;,,y;,/n,/:'(x-1)d'y-n:!1+y]} /distributions
|/*/-1_s:0|+d[4;100](+/*)\:x
|/*/-1_s@\:&500=s 4
x:{x@&~x in":,"}''col[2+!6]`p16
r:($`children`cats`samoyeds`pomeranians`akitas`vizslas`goldfish`trees`cars`perfumes)!3 7 2 3 0 0 5 3 2 1
1+&3=(+/r=)'x:(.:'!/+3 2#)'x
1+&3=(+/(=;<;=;{x>0W^y};=;=;{x>0W^y};<;=;=).'r,')'x
x:lst`p17
+/b:150=+/x*s:sets@#x
+/n=&/n:+/s[;&b]
x:"#"=rd`p18
f:{3=s-x&4=s:2{+(0+':x)+1_x,0}/x}
+//100 f/x
+//100(m|f@)/x|m:m*\:m,:|m:~!50
m:tok`p19
f:{(i#\:x),'z,/:((i:x ss y)+#y)_\:x}
#?,/(a:*a)f[m:**|m]'b:*|a:+-2_m
-1+#?(1<#:){$[#r:f[x;b i;a i:*1?#a];*r;x]}\m
N:.*rd`p20
d:{?f,_x%f@:&x=f*_x%f:1+!_sqrt x}
{N>+/10*d x}(M+)/M:420
{N>+/11*f@&x<51*f:d x}(M+)/M
B:lst`p21
b:{</-_-(100,*B)%1|(B 1;4+x+/1 2 3*3#S z)-(y+/1 2 3*3_S z;B 2)}.
g:+/(8 10 25 40 74;0 13 31 53 75 102;(+/25 50 100 20 40 80*)'S@:&3>+/'S:+sets 6)@'
&/g'x@&~b'x:+odo 5 6,#S
|/g'x@& b'x
B:lst`p22 / nick peter andrey ..
C:113 173 229 53 73;T:6 6 5 1 1;A:0 0 2 0,,0 1;W:0 3 -101 4,,2 -2
s:{x[A i]-:W i:&0<4_x;x[4+i]-:1;x};k:{x@&0<x@'1} / spell keep
n:{x{x[3 2,4+y]+:(-:\C y),T y;x[1]-:(0<*x)*B[1]-7*0<(x:s x)4;x}/:&~(C>x 2)|0<4_x:s x}
f:{$[#w:&1>*:'v:?x@&b:m<53+&/m:x@'3;&/v[w;3];f(x@&~b),/k'n'k H v]}
H:{x};f x:,(*B),50 500 0,(#C)#0
H:@[;1;-;1]';f x
a:0;b:1;I:{2_x@&~"+"=x}'rd`p23
p:{x};o:{$[1=*R;x 1;1]};e:{$[f=_f:.5**R;x 1;1]};c:{R[x]+:1;1};l:{R[x]*:3;1};f:{R[x]%:2;1}
R:0 0.;((#I)>){x+. I x}/0;R b
R:1 0.;((#I)>){x+. I x}/0;R b
s:+/a:lst`p24 /ryan
f:{$[#i:&x=+/'r:cmb[y]a;&/*/'r i;1+y]}
(9>)f[s%3]/1
(9>)f[s%4]/1
x@:&~^x:"I"$-1_'*tok`p25 /ryan
((+/!+/x)-*x){x-a*(x*:252533)div a:33554393}/20151125
\
25. 4/8/16
24. 5/13/60
23. 6/11/33(15)
22. 22/51/190 (long time)
21. 12/18/50 (6 on paper)
20. 6/12/68
19. 18/36/240
18. 6/12/30(3)
17. 2/5/18
16. 6/9/18
15. 7/13/35
14. 7/13/27(12)
13. 5/10/20(12)
12. 4/8/26
11. 5/10/25
10. 3/5/13(2)
09. 5/10/30(3)
08. 5/9/24(3)
07. 12/26/62(5)
05. 2/10/25(9)
..