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

56
2015/day13/input Normal file
View File

@@ -0,0 +1,56 @@
Alice would gain 2 happiness units by sitting next to Bob.
Alice would gain 26 happiness units by sitting next to Carol.
Alice would lose 82 happiness units by sitting next to David.
Alice would lose 75 happiness units by sitting next to Eric.
Alice would gain 42 happiness units by sitting next to Frank.
Alice would gain 38 happiness units by sitting next to George.
Alice would gain 39 happiness units by sitting next to Mallory.
Bob would gain 40 happiness units by sitting next to Alice.
Bob would lose 61 happiness units by sitting next to Carol.
Bob would lose 15 happiness units by sitting next to David.
Bob would gain 63 happiness units by sitting next to Eric.
Bob would gain 41 happiness units by sitting next to Frank.
Bob would gain 30 happiness units by sitting next to George.
Bob would gain 87 happiness units by sitting next to Mallory.
Carol would lose 35 happiness units by sitting next to Alice.
Carol would lose 99 happiness units by sitting next to Bob.
Carol would lose 51 happiness units by sitting next to David.
Carol would gain 95 happiness units by sitting next to Eric.
Carol would gain 90 happiness units by sitting next to Frank.
Carol would lose 16 happiness units by sitting next to George.
Carol would gain 94 happiness units by sitting next to Mallory.
David would gain 36 happiness units by sitting next to Alice.
David would lose 18 happiness units by sitting next to Bob.
David would lose 65 happiness units by sitting next to Carol.
David would lose 18 happiness units by sitting next to Eric.
David would lose 22 happiness units by sitting next to Frank.
David would gain 2 happiness units by sitting next to George.
David would gain 42 happiness units by sitting next to Mallory.
Eric would lose 65 happiness units by sitting next to Alice.
Eric would gain 24 happiness units by sitting next to Bob.
Eric would gain 100 happiness units by sitting next to Carol.
Eric would gain 51 happiness units by sitting next to David.
Eric would gain 21 happiness units by sitting next to Frank.
Eric would gain 55 happiness units by sitting next to George.
Eric would lose 44 happiness units by sitting next to Mallory.
Frank would lose 48 happiness units by sitting next to Alice.
Frank would gain 91 happiness units by sitting next to Bob.
Frank would gain 8 happiness units by sitting next to Carol.
Frank would lose 66 happiness units by sitting next to David.
Frank would gain 97 happiness units by sitting next to Eric.
Frank would lose 9 happiness units by sitting next to George.
Frank would lose 92 happiness units by sitting next to Mallory.
George would lose 44 happiness units by sitting next to Alice.
George would lose 25 happiness units by sitting next to Bob.
George would gain 17 happiness units by sitting next to Carol.
George would gain 92 happiness units by sitting next to David.
George would lose 92 happiness units by sitting next to Eric.
George would gain 18 happiness units by sitting next to Frank.
George would gain 97 happiness units by sitting next to Mallory.
Mallory would gain 92 happiness units by sitting next to Alice.
Mallory would lose 96 happiness units by sitting next to Bob.
Mallory would lose 51 happiness units by sitting next to Carol.
Mallory would lose 81 happiness units by sitting next to David.
Mallory would gain 31 happiness units by sitting next to Eric.
Mallory would lose 73 happiness units by sitting next to Frank.
Mallory would lose 89 happiness units by sitting next to George.

71
2015/day13/inputwithme Normal file
View File

