Combine AoC Repos
This commit is contained in:
1
2015/day01/input
Normal file
1
2015/day01/input
Normal file
File diff suppressed because one or more lines are too long
70
2015/day01/main.go
Normal file
70
2015/day01/main.go
Normal file
@@ -0,0 +1,70 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
)
|
||||
|
||||
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 total int
|
||||
var wentToBasement bool
|
||||
var procIdx int
|
||||
for _, k := range input {
|
||||
for i := range k {
|
||||
procIdx++
|
||||
if k[i] == '(' {
|
||||
total++
|
||||
} else if k[i] == ')' {
|
||||
total--
|
||||
}
|
||||
if total < 0 && !wentToBasement {
|
||||
wentToBasement = true
|
||||
fmt.Printf("Went to basement at direction #%d\n", procIdx)
|
||||
}
|
||||
}
|
||||
}
|
||||
fmt.Printf("Santa should go to floor %d\n", total)
|
||||
|
||||
fmt.Println("\nBen's Solution:")
|
||||
bens()
|
||||
}
|
||||
|
||||
func bens() {
|
||||
file, err := os.Open("./input")
|
||||
floor := 0
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
defer file.Close()
|
||||
for {
|
||||
data := make([]byte, 1)
|
||||
_, err := file.Read(data)
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
if data[0] == '(' {
|
||||
floor = floor + 1
|
||||
} else {
|
||||
floor = floor - 1
|
||||
}
|
||||
|
||||
}
|
||||
fmt.Printf("Floor: %d\n", floor)
|
||||
}
|
81
2015/day01/problem
Normal file
81
2015/day01/problem
Normal file
@@ -0,0 +1,81 @@
|
||||
Advent of Code
|
||||
|
||||
br0xen 40*
|
||||
|
||||
• [About]
|
||||
• [Stats]
|
||||
• [Leaderboard]
|
||||
• [Settings]
|
||||
• [Log out]
|
||||
|
||||
--- Day 1: Not Quite Lisp ---
|
||||
|
||||
Santa was hoping for a white Christmas, but his weather machine's "snow" function is powered by
|
||||
stars, and he's fresh out! To save Christmas, he needs you to collect fifty stars by December
|
||||
25th.
|
||||
|
||||
Collect stars by helping Santa solve puzzles. Two puzzles will be made available on each day in
|
||||
the advent calendar; the second puzzle is unlocked when you complete the first. Each puzzle
|
||||
grants one star. Good luck!
|
||||
|
||||
Here's an easy puzzle to warm you up.
|
||||
|
||||
Santa is trying to deliver presents in a large apartment building, but he can't find the right
|
||||
floor - the directions he got are a little confusing. He starts on the ground floor (floor 0)
|
||||
and then follows the instructions one character at a time.
|
||||
|
||||
An opening parenthesis, (, means he should go up one floor, and a closing parenthesis, ), means
|
||||
he should go down one floor.
|
||||
|
||||
The apartment building is very tall, and the basement is very deep; he will never find the top
|
||||
or bottom floors.
|
||||
|
||||
For example:
|
||||
|
||||
• (()) and ()() both result in floor 0.
|
||||
• ((( and (()(()( both result in floor 3.
|
||||
• ))((((( also results in floor 3.
|
||||
• ()) and ))( both result in floor -1 (the first basement level).
|
||||
• ))) and )())()) both result in floor -3.
|
||||
|
||||
To what floor do the instructions take Santa?
|
||||
|
||||
Your puzzle answer was 138.
|
||||
|
||||
--- Part Two ---
|
||||
|
||||
Now, given the same instructions, find the position of the first character that causes him to
|
||||
enter the basement (floor -1). The first character in the instructions has position 1, the
|
||||
second character has position 2, and so on.
|
||||
|
||||
For example:
|
||||
|
||||
• ) causes him to enter the basement at character position 1.
|
||||
• ()()) causes him to enter the basement at character position 5.
|
||||
|
||||
What is the position of the character that causes Santa to first enter the basement?
|
||||
|
||||
Your puzzle answer was 1771.
|
||||
|
||||
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/1/input
|
||||
. https://twitter.com/intent/tweet?text=I%27ve+completed+%22Not+Quite+Lisp%22+%2D+Day+1+%2D+Advent+of+Code&url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F1&related=ericwastl&hashtags=AdventOfCode
|
||||
. https://plus.google.com/share?url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F1
|
||||
. http://www.reddit.com/submit?url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F1&title=I%27ve+completed+%22Not+Quite+Lisp%22+%2D+Day+1+%2D+Advent+of+Code
|
Reference in New Issue
Block a user