Created
December 16, 2015 02:00
-
-
Save boone/b957876c662cfd0d96bb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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