From e7c9108b95e39d7ea5a29ae06d619c4727f11027 Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Fri, 29 Oct 2021 23:02:39 +0200 Subject: Initial commit --- 2015/10/.gitignore | 2 ++ 2015/10/Makefile | 12 ++++++++++++ 2015/10/README | 10 ++++++++++ 2015/10/input | 1 + 2015/10/puzzles.go | 31 +++++++++++++++++++++++++++++++ 2015/10/puzzles.sh | 13 +++++++++++++ 6 files changed, 69 insertions(+) create mode 100644 2015/10/.gitignore create mode 100644 2015/10/Makefile create mode 100644 2015/10/README create mode 100644 2015/10/input create mode 100644 2015/10/puzzles.go create mode 100755 2015/10/puzzles.sh (limited to '2015/10') 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 -- cgit v1.2.3