Skip to content

Instantly share code, notes, and snippets.

@boone
Created December 16, 2015 02:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save boone/b957876c662cfd0d96bb to your computer and use it in GitHub Desktop.
Save boone/b957876c662cfd0d96bb to your computer and use it in GitHub Desktop.
// http://adventofcode.com/day/10
// run with "./advent_day_10 input iterations"
// e.g. ./advent_day_10 1113122113 40
package main
import "fmt"
import "os"
import "strconv"
func main() {
input := os.Args[1]
iterations, _ := strconv.Atoi(os.Args[2])
for i := 1; i <= iterations; i++ {
fmt.Printf("%d ", i)
new_input := ""
run := 1
last := input[0]
input_length := len(input)
for j := 1; j <= input_length; j++ {
if j < input_length && input[j] == last {
run += 1
} else {
new_input += strconv.Itoa(run) + string(last)
if j < input_length {
last = input[j]
run = 1
}
}
}
input = new_input
}
fmt.Printf("\n%d\n", len(input))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment