Created
December 4, 2019 08:30
-
-
Save beanz/1d943f65218ab0c10481b0ecd5e3976c to your computer and use it in GitHub Desktop.
Advent of Code 2019, Day 4 in jq
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
exec jq -r --raw-input --slurp \ | |
'def part1(r): | |
range(r[0];r[1]+1) | tostring | | |
select((. | length) == 6) | | |
select(. | test("(.)\\1")) | | |
split("") | | |
select(.[0] <= .[1] and | |
.[1] <= .[2] and | |
.[2] <= .[3] and | |
.[3] <= .[4] and | |
.[4] <= .[5]); | |
def part2(r): | |
range(r[0];r[1]+1) | tostring | | |
select((. | length) == 6) | | |
select(. | test("^(?:.*(.)((?!\\1).)\\2(?!\\2)|(.)\\3(?!\\3))")) | | |
split("") | | |
select(.[0] <= .[1] and | |
.[1] <= .[2] and | |
.[2] <= .[3] and | |
.[3] <= .[4] and | |
.[4] <= .[5]); | |
. | split("-") | map(tonumber) | | |
{ | |
p1: [part1(.)] | length, | |
p2: [part2(.)] | length | |
} | "Part 1: \(.p1)\nPart 2: \(.p2)"' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment