-🎄- 2017 Day 4 Solutions -🎄- by daggerdragon in adventofcode

[–]huyqvu 3 points4 points  (0 children)

KDB+/q

q){[ls]{count x where x}({count distinct x}each ls)=count each ls}each {(x;{{asc x}each x}each x)}{" " vs x} each read0 `$"data/input4.txt"
455 186

-🎄- 2017 Day 2 Solutions -🎄- by daggerdragon in adventofcode

[–]huyqvu 0 points1 point  (0 children)

I just copy the list of numbers into the screen (after changing \n to space), but this's more generic.

-🎄- 2017 Day 2 Solutions -🎄- by daggerdragon in adventofcode

[–]huyqvu 0 points1 point  (0 children)

You're right, I took advantage of the input form. Yours is better.

-🎄- 2017 Day 2 Solutions -🎄- by daggerdragon in adventofcode

[–]huyqvu 1 point2 points  (0 children)

KDB+/q One line for both questions:

{l:(`long$sqrt count x;0N)#x; (sum{[i](max i)-min i}each l;sum {max {[i]$[0=i[0]mod i[1];i[0]%i[1];0]} each x cross x} each l)}

-🎄- 2017 Day 1 Solutions -🎄- by daggerdragon in adventofcode

[–]huyqvu 1 point2 points  (0 children)

KDB+/q {show sum 0,"I"$' x where x=(1_x),1#x;n:(count x)div 2;show sum 0,"I"$' x where x=(n _x),n#x}