Brings this to mind: http://amoffat.github.io/sh/
Yep and I think that explicitly partially applying using their bake
is a nice API. The blog post’s API supports pipes (and redirections!) which in my opinion is nicer than what the sh library offers.
I am going to write up my Haskell solution at some point, but I liked this:
CREATE TABLE day_01 (v INT NOT NULL UNIQUE);
COPY day_01 FROM 'Projects/AOC/2020/data/Day01.txt';
SELECT 1 AS part, a.v * b.v AS answer
FROM day_01 a CROSS JOIN day_01 b
WHERE a.v <> b.v AND a.v + b.v = 2020
UNION
SELECT 2 AS part, a.v * b.v * (2020 - a.v - b.v) AS answer
FROM day_01 a CROSS JOIN day_01 b
WHERE a.v <> b.v
AND 2020 - a.v - b.v > 0
AND EXISTS (SELECT 1 FROM day_01 WHERE v = 2020 - a.v - b.v);
And it’s crazy fast:
part | answer
-------+----------
1 | 800139
2 | 59885340
(2 rows)
Time: 6.732 ms
I love the SQL solution. If you want to use it with a version of sqlite that shipped post-2004, change COPY...
to .import day01.txt day_01
Looks neat, and it’s also all one line of code! Woot!
Would love to see that done for the triples in the next section.
If everything keeps building on everything, that’s going to be a fun hunk of code to watch evolve. :)
If DDL does not count as code, would it be zero lines of code if I could make a macro that reports the solution in an error? Or maybe if one used dependently typed programming where the compiler can infer the solution? If I used Datalog, would the queries count as code, but that statements not? ;)
Since the numbers are unique, they’re using that to make sure they’re not checking the number added with itself since that wouldn’t be a valid solution even if it added up to 2020.
Plus I assume you would’ve found out pretty quickly if they weren’t all unique when you tried to import them into a column with a unique constraint.
My first solution was in Haskell, so I had already determined that particular bit of data modelling.
Is there just one column? I was wondering how you’d handle duplicates where the answer is a perfect square.
The Haskell version I ported from:
solve01 :: [Int] -> Int
solve01 xs = head [a * b | a <- xs, let b = 2020 - a, b `elem` xs]
solve02 :: [Int] -> Int
solve02 xs =
head [a * b * c | a <- xs, b <- xs, a /= b, let c = 2020 - a - b, c `elem` xs]
Tedious IO is left to the reader.
Dvorak user here. I remap htns
, qwerty’s jkl;
, to hjkl
in all applications to get spatial navigation. This also frees up d
, qwerty’s h
, to be used for delete in vim/kakoune/qutebrowser. However new locations for tns
are needed and I’ve been using kgl
for that. This leaves j
free and I use that as a leader (as well as ,
and z
).
Finally finishing up my font! I’ve just finished the glyphs for this version yesterday, so all that’s left is adding a nice landing page, and (maybe?) showing it here.
Hm, I think I’m done!
Congrats on getting it finished! I’m curious why you chose to not have dots on top of lowercase i and j. The i makes me think of Turkish dotless i or Greek iota.
Will that font be distributed in a format that could be installed on Windows?
I honestly don’t know what bitmapped-font formats could be installed on Windows. Would
bdf
,pcf
, orotb
work?