aboutsummaryrefslogtreecommitdiff
path: root/2015/10
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
Initial commit
Diffstat (limited to '2015/10')
-rw-r--r--2015/10/.gitignore2
-rw-r--r--2015/10/Makefile12
-rw-r--r--2015/10/README10
-rw-r--r--2015/10/input1
-rw-r--r--2015/10/puzzles.go31
-rwxr-xr-x2015/10/puzzles.sh13
6 files changed, 69 insertions, 0 deletions
diff --git a/2015/10/.gitignore b/2015/10/.gitignore
new file mode 100644
index 0000000..3971a19
--- /dev/null
+++ b/2015/10/.gitignore
@@ -0,0 +1,2 @@
+puzzle-[12]
+tmp[12].go
diff --git a/2015/10/Makefile b/2015/10/Makefile
new file mode 100644
index 0000000..8d258e1
--- /dev/null
+++ b/2015/10/Makefile
@@ -0,0 +1,12 @@
+all:
+ m4 -D INPUT=\"$$(cat input)\" -D LOOPS=40 -U len puzzles.go >tmp1.go
+ m4 -D INPUT=\"$$(cat input)\" -D LOOPS=50 -U len puzzles.go >tmp2.go
+ go build tmp1.go
+ go build tmp2.go
+ mv tmp1 puzzle-1
+ mv tmp2 puzzle-2
+ rm tmp[12].go
+
+.PHONY: clean
+clean:
+ rm -f puzzle-[12] tmp[12].go
diff --git a/2015/10/README b/2015/10/README
new file mode 100644
index 0000000..1102d82
--- /dev/null
+++ b/2015/10/README
@@ -0,0 +1,10 @@
+======
+ NOTE
+======
+
+I did not come up with the shell script solution myself, that is why I also included the very slow
+Go solution. The shell script solution comes from this Reddit post:
+
+ https://www.reddit.com/r/adventofcode/comments/3w6h3m/comment/cxtsigs/
+
+I felt that this solution was just too epic, so I included it here.
diff --git a/2015/10/input b/2015/10/input
new file mode 100644
index 0000000..13dcd63
--- /dev/null
+++ b/2015/10/input
@@ -0,0 +1 @@
+3113322113
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))
+}
diff --git a/2015/10/puzzles.sh b/2015/10/puzzles.sh
new file mode 100755
index 0000000..291ac96
--- /dev/null
+++ b/2015/10/puzzles.sh
@@ -0,0 +1,13 @@
+#!/usr/bin/env sh
+
+output()
+{
+ echo $in | tr -d '\n' | wc -c
+}
+
+in=$(cat input)
+for i in $(seq 1 50); do
+ in=$(echo "$in" | fold -w1 | uniq -c | tr -d '\n ')
+ [ $i -eq 40 ] && output
+done
+output