@@ -0,0 +1,71 @@
Alice would gain 2 happiness units by sitting next to Bob.
Alice would gain 26 happiness units by sitting next to Carol.
Alice would lose 82 happiness units by sitting next to David.
Alice would lose 75 happiness units by sitting next to Eric.
Alice would gain 42 happiness units by sitting next to Frank.
Alice would gain 38 happiness units by sitting next to George.
Alice would gain 39 happiness units by sitting next to Mallory.
Alice would gain 0 happiness units by sitting next to Brian.
Bob would gain 40 happiness units by sitting next to Alice.
Bob would lose 61 happiness units by sitting next to Carol.
Bob would lose 15 happiness units by sitting next to David.
Bob would gain 63 happiness units by sitting next to Eric.
Bob would gain 41 happiness units by sitting next to Frank.
Bob would gain 30 happiness units by sitting next to George.
Bob would gain 87 happiness units by sitting next to Mallory.
Bob would gain 0 happiness units by sitting next to Brian.
Carol would lose 35 happiness units by sitting next to Alice.
Carol would lose 99 happiness units by sitting next to Bob.
Carol would lose 51 happiness units by sitting next to David.
Carol would gain 95 happiness units by sitting next to Eric.
Carol would gain 90 happiness units by sitting next to Frank.
Carol would lose 16 happiness units by sitting next to George.
Carol would gain 94 happiness units by sitting next to Mallory.
Carol would gain 0 happiness units by sitting next to Brian.
David would gain 36 happiness units by sitting next to Alice.
David would lose 18 happiness units by sitting next to Bob.
David would lose 65 happiness units by sitting next to Carol.
David would lose 18 happiness units by sitting next to Eric.
David would lose 22 happiness units by sitting next to Frank.
David would gain 2 happiness units by sitting next to George.
David would gain 42 happiness units by sitting next to Mallory.
David would gain 0 happiness units by sitting next to Brian.
Eric would lose 65 happiness units by sitting next to Alice.
Eric would gain 24 happiness units by sitting next to Bob.
Eric would gain 100 happiness units by sitting next to Carol.
Eric would gain 51 happiness units by sitting next to David.
Eric would gain 21 happiness units by sitting next to Frank.
Eric would gain 55 happiness units by sitting next to George.
Eric would lose 44 happiness units by sitting next to Mallory.
Eric would gain 0 happiness units by sitting next to Brian.
Frank would lose 48 happiness units by sitting next to Alice.
Frank would gain 91 happiness units by sitting next to Bob.
Frank would gain 8 happiness units by sitting next to Carol.
Frank would lose 66 happiness units by sitting next to David.
Frank would gain 97 happiness units by sitting next to Eric.
Frank would lose 9 happiness units by sitting next to George.
Frank would lose 92 happiness units by sitting next to Mallory.
Frank would gain 0 happiness units by sitting next to Brian.
George would lose 44 happiness units by sitting next to Alice.
George would lose 25 happiness units by sitting next to Bob.
George would gain 17 happiness units by sitting next to Carol.
George would gain 92 happiness units by sitting next to David.
George would lose 92 happiness units by sitting next to Eric.
George would gain 18 happiness units by sitting next to Frank.
George would gain 97 happiness units by sitting next to Mallory.
George would gain 0 happiness units by sitting next to Brian.
Mallory would gain 92 happiness units by sitting next to Alice.
Mallory would lose 96 happiness units by sitting next to Bob.
Mallory would lose 51 happiness units by sitting next to Carol.
Mallory would lose 81 happiness units by sitting next to David.
Mallory would gain 31 happiness units by sitting next to Eric.
Mallory would lose 73 happiness units by sitting next to Frank.
Mallory would gain 0 happiness units by sitting next to Brian.
Mallory would lose 89 happiness units by sitting next to George.
Brian would gain 0 happiness units by sitting next to Alice.
Brian would gain 0 happiness units by sitting next to Bob.
Brian would gain 0 happiness units by sitting next to Carol.
Brian would gain 0 happiness units by sitting next to David.
Brian would gain 0 happiness units by sitting next to Eric.
Brian would gain 0 happiness units by sitting next to Frank.
Brian would gain 0 happiness units by sitting next to Mallory.

157
2015/day13/main.go Normal file
View File

@@ -0,0 +1,157 @@
package main
import (
"bufio"
"fmt"
"os"
"strconv"
"strings"
)
var people map[string]person
func main() {
var pplSlice []string
people = make(map[string]person)
var input []string
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
input = append(input, scanner.Text())
}
for i := range input {
p := parseLine(input[i])
people[p.name] = p
}
for i := range people {
pplSlice = append(pplSlice, people[i].name)
}
// Output all preferences
/*
for k, v := range people {
fmt.Println(k)
fmt.Println(" High: " + v.highName + " :: " + strconv.Itoa(v.highVal))
for pk, pv := range v.prefs {
fmt.Println(" " + pk + ": " + strconv.Itoa(pv))
}
}
*/
//getPerms(pplSlice)
first := pplSlice[0]
res := getPerms(pplSlice[1:])
var high int
var arrangement []string
for i := range res {
tstArr := append([]string{first}, res[i]...)
tst := happinessFromStrings(tstArr)
if tst > high {
high = tst
arrangement = tstArr
}
}
fmt.Println("Highest: " + strconv.Itoa(high))
fmt.Println(arrangement)
}
func getPerms(ppl []string) [][]string {
var ret [][]string
if len(ppl) == 1 {
return append(ret, ppl)
}
for j := range ppl {
var bld []string
for i := range ppl {
if i != j {
bld = append(bld, ppl[i])
}
}
perms := getPerms(bld)
for i := range perms {
perms[i] = append([]string{ppl[j]}, perms[i]...)
ret = append(ret, perms[i])
}
}
return ret
}
func happinessFromStrings(pS []string) int {
var ppl []person
for i := range pS {
ppl = append(ppl, people[pS[i]])
}
return happinessValue(ppl)
}
func happinessValue(ppl []person) int {
var ret int
for i := range ppl {
p1, p2 := getNeighbors(ppl[i], ppl)
ret += ppl[i].prefs[p1.name]
ret += ppl[i].prefs[p2.name]
}
return ret
}
func getNeighbors(p person, ppl []person) (person, person) {
var p1, p2 person
for idx := range ppl {
if ppl[idx].name == p.name {
if idx == 0 {
p1 = ppl[len(ppl)-1]
p2 = ppl[idx+1]
} else if idx == len(ppl)-1 {
p1 = ppl[idx-1]
p2 = ppl[0]
} else {
p1 = ppl[idx-1]
p2 = ppl[idx+1]
}
break
}
}
return p1, p2
}
type person struct {
name string
prefs map[string]int
highName string
highVal int
lowName string
lowVal int
}
func parseLine(s string) person {
parts := strings.Split(s, " ")
who := parts[0]
direction := parts[2]
amount := mustAtoi(parts[3])
nextTo := parts[10][:len(parts[10])-1]
if direction == "lose" {
amount = amount * -1
}
var ret person
var ok bool
if ret, ok = people[who]; !ok {
ret = person{name: who}
ret.prefs = make(map[string]int)
}
ret.prefs[nextTo] = amount
if ret.highVal < amount || ret.highName == "" {
ret.highVal, ret.highName = amount, nextTo
}
if ret.lowVal > amount || ret.lowName == "" {
ret.lowVal, ret.lowName = amount, nextTo
}
return ret
}
func mustAtoi(s string) int {
var i int
var err error
if i, err = strconv.Atoi(s); err != nil {
fmt.Println("Tried to atoi " + s)
}
return i
}

