Skip to content

Instantly share code, notes, and snippets.

@msullivan
Last active December 1, 2022 20:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save msullivan/bda7c6050940c28ae481078c6022b305 to your computer and use it in GitHub Desktop.
Save msullivan/bda7c6050940c28ae481078c6022b305 to your computer and use it in GitHub Desktop.
advent of code day 1 in edgeql
with
# I made an object Input with a data property, which made it easier to
# develop this in the CLI. It also works fine to make the input a parameter.
input := (select Input filter .day = 1).data,
# input := <str>$0,
grps := array_unpack(str_split(input[:-1], '\n\n')),
sums := (for grp in grps union (
with entries := <int64>array_unpack(str_split(grp, '\n')),
select sum(entries)
)),
select {
part_1 := max(sums),
part_2 := sum((select sums order by sums desc limit 3)),
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment