aboutsummaryrefslogtreecommitdiff
path: root/2015/10/puzzles.go
diff options
context:
space:
mode:
authorThomas Voss <thomasvoss@live.com> 2021-10-29 23:02:39 +0200
committerThomas Voss <thomasvoss@live.com> 2021-10-29 23:02:39 +0200
commite7c9108b95e39d7ea5a29ae06d619c4727f11027 (patch)
tree237261eef3afd0720be77dbcbb9599fa66a24b67 /2015/10/puzzles.go
Initial commit
Diffstat (limited to '2015/10/puzzles.go')
-rw-r--r--2015/10/puzzles.go31
1 files changed, 31 insertions, 0 deletions
diff --git a/2015/10/puzzles.go b/2015/10/puzzles.go
new file mode 100644
index 0000000..65de02f
--- /dev/null
+++ b/2015/10/puzzles.go
@@ -0,0 +1,31 @@
+package main
+
+import (
+ "fmt"
+ "strconv"
+)
+
+func process(num string) string {
+ var newnum string
+
+ for i := 0; i < len(num); {
+ c := num[i]
+ j := 0
+ for i < len(num) && num[i] == c {
+ i++
+ j++
+ }
+ newnum += strconv.Itoa(j)
+ newnum = string(append([]byte(newnum), c))
+ }
+
+ return newnum
+}
+
+func main() {
+ num := INPUT
+ for i := 0; i < LOOPS; i++ {
+ num = process(num)
+ }
+ fmt.Println(len(num))
+}