-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
144 additions
and
426 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,5 @@ | |
|
||
last s:sums -1 1"("=first read0 `:input/01.txt | ||
/232 | ||
1+first where -1=s | ||
/1783 | ||
1+s?-1 | ||
/1783 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
/--- Day 2: I Was Told There Would Be No Math --- | ||
|
||
d:asc each "J"$ "x" vs'read0 `:input/02.txt | ||
sum sum each (2*d[;2]*d[;0];3*d[;0]*d[;1];2*d[;1]*d[;2]) | ||
t:flip `w`h`l!flip asc each "J"$ "x" vs'read0 `:input/02.txt | ||
exec sum (2*w*l) + (3*w*h) + 2*h*l from t | ||
/1598415 | ||
sum sum each (d[;0]*d[;1]*d[;2];2*d[;0]+d[;1]) | ||
/3812909 | ||
exec sum (w*h*l) + (2*w+h) from t | ||
/3812909 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
/--- Day 3: Perfectly Spherical Houses in a Vacuum --- | ||
|
||
count distinct sums D:!["^v<>";(0 1;0 -1;-1 0;1 0)] first read0 `:input/03.txt | ||
count distinct sums d:(0 1;0 -1;-1 0;1 0)"^v<>"?first read0 `:input/03.txt | ||
/2572 | ||
count distinct (sums D where not o),sums D where o:count[D]#10b | ||
/2631 | ||
count distinct raze sums 0N 2#d | ||
/2631 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/--- Day 7: Some Assembly Required --- | ||
|
||
.a.wires:(`u#enlist `)!enlist 0N | ||
|
||
.a.get:{ $[all x in .Q.n;"J"$x;.a.wires `$x] } | ||
.a.not:{ $[null r:.a.get x;0N;0b sv (48#0b),not -16#0b vs r] } | ||
.a.and:{ $[any null r:.a.get each (x;y);0N;0b sv all 0b vs'r] } | ||
.a.or:{ $[any null r:.a.get each (x;y);0N;0b sv any 0b vs'r] } | ||
.a.ls:{ "j"$(2 xexp .a.get y) * .a.get x } | ||
.a.rs:{ .a.get[x] div (2 xexp .a.get y) } | ||
|
||
f:{ | ||
if[not null .a.wires y;:()]; | ||
.a.wires[y]:$[1=count x; | ||
.a.get x 0; | ||
"NOT"~x 0; | ||
.a.not x 1; | ||
"AND"~x 1; | ||
.a.and . x 0 2; | ||
"OR"~x 1; | ||
.a.or . x 0 2; | ||
"LSHIFT"~x 1; | ||
.a.ls . x 0 2; | ||
.a.rs . x 0 2 | ||
] | ||
}; | ||
|
||
i:{(" "vs x;`$y)}.'" -> "vs/:read0 `:input/07.txt | ||
|
||
while[null .a.wires`a;f .'i];a:.a.wires`a;a | ||
/16076 | ||
|
||
delete from `.a.wires; | ||
i[where i[;1]=`b;0]:enlist enlist string a | ||
while[null .a.wires`a;f .'i];a:.a.wires`a;a | ||
/2797 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
/--- Day 8: Matchsticks --- | ||
|
||
sum { count[x]-count 2_ssr[ssr[ssr[x;"\\x[0-9a-f][0-9a-f]";"_"];"\\\\";"_"];"\\\"";"_"] } each r:read0 `:input/08.txt | ||
sum { count[x]-count 2_ ssr[ssr[x;"\\x[0-9a-f][0-9a-f]";"_"];"\\?";"_"] } each r:read0 `:input/08.txt | ||
/1350 | ||
sum { count[except[.Q.s x;"\r\n"]]-count x} each r | ||
/2085 | ||
sum { count[.Q.s1 x]-count x} each r | ||
/2085 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,8 @@ | ||
/--- Day 14: Reindeer Olympics --- | ||
|
||
f:flip `n`s`t`r!("s i i i";" ")0: `:input/14.txt | ||
update p:0 from `f; | ||
t:flip `n`s`t`r!("s j j j";" ")0: `:input/14.txt | ||
max sum r:flip 2503#'{(x[`t]#x`s),x[`r]#0i } each f | ||
max last f:flip value exec sums 2503#((t#s),r#0) by n from t | ||
/2696 | ||
{ update p+1 from `f where x = max x } each sums r; | ||
exec max p from f | ||
max sum each flip f=max flip f | ||
/1084 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,17 @@ | ||
/--- Day 17: No Such Thing as Too Much --- | ||
|
||
TARGET:150 | ||
B:(count[i]#.Q.a)!i:desc "J"$ read0 `:input/17.txt | ||
|
||
buckets:(count[i]#.Q.a)!i:desc "J"$ read0 `:input/17.txt | ||
|
||
f:{[current;available;indexes] | ||
// target reached, return | ||
if[TARGET=sum buckets indexes;:enlist indexes]; | ||
// filter available | ||
available:available where buckets[available] <= min buckets[indexes]; | ||
f:{ | ||
// success | ||
if[x=s:sum B y;:enlist y]; | ||
// discover possibilities | ||
w:where (z > last y) and x >= B[z] + s; | ||
// recurse | ||
raze .z.s'[c w;available _/:w;indexes,/:available w:where 0<=c:current-/:buckets[available]] | ||
raze .z.s'[x;y,/:z w;z _/:w] | ||
} | ||
|
||
count c:distinct asc each f[TARGET;key buckets;()] | ||
count r:f[150;"";key B] | ||
/4372 | ||
min count each c | ||
min count each r | ||
/4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,20 @@ | ||
/ --- Day 24: It Hangs in the Balance --- | ||
/--- Day 24: It Hangs in the Balance --- | ||
|
||
f:{ | ||
// success | ||
if[x=s:sum y;:enlist y]; | ||
// discover possibilities | ||
p:z where z <= x - s; | ||
// optimisation to avoid recalculations | ||
p:p where all p</:y; | ||
w:where (z<last y) and x >= z + s; | ||
// recurse | ||
raze .z.s'[x;y,/:p;z except/:p] | ||
raze .z.s'[x;y,/:z w;z _/:w] | ||
}; | ||
|
||
f2:{ f[x;1#y;y except first y] }; | ||
f2:{ f[x;1#y;1_ y] }; | ||
|
||
r:f2[sum[i]%3;] i:desc "J"$read0 `:input/24.txt; | ||
prd r first iasc prd each r:r where c=min c:count each r | ||
r:f2[sum[i] div 3;] i:desc "J"$read0 `:input/24.txt; | ||
min prd each r:r where c=min c:count each r | ||
/10439961859 | ||
|
||
r:f2[sum[i]%4;i]; | ||
prd r first iasc prd each r:r where c=min c:count each r | ||
r:f2[sum[i] div 4;i]; | ||
min prd each r:r where c=min c:count each r | ||
/72050269 |
Oops, something went wrong.