Combine AoC Repos
This commit is contained in:
1000
2015/day02/input
Normal file
1000
2015/day02/input
Normal file
File diff suppressed because it is too large
Load Diff
73
2015/day02/main.go
Normal file
73
2015/day02/main.go
Normal file
@@ -0,0 +1,73 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func main() {
|
||||
var input []string
|
||||
var readInp string
|
||||
for {
|
||||
_, err := fmt.Scan(&readInp)
|
||||
if err != nil {
|
||||
if err != io.EOF {
|
||||
log.Fatal(err)
|
||||
}
|
||||
break
|
||||
}
|
||||
input = append(input, readInp)
|
||||
}
|
||||
var totalPaper, totalRibbon int
|
||||
for _, k := range input {
|
||||
l, w, h := parseInputString(k)
|
||||
totalPaper += calcPaperForPresent(l, w, h)
|
||||
totalRibbon += calcRibbonForPresent(l, w, h)
|
||||
}
|
||||
fmt.Printf("The elves need %d sq ft of wrapping paper\n", totalPaper)
|
||||
fmt.Printf("and %d ft of ribbon.\n", totalRibbon)
|
||||
}
|
||||
|
||||
func parseInputString(inp string) (int, int, int) {
|
||||
dim := strings.Split(inp, "x")
|
||||
if len(dim) == 3 {
|
||||
pt1, _ := strconv.Atoi(dim[0])
|
||||
pt2, _ := strconv.Atoi(dim[1])
|
||||
pt3, _ := strconv.Atoi(dim[2])
|
||||
return pt1, pt2, pt3
|
||||
}
|
||||
return 0, 0, 0
|
||||
}
|
||||
|
||||
func calcPaperForPresent(l, w, h int) int {
|
||||
pt1 := l * w
|
||||
pt2 := w * h
|
||||
pt3 := h * l
|
||||
pt4 := pt3
|
||||
if pt1 < pt2 && pt1 < pt3 {
|
||||
pt4 = pt1
|
||||
} else if pt2 < pt3 {
|
||||
pt4 = pt2
|
||||
}
|
||||
return pt1*2 + pt2*2 + pt3*2 + pt4
|
||||
}
|
||||
|
||||
func calcRibbonForPresent(l, w, h int) int {
|
||||
var low1, low2 int
|
||||
low2 = h
|
||||
if l < w {
|
||||
low1 = l
|
||||
if w < h {
|
||||
low2 = w
|
||||
}
|
||||
} else {
|
||||
low1 = w
|
||||
if l < h {
|
||||
low2 = l
|
||||
}
|
||||
}
|
||||
return low1*2 + low2*2 + (l * w * h)
|
||||
}
|
77
2015/day02/problem
Normal file
77
2015/day02/problem
Normal file
@@ -0,0 +1,77 @@
|
||||
Advent of Code
|
||||
|
||||
br0xen 40*
|
||||
|
||||
• [About]
|
||||
• [Stats]
|
||||
• [Leaderboard]
|
||||
• [Settings]
|
||||
• [Log out]
|
||||
|
||||
--- Day 2: I Was Told There Would Be No Math ---
|
||||
|
||||
The elves are running low on wrapping paper, and so they need to submit an order for more. They
|
||||
have a list of the dimensions (length l, width w, and height h) of each present, and only want
|
||||
to order exactly as much as they need.
|
||||
|
||||
Fortunately, every present is a box (a perfect right rectangular prism), which makes
|
||||
calculating the required wrapping paper for each gift a little easier: find the surface area of
|
||||
the box, which is 2*l*w + 2*w*h + 2*h*l. The elves also need a little extra paper for each
|
||||
present: the area of the smallest side.
|
||||
|
||||
For example:
|
||||
|
||||
• A present with dimensions 2x3x4 requires 2*6 + 2*12 + 2*8 = 52 square feet of wrapping
|
||||
paper plus 6 square feet of slack, for a total of 58 square feet.
|
||||
• A present with dimensions 1x1x10 requires 2*1 + 2*10 + 2*10 = 42 square feet of wrapping
|
||||
paper plus 1 square foot of slack, for a total of 43 square feet.
|
||||
|
||||
All numbers in the elves' list are in feet. How many total square feet of wrapping paper should
|
||||
they order?
|
||||
|
||||
Your puzzle answer was 1588178.
|
||||
|
||||
--- Part Two ---
|
||||
|
||||
The elves are also running low on ribbon. Ribbon is all the same width, so they only have to
|
||||
worry about the length they need to order, which they would again like to be exact.
|
||||
|
||||
The ribbon required to wrap a present is the shortest distance around its sides, or the
|
||||
smallest perimeter of any one face. Each present also requires a bow made out of ribbon as
|
||||
well; the feet of ribbon required for the perfect bow is equal to the cubic feet of volume of
|
||||
the present. Don't ask how they tie the bow, though; they'll never tell.
|
||||
|
||||
For example:
|
||||
|
||||
• A present with dimensions 2x3x4 requires 2+2+3+3 = 10 feet of ribbon to wrap the present
|
||||
plus 2*3*4 = 24 feet of ribbon for the bow, for a total of 34 feet.
|
||||
• A present with dimensions 1x1x10 requires 1+1+1+1 = 4 feet of ribbon to wrap the present
|
||||
plus 1*1*10 = 10 feet of ribbon for the bow, for a total of 14 feet.
|
||||
|
||||
How many total feet of ribbon should they order?
|
||||
|
||||
Your puzzle answer was 3783758.
|
||||
|
||||
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
|
||||
. https://en.wikipedia.org/wiki/Cuboid#Rectangular_cuboid
|
||||
. http://adventofcode.com/
|
||||
. http://adventofcode.com/day/2/input
|
||||
. https://twitter.com/intent/tweet?text=I%27ve+completed+%22I+Was+Told+There+Would+Be+No+Math%22+%2D+Day+2+%2D+Advent+of+Code&url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F2&related=ericwastl&hashtags=AdventOfCode
|
||||
. https://plus.google.com/share?url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F2
|
||||
. http://www.reddit.com/submit?url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F2&title=I%27ve+completed+%22I+Was+Told+There+Would+Be+No+Math%22+%2D+Day+2+%2D+Advent+of+Code
|
Reference in New Issue
Block a user