Created
December 2, 2020 10:22
-
-
Save mrwilson/493ec7f4e5e3e1a922057ac1b2b20182 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
-- Preprocessing the input into a csv e.g. 1,3,a,abcde | |
-- Creating table: | |
CREATE TABLE aoc_2(lower int4, upper int4, letter char, password varchar); | |
--Part 1: | |
SELECT | |
count(*) | |
FROM | |
aoc_2 | |
WHERE | |
(char_length(password) - char_length(replace(password, letter, ''))) <@ int4range(lower,upper, '[]'); | |
-- Part 2: | |
SELECT | |
count(*) | |
FROM aoc_2 | |
WHERE | |
(substring(password, lower,1) = letter)::integer | |
+ (substring(password,upper,1) = letter)::integer | |
= 1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment