Combine AoC Repos
This commit is contained in:
4
2015/day15/input
Normal file
4
2015/day15/input
Normal file
@@ -0,0 +1,4 @@
|
||||
Frosting: capacity 4, durability -2, flavor 0, texture 0, calories 5
|
||||
Candy: capacity 0, durability 5, flavor -1, texture 0, calories 8
|
||||
Butterscotch: capacity -1, durability 0, flavor 5, texture 0, calories 6
|
||||
Sugar: capacity 0, durability 0, flavor -2, texture 2, calories 1
|
156
2015/day15/main.go
Normal file
156
2015/day15/main.go
Normal file
@@ -0,0 +1,156 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var ings []ingredient
|
||||
|
||||
func main() {
|
||||
var input []string
|
||||
scanner := bufio.NewScanner(os.Stdin)
|
||||
for scanner.Scan() {
|
||||
input = append(input, scanner.Text())
|
||||
}
|
||||
|
||||
var stringIngs []string
|
||||
total := 100
|
||||
for i := range input {
|
||||
bldI := *createIngredient(input[i])
|
||||
ings = append(ings, bldI)
|
||||
stringIngs = append(stringIngs, bldI.name)
|
||||
}
|
||||
|
||||
combis := getIntCombis(total, len(stringIngs))
|
||||
ingPerms := getStringPermus(stringIngs)
|
||||
|
||||
var highVal int
|
||||
var highMap map[string]int
|
||||
for h := range combis {
|
||||
for i := range ingPerms {
|
||||
tstMap := make(map[string]int)
|
||||
for j := range ingPerms[i] {
|
||||
tstMap[ingPerms[i][j]] = combis[h][j]
|
||||
}
|
||||
tmp, cals := calcValue(tstMap)
|
||||
if cals == 500 && tmp > highVal {
|
||||
highVal = tmp
|
||||
highMap = tstMap
|
||||
|
||||
fmt.Print(strconv.Itoa(tmp))
|
||||
fmt.Print(" :: ")
|
||||
fmt.Println(tstMap)
|
||||
}
|
||||
}
|
||||
}
|
||||
fmt.Println()
|
||||
fmt.Println(highMap)
|
||||
fmt.Println("Highest Value: " + strconv.Itoa(highVal))
|
||||
}
|
||||
|
||||
func getStringPermus(vals []string) [][]string {
|
||||
var ret [][]string
|
||||
if len(vals) == 1 {
|
||||
return append(ret, vals)
|
||||
}
|
||||
|
||||
for j := range vals {
|
||||
var bld []string
|
||||
for i := range vals {
|
||||
if i != j {
|
||||
bld = append(bld, vals[i])
|
||||
}
|
||||
}
|
||||
tmp := getStringPermus(bld)
|
||||
for i := range tmp {
|
||||
tmp[i] = append([]string{vals[j]}, tmp[i]...)
|
||||
ret = append(ret, tmp[i])
|
||||
}
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func getIntCombis(total, containers int) [][]int {
|
||||
var ret [][]int
|
||||
if containers == 2 {
|
||||
for i := total; i >= 0; i-- { //(total / 2); i-- {
|
||||
ret = append(ret, []int{i, (total - i)})
|
||||
}
|
||||
return ret
|
||||
}
|
||||
for i := total; i >= 0; i-- { //(total / 2); i-- {
|
||||
tmp := getIntCombis((total - i), (containers - 1))
|
||||
for j := 0; j < len(tmp); j++ {
|
||||
tmp[j] = append([]int{i}, tmp[j]...)
|
||||
ret = append(ret, tmp[j])
|
||||
}
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func getIngredient(name string) *ingredient {
|
||||
for i := range ings {
|
||||
if ings[i].name == name {
|
||||
return &ings[i]
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func calcValue(list map[string]int) (int, int) {
|
||||
tmp := new(ingredient)
|
||||
for kname, v := range list {
|
||||
k := getIngredient(kname)
|
||||
tmp.capacity += k.capacity * v
|
||||
tmp.durability += k.durability * v
|
||||
tmp.flavor += k.flavor * v
|
||||
tmp.texture += k.texture * v
|
||||
tmp.calories += k.calories * v
|
||||
}
|
||||
if tmp.texture < 0 || tmp.durability < 0 || tmp.flavor < 0 || tmp.texture < 0 {
|
||||
return 0, 0
|
||||
}
|
||||
return (tmp.capacity * tmp.durability * tmp.flavor * tmp.texture), tmp.calories
|
||||
}
|
||||
|
||||
type ingredient struct {
|
||||
name string
|
||||
capacity int
|
||||
durability int
|
||||
flavor int
|
||||
texture int
|
||||
calories int
|
||||
}
|
||||
|
||||
func createIngredient(s string) *ingredient {
|
||||
parts := strings.Split(s, " ")
|
||||
name := parts[0]
|
||||
name = name[:len(name)-1]
|
||||
c := parts[2]
|
||||
d := parts[4]
|
||||
f := parts[6]
|
||||
t := parts[8]
|
||||
cal := parts[10]
|
||||
i := ingredient{
|
||||
name: name,
|
||||
capacity: mustAtoi(c[:len(c)-1]),
|
||||
durability: mustAtoi(d[:len(d)-1]),
|
||||
flavor: mustAtoi(f[:len(f)-1]),
|
||||
texture: mustAtoi(t[:len(t)-1]),
|
||||
calories: mustAtoi(cal),
|
||||
}
|
||||
return &i
|
||||
}
|
||||
|
||||
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
|
||||
}
|
92
2015/day15/problem
Normal file
92
2015/day15/problem
Normal file
@@ -0,0 +1,92 @@
|
||||
Advent of Code
|
||||
|
||||
br0xen 40*
|
||||
|
||||
• [About]
|
||||
• [Stats]
|
||||
• [Leaderboard]
|
||||
• [Settings]
|
||||
• [Log out]
|
||||
|
||||
--- Day 15: Science for Hungry People ---
|
||||
|
||||
Today, you set out on the task of perfecting your milk-dunking cookie recipe. All you have to
|
||||
do is find the right balance of ingredients.
|
||||
|
||||
Your recipe leaves room for exactly 100 teaspoons of ingredients. You make a list of the
|
||||
remaining ingredients you could use to finish the recipe (your puzzle input) and their
|
||||
properties per teaspoon:
|
||||
|
||||
• capacity (how well it helps the cookie absorb milk)
|
||||
• durability (how well it keeps the cookie intact when full of milk)
|
||||
• flavor (how tasty it makes the cookie)
|
||||
• texture (how it improves the feel of the cookie)
|
||||
• calories (how many calories it adds to the cookie)
|
||||
|
||||
You can only measure ingredients in whole-teaspoon amounts accurately, and you have to be
|
||||
accurate so you can reproduce your results in the future. The total score of a cookie can be
|
||||
found by adding up each of the properties (negative totals become 0) and then multiplying
|
||||
together everything except calories.
|
||||
|
||||
For instance, suppose you have these two ingredients:
|
||||
|
||||
Butterscotch: capacity -1, durability -2, flavor 6, texture 3, calories 8
|
||||
Cinnamon: capacity 2, durability 3, flavor -2, texture -1, calories 3
|
||||
|
||||
Then, choosing to use 44 teaspoons of butterscotch and 56 teaspoons of cinnamon (because the
|
||||
amounts of each ingredient must add up to 100) would result in a cookie with the following
|
||||
properties:
|
||||
|
||||
• A capacity of 44*-1 + 56*2 = 68
|
||||
• A durability of 44*-2 + 56*3 = 80
|
||||
• A flavor of 44*6 + 56*-2 = 152
|
||||
• A texture of 44*3 + 56*-1 = 76
|
||||
|
||||
Multiplying these together (68 * 80 * 152 * 76, ignoring calories for now) results in a total
|
||||
score of 62842880, which happens to be the best score possible given these ingredients. If any
|
||||
properties had produced a negative total, it would have instead become zero, causing the whole
|
||||
score to multiply to zero.
|
||||
|
||||
Given the ingredients in your kitchen and their properties, what is the total score of the
|
||||
highest-scoring cookie you can make?
|
||||
|
||||
Your puzzle answer was 18965440.
|
||||
|
||||
--- Part Two ---
|
||||
|
||||
Your cookie recipe becomes wildly popular! Someone asks if you can make another recipe that has
|
||||
exactly 500 calories per cookie (so they can use it as a meal replacement). Keep the rest of
|
||||
your award-winning process the same (100 teaspoons, same ingredients, same scoring system).
|
||||
|
||||
For example, given the ingredients above, if you had instead selected 40 teaspoons of
|
||||
butterscotch and 60 teaspoons of cinnamon (which still adds to 100), the total calorie count
|
||||
would be 40*8 + 60*3 = 500. The total score would go down, though: only 57600000, the best you
|
||||
can do in such trying circumstances.
|
||||
|
||||
Given the ingredients in your kitchen and their properties, what is the total score of the
|
||||
highest-scoring cookie you can make with a calorie total of 500?
|
||||
|
||||
Your puzzle answer was 15862900.
|
||||
|
||||
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/15/input
|
||||
. https://twitter.com/intent/tweet?text=I%27ve+completed+%22Science+for+Hungry+People%22+%2D+Day+15+%2D+Advent+of+Code&url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F15&related=ericwastl&hashtags=AdventOfCode
|
||||
. https://plus.google.com/share?url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F15
|
||||
. http://www.reddit.com/submit?url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F15&title=I%27ve+completed+%22Science+for+Hungry+People%22+%2D+Day+15+%2D+Advent+of+Code
|
2
2015/day15/sample_input
Normal file
2
2015/day15/sample_input
Normal file
@@ -0,0 +1,2 @@
|
||||
B: c -1, dur -2, flav 6, tex 3, cal 8
|
||||
C: c 2, dur 3, flav -2, tex -1, cal 3
|
Reference in New Issue
Block a user