96
2015/day13/problem Normal file
View File

@@ -0,0 +1,96 @@
Advent of Code
br0xen 40*
• [About]
• [Stats]
• [Leaderboard]
• [Settings]
• [Log out]
--- Day 13: Knights of the Dinner Table ---
In years past, the holiday feast with your family hasn't gone so well. Not everyone gets along!
This year, you resolve, will be different. You're going to find the optimal seating arrangement
and avoid all those awkward conversations.
You start by writing up a list of everyone invited and the amount their happiness would
increase or decrease if they were to find themselves sitting next to each other person. You
have a circular table that will be just big enough to fit everyone comfortably, and so each
person will have exactly two neighbors.
For example, suppose you have only four attendees planned, and you calculate their potential
happiness as follows:
Alice would gain 54 happiness units by sitting next to Bob.
Alice would lose 79 happiness units by sitting next to Carol.
Alice would lose 2 happiness units by sitting next to David.
Bob would gain 83 happiness units by sitting next to Alice.
Bob would lose 7 happiness units by sitting next to Carol.
Bob would lose 63 happiness units by sitting next to David.
Carol would lose 62 happiness units by sitting next to Alice.
Carol would gain 60 happiness units by sitting next to Bob.
Carol would gain 55 happiness units by sitting next to David.
David would gain 46 happiness units by sitting next to Alice.
David would lose 7 happiness units by sitting next to Bob.
David would gain 41 happiness units by sitting next to Carol.
Then, if you seat Alice next to David, Alice would lose 2 happiness units (because David talks
so much), but David would gain 46 happiness units (because Alice is such a good listener), for
a total change of 44.
If you continue around the table, you could then seat Bob next to Alice (Bob gains 83, Alice
gains 54). Finally, seat Carol, who sits next to Bob (Carol gains 60, Bob loses 7) and David
(Carol gains 55, David gains 41). The arrangement looks like this:
+41 +46
+55 David -2
Carol Alice
+60 Bob +54
-7 +83
After trying every other seating arrangement in this hypothetical scenario, you find that this
one is the most optimal, with a total change in happiness of 330.
What is the total change in happiness for the optimal seating arrangement of the actual guest
list?
Your puzzle answer was 733.
--- Part Two ---
In all the commotion, you realize that you forgot to seat yourself. At this point, you're
pretty apathetic toward the whole thing, and your happiness wouldn't really go up or down
regardless of who you sit next to. You assume everyone else would be just as ambivalent about
sitting next to you, too.
So, add yourself to the list, and give all happiness relationships that involve you a score of
0.
What is the total change in happiness for the optimal seating arrangement that actually
includes yourself?
Your puzzle answer was 725.
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.
If you still want to see it, you can get your puzzle input.
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/
. http://adventofcode.com/day/13/input
. https://twitter.com/intent/tweet?text=I%27ve+completed+%22Knights+of+the+Dinner+Table%22+%2D+Day+13+%2D+Advent+of+Code&url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F13&related=ericwastl&hashtags=AdventOfCode
. https://plus.google.com/share?url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F13
. http://www.reddit.com/submit?url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F13&title=I%27ve+completed+%22Knights+of+the+Dinner+Table%22+%2D+Day+13+%2D+Advent+of+Code