From b1956e0d5a9368d2757b95e4f8ba1781df7e9d84 Mon Sep 17 00:00:00 2001 From: Bert Peters Date: Thu, 10 Dec 2015 11:57:42 +0100 Subject: [PATCH] Add solution for day 10. For some reason, day 10 won't run that well with pypy, so I disabled trying pypy in the runner script. --- day-10/solution.py | 29 +++++++++++++++++++++++++++++ runall.sh | 9 ++------- 2 files changed, 31 insertions(+), 7 deletions(-) create mode 100644 day-10/solution.py diff --git a/day-10/solution.py b/day-10/solution.py new file mode 100644 index 0000000..b19a4eb --- /dev/null +++ b/day-10/solution.py @@ -0,0 +1,29 @@ +def lookandsay(line): + p = None + n = 0 + result = [] + for c in line: + if n > 0 and p is not c: + result.append(str(n)) + result.append(p) + n = 0 + + p = c + n += 1 + + result.append(str(n)) + result.append(p) + + return ''.join(result) + + +line = "1321131112" +for x in range(40): + line = lookandsay(line) + +print "40:", len(line) + +for x in range(10): + line = lookandsay(line) + +print "50:", len(line) diff --git a/runall.sh b/runall.sh index 40ba5fb..d382d30 100755 --- a/runall.sh +++ b/runall.sh @@ -2,12 +2,6 @@ rundir() { - if hash pypy &> /dev/null; then - python=pypy - else - python=python - fi - input="" if [ -f $1/input.txt ]; then input="$1/input.txt" @@ -15,7 +9,8 @@ rundir() for i in $1/*.py; do echo "$i" "$input" - $python "$i" "$input" + python "$i" "$input" + echo done }