diff --git a/2022/03.q b/2022/03.q index d4ff4e3..487b479 100644 --- a/2022/03.q +++ b/2022/03.q @@ -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 diff --git a/2022/04.q b/2022/04.q index d363239..79b9849 100644 --- a/2022/04.q +++ b/2022/04.q @@ -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 diff --git a/2022/05.q b/2022/05.q index afd37e7..20e9e6d 100644 --- a/2022/05.q +++ b/2022/05.q @@ -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 diff --git a/2022/06.q b/2022/06.q index 1f9de99..3203bf7 100644 --- a/2022/06.q +++ b/2022/06.q @@ -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 diff --git a/2022/07.q b/2022/07.q index d54e727..1706240 100644 --- a/2022/07.q +++ b/2022/07.q @@ -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~`$"..";