Combine AoC Repos
This commit is contained in:
1
2015/day10/input
Normal file
1
2015/day10/input
Normal file
@@ -0,0 +1 @@
|
||||
1113122113
|
76
2015/day10/main.go
Normal file
76
2015/day10/main.go
Normal file
@@ -0,0 +1,76 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func printUsage() {
|
||||
fmt.Println("Usage: day10 <look-and-say> [iterations]")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
/* Pt 2 Result:
|
||||
Length of result: 5103798
|
||||
*/
|
||||
func main() {
|
||||
var debugMode bool
|
||||
|
||||
args := os.Args
|
||||
if len(args) < 2 {
|
||||
printUsage()
|
||||
}
|
||||
var lasString string
|
||||
lasString = args[1]
|
||||
|
||||
var iter int
|
||||
var err error
|
||||
if len(args) > 2 {
|
||||
if iter, err = strconv.Atoi(args[2]); err != nil {
|
||||
printUsage()
|
||||
}
|
||||
} else {
|
||||
iter = 40
|
||||
}
|
||||
if len(args) > 3 {
|
||||
if args[2] == "--debug" {
|
||||
debugMode = true
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Printf("Iterate %d times over %s\n", iter, lasString)
|
||||
for i := 0; i < iter; i++ {
|
||||
fmt.Print("O")
|
||||
if i%10 == 9 {
|
||||
fmt.Println(" " + strconv.Itoa(len(lasString)))
|
||||
}
|
||||
r := lookAndSay(lasString)
|
||||
if debugMode {
|
||||
fmt.Println(strconv.Itoa(i) + " >> " + r)
|
||||
}
|
||||
lasString = r
|
||||
}
|
||||
fmt.Println("\nLength of result: " + strconv.Itoa(len(lasString)))
|
||||
}
|
||||
|
||||
func lookAndSay(str string) string {
|
||||
numI := 1
|
||||
var ret string
|
||||
|
||||
strLen := len(str)
|
||||
|
||||
for i := range str {
|
||||
if strLen > i+1 {
|
||||
if str[i+1] != str[i] {
|
||||
ret += strconv.Itoa(numI) + string(str[i])
|
||||
numI = 0
|
||||
}
|
||||
} else {
|
||||
// Last char in string
|
||||
ret += strconv.Itoa(numI) + string(str[i])
|
||||
}
|
||||
numI++
|
||||
}
|
||||
return ret
|
||||
}
|
66
2015/day10/problem
Normal file
66
2015/day10/problem
Normal file
@@ -0,0 +1,66 @@
|
||||
Advent of Code
|
||||
|
||||
br0xen 40*
|
||||
|
||||
• [About]
|
||||
• [Stats]
|
||||
• [Leaderboard]
|
||||
• [Settings]
|
||||
• [Log out]
|
||||
|
||||
--- Day 10: Elves Look, Elves Say ---
|
||||
|
||||
Today, the Elves are playing a game called look-and-say. They take turns making sequences by
|
||||
reading aloud the previous sequence and using that reading as the next sequence. For example,
|
||||
211 is read as "one two, two ones", which becomes 1221 (1 2, 2 1s).
|
||||
|
||||
Look-and-say sequences are generated iteratively, using the previous value as input for the
|
||||
next step. For each step, take the previous value, and replace each run of digits (like 111)
|
||||
with the number of digits (3) followed by the digit itself (1).
|
||||
|
||||
For example:
|
||||
|
||||
• 1 becomes 11 (1 copy of digit 1).
|
||||
• 11 becomes 21 (2 copies of digit 1).
|
||||
• 21 becomes 1211 (one 2 followed by one 1).
|
||||
• 1211 becomes 111221 (one 1, one 2, and two 1s).
|
||||
• 111221 becomes 312211 (three 1s, two 2s, and one 1).
|
||||
|
||||
Starting with the digits in your puzzle input, apply this process 40 times. What is the length
|
||||
of the result?
|
||||
|
||||
Your puzzle answer was 360154.
|
||||
|
||||
--- Part Two ---
|
||||
|
||||
Neat, right? You might also enjoy hearing John Conway talking about this sequence (that's
|
||||
Conway of Conway's Game of Life fame).
|
||||
|
||||
Now, starting again with the digits in your puzzle input, apply this process 50 times. What is
|
||||
the length of the new result?
|
||||
|
||||
Your puzzle answer was 5103798.
|
||||
|
||||
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.
|
||||
|
||||
Your puzzle input was 1113122113.
|
||||
|
||||
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/Look-and-say_sequence
|
||||
. https://www.youtube.com/watch?v=ea7lJkEhytA
|
||||
. http://adventofcode.com/
|
||||
. https://twitter.com/intent/tweet?text=I%27ve+completed+%22Elves+Look%2C+Elves+Say%22+%2D+Day+10+%2D+Advent+of+Code&url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F10&related=ericwastl&hashtags=AdventOfCode
|
||||
. https://plus.google.com/share?url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F10
|
||||
. http://www.reddit.com/submit?url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F10&title=I%27ve+completed+%22Elves+Look%2C+Elves+Say%22+%2D+Day+10+%2D+Advent+of+Code
|
Reference in New Issue
Block a user