Skip to content

Commit

Permalink
2022 tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
mkst committed Dec 8, 2022
1 parent 9292845 commit 1d458f9
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 21 deletions.
5 changes: 2 additions & 3 deletions 2022/03.q
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// --- Day 3: Rucksack Reorganization ---

lut:" ",.Q.a,.Q.A
sum lut?raze (distinct@(inter/)2 0N#) each r:read0 `:input/03.txt
sum 1+.Q.an?raze (distinct@(inter/)2 0N#) each r:read0 `:input/03.txt
/7990
sum lut?raze (distinct@inter/) each 3 cut r
sum 1+.Q.an?raze (distinct@inter/) each 3 cut r
/2602
2 changes: 1 addition & 1 deletion 2022/04.q
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// --- Day 4: Camp Cleanup ---

range:{x + til 1 + y - x};
sum {$[all x in y;1b;all y in x;1b;0b]}.'p:{range .'"J"$"-"vs'","vs x} each read0`:input/04.txt
sum {$[all x in y;1b;all y in x]}.'p:{range .'"J"$"-"vs'","vs x} each read0`:input/04.txt
/567
sum {any x in y}.'p
/907
23 changes: 11 additions & 12 deletions 2022/05.q
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,22 @@ crates:(w-1)#r
steps:(w+1)_r

steps:"J"$(" "vs'steps)[;1 3 5]
steps:{(x;y-1;z-1)}.'steps
steps:0 -1 -1+/:steps

crates:crates[;(1 + 4 * til ceiling (max count each crates) % 4)]
crates:{ x except " " } each flip crates
crates:{x except " "} each flip crates

f:{[x;y]
cnt: $[3=count y;y[0];1];
frm: y $[3=count y;1;0];
to: y $[3=count y;2;1];
tmp: cnt#x[frm];
x: @[x;frm;{y _ x};cnt];
x: @[x;to;{y,x};tmp];
f:{[f;x;y]
cnt: y 0;
frm: y 1;
to: y 2;
x: @[x;to;{y,x};f cnt#x[frm]];
x: @[x;frm;{y _ x};cnt];
:x;
}

-1@raze first each f/[crates;] raze {[x;y;z] x#enlist (y;z) }.' steps;
-1@raze first each f[reverse]/[crates;steps];
/ JRVNHHCSJ

-1@raze first each f/[crates;steps];
/GNFBSBJLH
-1@raze first each f[(::)]/[crates;steps];
/ GNFBSBJLH
7 changes: 3 additions & 4 deletions 2022/06.q
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
// --- Day 6: Tuning Trouble ---

sw:{neg[x-1]_flip next\[x-1;y]}
f:{x + first where {(count distinct x) = count x} each sw[x;y]};
f:{y + count[x] - count (1_)/[{not y = count distinct y#x}[;y];x]}

f[4;] i:first read0 `:input/06.txt
f[;4] i:first read0 `:input/06.txt
/ 1238
f[14;] i
f[i;14]
/ 3037
2 changes: 1 addition & 1 deletion 2022/07.q
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ cwd:`
isls:0b

while[count line:first lines;
if[line like "$ cd *";
if[line like "$ cd*";
isls:0b;
dir:`$last " " vs line;
cwd:$[dir~`$"..";
Expand Down

0 comments on commit 1d458f9

Please sign in to comment.