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

20
2015/day17/input Normal file
View File

@@ -0,0 +1,20 @@
33
14
18
20
45
35
16
35
1
13
18
13
50
44
48
6
24
41
30
42

151
2015/day17/main.go Normal file
View File

@@ -0,0 +1,151 @@
package main
import (
"bufio"
"fmt"
"os"
"strconv"
"strings"
)
type container struct {
value int
name string
}
func main() {
if len(os.Args) < 2 {
fmt.Println("Usage: day17 <liters>")
os.Exit(1)
}
total := mustAtoi(os.Args[1])
var input []string
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
input = append(input, scanner.Text())
}
var containers []container
for i := range input {
val := mustAtoi(input[i])
// Generate a name for this container
var u int
for j := range containers {
if containers[j].value == val {
u++
}
}
n := strconv.Itoa(val) + "-" + strconv.Itoa(u)
containers = append(containers, container{value: val, name: n})
}
fmt.Println("All Containers: ")
fmt.Println(containers)
fmt.Println()
fmt.Println("Finding Combinations...")
res := findCombis(total, containers)
var final [][]container
fmt.Println()
fmt.Println("Sorting Results...")
for i := 0; i < len(res); i++ {
tst := sortContainers(res[i])
var dup bool
for j := 0; j < len(final); j++ {
if isEqual(tst, final[j]) {
dup = true
}
}
if !dup {
final = append(final, tst)
}
}
minNum := len(final[0])
var minConfig [][]container
for i := 0; i < len(final); i++ {
if len(final[i]) < minNum {
minNum = len(final[i])
}
}
for i := 0; i < len(final); i++ {
if len(final[i]) == minNum {
minConfig = append(minConfig, final[i])
}
}
fmt.Print("Total Combinations: ")
fmt.Println(strconv.Itoa(len(final)))
fmt.Println("Minimum Containers: " + strconv.Itoa(minNum))
fmt.Println("Num Configurations: " + strconv.Itoa(len(minConfig)))
}
func findCombis(total int, containers []container) [][]container {
var ret [][]container
for i := range containers {
if total == containers[i].value {
fmt.Print("O")
ret = append(ret, []container{containers[i]})
}
if containers[i].value < total {
fmt.Print(".")
bld := []container{containers[i]}
var pass []container
for j := range containers {
if i != j {
pass = append(pass, containers[j])
}
}
tmp := findCombis((total - containers[i].value), pass)
for idx := 0; idx < len(tmp); idx++ {
tmp[idx] = append(bld, tmp[idx]...)
}
ret = append(ret, tmp...)
}
}
return ret
}
func sortContainers(c []container) []container {
n := len(c)
swapped := true
for swapped {
swapped = false
for i := 1; i <= n-1; i++ {
if strings.Compare(c[i-1].name, c[i].name) > 0 {
tmp := c[i-1]
c[i-1] = c[i]
c[i] = tmp
swapped = true
}
}
n = n - 1
}
return c
}
func isEqual(a, b []container) bool {
if len(a) != len(b) {
return false
}
for i := 0; i < len(a); i++ {
if a[i].name != b[i].name {
return false
}
}
return true
}
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)
os.Exit(1)
}
return i
}

64
2015/day17/problem Normal file
View File

@@ -0,0 +1,64 @@
Advent of Code
br0xen 40*
• [About]
• [Stats]
• [Leaderboard]
• [Settings]
• [Log out]
--- Day 17: No Such Thing as Too Much ---
The elves bought too much eggnog again - 150 liters this time. To fit it all into your
refrigerator, you'll need to move it into smaller containers. You take an inventory of the
capacities of the available containers.
For example, suppose you have containers of size 20, 15, 10, 5, and 5 liters. If you need to
store 25 liters, there are four ways to do it:
 15 and 10
 20 and 5 (the first 5)
 20 and 5 (the second 5)
 15, 5, and 5
Filling all containers entirely, how many different combinations of containers can exactly fit
all 150 liters of eggnog?
Your puzzle answer was 1304.
--- Part Two ---
While playing with all the containers in the kitchen, another load of eggnog arrives! The
shipping and receiving department is requesting as many containers as you can spare.
Find the minimum number of containers that can exactly fit all 150 liters of eggnog. How many
different ways can you fill that number of containers and still hold exactly 150 litres?
In the example above, the minimum number of containers was two. There were three ways to use
that many containers, and so the answer there would be 3.
Your puzzle answer was 18.
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/17/input
. https://twitter.com/intent/tweet?text=I%27ve+completed+%22No+Such+Thing+as+Too+Much%22+%2D+Day+17+%2D+Advent+of+Code&url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F17&related=ericwastl&hashtags=AdventOfCode
. https://plus.google.com/share?url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F17
. http://www.reddit.com/submit?url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F17&title=I%27ve+completed+%22No+Such+Thing+as+Too+Much%22+%2D+Day+17+%2D+Advent+of+Code

5
2015/day17/sample_input Normal file
View File

@@ -0,0 +1,5 @@
20
15
10
5
5