Day 3 Complete
Also clean up some of the problem files
This commit is contained in:
parent
9ec55d2a89
commit
2dfe2f4b2f
@ -1,19 +1,4 @@
|
||||
Advent of Code
|
||||
|
||||
• [About]
|
||||
• [AoC++]
|
||||
• [Events]
|
||||
• [Settings]
|
||||
• [Log Out]
|
||||
|
||||
br0xen (AoC++) 2*
|
||||
|
||||
<y>2016</y>
|
||||
|
||||
• [Calendar]
|
||||
• [Leaderboard]
|
||||
• [Stats]
|
||||
• [Sponsors]
|
||||
Advent of Code
|
||||
|
||||
--- Day 1: No Time for a Taxicab ---
|
||||
|
||||
@ -56,8 +41,6 @@
|
||||
|
||||
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
|
||||
@ -76,6 +59,3 @@ References
|
||||
. https://en.wikipedia.org/wiki/Taxicab_geometry
|
||||
. http://adventofcode.com/2016
|
||||
. http://adventofcode.com/2016/day/1/input
|
||||
. https://twitter.com/intent/tweet?text=I%27ve+completed+%22No+Time+for+a+Taxicab%22+%2D+Day+1+%2D+Advent+of+Code+2016&url=http%3A%2F%2Fadventofcode%2Ecom%2F2016%2Fday%2F1&related=ericwastl&hashtags=AdventOfCode
|
||||
. https://plus.google.com/share?url=http%3A%2F%2Fadventofcode%2Ecom%2F2016%2Fday%2F1
|
||||
. http://www.reddit.com/submit?url=http%3A%2F%2Fadventofcode%2Ecom%2F2016%2Fday%2F1&title=I%27ve+completed+%22No+Time+for+a+Taxicab%22+%2D+Day+1+%2D+Advent+of+Code+2016
|
||||
|
@ -1,19 +1,4 @@
|
||||
Advent of Code
|
||||
|
||||
• [About]
|
||||
• [AoC++]
|
||||
• [Events]
|
||||
• [Settings]
|
||||
• [Log Out]
|
||||
|
||||
br0xen (AoC++) 4*
|
||||
|
||||
<y>2016</y>
|
||||
|
||||
• [Calendar]
|
||||
• [Leaderboard]
|
||||
• [Stats]
|
||||
• [Sponsors]
|
||||
Advent of Code
|
||||
|
||||
--- Day 2: Bathroom Security ---
|
||||
|
||||
@ -89,8 +74,6 @@
|
||||
|
||||
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
|
||||
@ -108,6 +91,3 @@ References
|
||||
. http://adventofcode.com/2016/sponsors
|
||||
. http://adventofcode.com/2016
|
||||
. http://adventofcode.com/2016/day/2/input
|
||||
. https://twitter.com/intent/tweet?text=I%27ve+completed+%22Bathroom+Security%22+%2D+Day+2+%2D+Advent+of+Code+2016&url=http%3A%2F%2Fadventofcode%2Ecom%2F2016%2Fday%2F2&related=ericwastl&hashtags=AdventOfCode
|
||||
. https://plus.google.com/share?url=http%3A%2F%2Fadventofcode%2Ecom%2F2016%2Fday%2F2
|
||||
. http://www.reddit.com/submit?url=http%3A%2F%2Fadventofcode%2Ecom%2F2016%2Fday%2F2&title=I%27ve+completed+%22Bathroom+Security%22+%2D+Day+2+%2D+Advent+of+Code+2016
|
||||
|
BIN
day03/day03
Executable file
BIN
day03/day03
Executable file
Binary file not shown.
1599
day03/input
Normal file
1599
day03/input
Normal file
File diff suppressed because it is too large
Load Diff
88
day03/main.go
Normal file
88
day03/main.go
Normal file
@ -0,0 +1,88 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func main() {
|
||||
input := stdinToStringSlice()
|
||||
puzzleOne(input)
|
||||
puzzleTwo(input)
|
||||
}
|
||||
|
||||
func puzzleOne(input []string) {
|
||||
fmt.Println("=== Puzzle One ===")
|
||||
var numGood int
|
||||
var sides []int
|
||||
for i := range input {
|
||||
pts := strings.Fields(input[i])
|
||||
sides = []int{atoi(pts[0]), atoi(pts[1]), atoi(pts[2])}
|
||||
if isValidTriangle(sides) {
|
||||
numGood++
|
||||
}
|
||||
}
|
||||
fmt.Println("Found Good: ", numGood)
|
||||
}
|
||||
|
||||
func puzzleTwo(input []string) {
|
||||
fmt.Println("=== Puzzle Two ===")
|
||||
var numGood int
|
||||
var sides1, sides2, sides3 []int
|
||||
for i := range input {
|
||||
pts := strings.Fields(input[i])
|
||||
sides1 = append(sides1, atoi(pts[0]))
|
||||
sides2 = append(sides2, atoi(pts[1]))
|
||||
sides3 = append(sides3, atoi(pts[2]))
|
||||
if len(sides1) == 3 {
|
||||
if isValidTriangle(sides1) {
|
||||
numGood++
|
||||
}
|
||||
if isValidTriangle(sides2) {
|
||||
numGood++
|
||||
}
|
||||
if isValidTriangle(sides3) {
|
||||
numGood++
|
||||
}
|
||||
sides1 = []int{}
|
||||
sides2 = []int{}
|
||||
sides3 = []int{}
|
||||
}
|
||||
}
|
||||
fmt.Println("Found Good: ", numGood)
|
||||
}
|
||||
|
||||
func isValidTriangle(sides []int) bool {
|
||||
sort.Ints(sides)
|
||||
if sides[2] < (sides[1] + sides[0]) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func itoa(i int) string {
|
||||
return strconv.Itoa(i)
|
||||
}
|
||||
|
||||
func atoi(i string) int {
|
||||
var ret int
|
||||
var err error
|
||||
if ret, err = strconv.Atoi(i); err != nil {
|
||||
log.Fatal("Invalid Atoi")
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func stdinToStringSlice() []string {
|
||||
var input []string
|
||||
scanner := bufio.NewScanner(os.Stdin)
|
||||
for scanner.Scan() {
|
||||
input = append(input, scanner.Text())
|
||||
}
|
||||
return input
|
||||
}
|
59
day03/problem
Normal file
59
day03/problem
Normal file
@ -0,0 +1,59 @@
|
||||
Advent of Code
|
||||
|
||||
--- Day 3: Squares With Three Sides ---
|
||||
|
||||
Now that you can think clearly, you move deeper into the labyrinth of hallways and office
|
||||
furniture that makes up this part of Easter Bunny HQ. This must be a graphic design
|
||||
department; the walls are covered in specifications for triangles.
|
||||
|
||||
Or are they?
|
||||
|
||||
The design document gives the side lengths of each triangle it describes, but... 5 10 25? Some
|
||||
of these aren't triangles. You can't help but mark the impossible ones.
|
||||
|
||||
In a valid triangle, the sum of any two sides must be larger than the remaining side. For
|
||||
example, the "triangle" given above is impossible, because 5 + 10 is not larger than 25.
|
||||
|
||||
In your puzzle input, how many of the listed triangles are possible?
|
||||
|
||||
Your puzzle answer was 869.
|
||||
|
||||
The first half of this puzzle is complete! It provides one gold star: *
|
||||
|
||||
--- Part Two ---
|
||||
|
||||
Now that you've helpfully marked up their design documents, it occurs to you that triangles
|
||||
are specified in groups of three vertically. Each set of three numbers in a column specifies a
|
||||
triangle. Rows are unrelated.
|
||||
|
||||
For example, given the following specification, numbers with the same hundreds digit would be
|
||||
part of the same triangle:
|
||||
|
||||
101 301 501
|
||||
102 302 502
|
||||
103 303 503
|
||||
201 401 601
|
||||
202 402 602
|
||||
203 403 603
|
||||
|
||||
In your puzzle input, and instead reading by columns, how many of the listed triangles are
|
||||
possible?
|
||||
|
||||
Although it hasn't changed, you can still get your puzzle input.
|
||||
|
||||
References
|
||||
|
||||
Visible links
|
||||
. http://adventofcode.com/
|
||||
. http://adventofcode.com/2016/about
|
||||
. http://adventofcode.com/2016/support
|
||||
. http://adventofcode.com/2016/events
|
||||
. http://adventofcode.com/2016/settings
|
||||
. http://adventofcode.com/2016/auth/logout
|
||||
. http://adventofcode.com/2016
|
||||
. http://adventofcode.com/2016
|
||||
. http://adventofcode.com/2016/leaderboard
|
||||
. http://adventofcode.com/2016/stats
|
||||
. http://adventofcode.com/2016/sponsors
|
||||
. http://adventofcode.com/2016/sponsors
|
||||
. http://adventofcode.com/2016/day/3/input
|
Loading…
Reference in New Issue
Block a user