Combine AoC Repos

This commit is contained in:
2016-12-16 16:21:15 -06:00
parent 5977b28d73
commit 105dbd1ff7
151 changed files with 9081 additions and 1 deletions

1
2015/day11/input Normal file
View File

@@ -0,0 +1 @@
hepxcrrq

95
2015/day11/main.go Normal file
View File

@@ -0,0 +1,95 @@
package main
import (
"fmt"
"os"
"strings"
)
func printUsage() {
fmt.Println("Usage: day11 <string> [add-amt]")
fmt.Println("If add-amt isn't given, we just add 1")
os.Exit(1)
}
func main() {
args := os.Args
if len(args) < 2 {
printUsage()
}
var orig string
orig = args[1]
var valid bool
for !valid {
orig = addOneToString(orig)
valid = testPassword(orig)
}
fmt.Println(orig)
}
func addOneToString(s string) string {
lastPlace := s[len(s)-1]
ret := s[:len(s)-1]
if lastPlace == 'z' {
lastPlace = 'a'
ret = addOneToString(s[:len(s)-1])
} else {
lastPlace++
}
return ret + string(lastPlace)
}
func testPassword(s string) bool {
if hasValidChars(s) && hasStraight(s) && hasDoubles(s) {
return true
}
return false
}
// Test if string contains only valid chars
func hasValidChars(s string) bool {
if strings.Count(s, "i") > 0 {
return false
}
if strings.Count(s, "o") > 0 {
return false
}
if strings.Count(s, "l") > 0 {
return false
}
return true
}
// Test if string has a 3 char straight
func hasStraight(s string) bool {
for i := range s {
if i > 1 {
if (s[i-2] == s[i]-2) && (s[i-1] == s[i]-1) {
return true
}
}
}
return false
}
// Test if string has 2 doubles
func hasDoubles(s string) bool {
if i := hasDouble(s); i >= 0 {
return (hasDouble(s[i+2:]) >= 0)
}
return false
}
// Returns index of first double in string
// -1 if there isn't one
func hasDouble(s string) int {
for i := range s {
if i > 0 {
if s[i-1] == s[i] {
return i - 1
}
}
}
return -1
}

75
2015/day11/problem Normal file
View File

@@ -0,0 +1,75 @@
Advent of Code
br0xen 40*
• [About]
• [Stats]
• [Leaderboard]
• [Settings]
• [Log out]
--- 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?
Your puzzle answer was hepxxyzz.
--- Part Two ---
Santa's password expired again. What's the next one?
Your puzzle answer was heqaabcc.
Both parts of this puzzle are complete! They provide two gold stars: **
At this point, you should return to your advent calendar and try another puzzle.
Your puzzle input was hepxcrrq.
You can also [Shareon Twitter Google+ Reddit] this puzzle.
References
Visible links
. http://adventofcode.com/
. http://adventofcode.com/about
. http://adventofcode.com/stats
. http://adventofcode.com/leaderboard
. http://adventofcode.com/settings
. http://adventofcode.com/auth/logout
. http://adventofcode.com/
. https://twitter.com/intent/tweet?text=I%27ve+completed+%22Corporate+Policy%22+%2D+Day+11+%2D+Advent+of+Code&url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F11&related=ericwastl&hashtags=AdventOfCode
. https://plus.google.com/share?url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F11
. http://www.reddit.com/submit?url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F11&title=I%27ve+completed+%22Corporate+Policy%22+%2D+Day+11+%2D+Advent+of+Code