From c2744420f190800dac8bc9c17a058e3998291cc9 Mon Sep 17 00:00:00 2001 From: Nathan Lasseter Date: Fri, 11 Dec 2015 11:24:34 +0000 Subject: Day 11 --- day11/Makefile | 1 + day11/day11.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ day11/day11.input | 1 + day11/day11.readme | 27 +++++++++++++++++++++ 4 files changed, 100 insertions(+) create mode 120000 day11/Makefile create mode 100644 day11/day11.c create mode 100644 day11/day11.input create mode 100644 day11/day11.readme (limited to 'day11') diff --git a/day11/Makefile b/day11/Makefile new file mode 120000 index 0000000..d0b0e8e --- /dev/null +++ b/day11/Makefile @@ -0,0 +1 @@ +../Makefile \ No newline at end of file diff --git a/day11/day11.c b/day11/day11.c new file mode 100644 index 0000000..3a12820 --- /dev/null +++ b/day11/day11.c @@ -0,0 +1,71 @@ +#include +#include +#include + +char* incr(char password[8]) { + int i, rollover = 1; + + for(i = 7; (i >= 0) && rollover; i--) { + if(password[i] == 'z') { + password[i] = 'a'; + } else { + password[i] += 1; + rollover = 0; + } + } + + return password; +} + +char check(char* password) { + char i, flags = 2, firstpair = 0; + + for(i = 0; i < 5; i++) + if(password[i+1] == password[i] + 1 && password[i+2] == password[i] + 2) + flags |= 1; + + for(i = 0; i < 8; i++) + if(password[i] == 'i' || password[i] == 'o' || password[i] == 'l') + flags &= (~2); + + for(i = 0; i < 7; i++) { + if(password[i] == password[i+1]) { + if(firstpair) { + if(password[i] != firstpair) + flags |= 4; + } + else + firstpair = password[i]; + i++; + } + } + + return (flags == 7); +} + +char* next(char* password) { + char good = 0; + + while(!good) { + password = incr(password); + good = check(password); + } + + return password; +} + +int main() { + char *password; + password = malloc(10*sizeof(char)); + scanf("%s", password); + + password = next(password); + printf("First new password: %s\n", password); + + password = next(password); + printf("Second new password: %s\n", password); + + free(password); + + return 0; +} diff --git a/day11/day11.input b/day11/day11.input new file mode 100644 index 0000000..5915be7 --- /dev/null +++ b/day11/day11.input @@ -0,0 +1 @@ +cqjxjnds diff --git a/day11/day11.readme b/day11/day11.readme new file mode 100644 index 0000000..a4e2614 --- /dev/null +++ b/day11/day11.readme @@ -0,0 +1,27 @@ +--- Day 11: Corporate Policy --- + +Santa's previous password expired, and he needs help choosing a new one. + +To help him remember his new password after the old one expires, Santa has devised a method of coming up with a password based on the previous one. Corporate policy dictates that passwords must be exactly eight lowercase letters (for security reasons), so he finds his new password by incrementing his old password string repeatedly until it is valid. + +Incrementing is just like counting with numbers: xx, xy, xz, ya, yb, and so on. Increase the rightmost letter one step; if it was z, it wraps around to a, and repeat with the next letter to the left until one doesn't wrap around. + +Unfortunately for Santa, a new Security-Elf recently started, and he has imposed some additional password requirements: + + - Passwords must include one increasing straight of at least three letters, like abc, bcd, cde, and so on, up to xyz. They cannot skip letters; abd doesn't count. + - Passwords may not contain the letters i, o, or l, as these letters can be mistaken for other characters and are therefore confusing. + - Passwords must contain at least two different, non-overlapping pairs of letters, like aa, bb, or zz. + +For example: + + - hijklmmn meets the first requirement (because it contains the straight hij) but fails the second requirement requirement (because it contains i and l). + - abbceffg meets the third requirement (because it repeats bb and ff) but fails the first requirement. + - abbcegjk fails the third requirement, because it only has one double letter (bb). + - The next password after abcdefgh is abcdffaa. + - The next password after ghijklmn is ghjaabcc, because you eventually skip all the passwords that start with ghi..., since i is not allowed. + +Given Santa's current password (your puzzle input), what should his next password be? + +--- Part Two --- + +Santa's password expired again. What's the next one? -- cgit v1.2.1