mirror of
https://github.com/bertptrs/adventofcode.git
synced 2025-12-27 13:50:32 +01:00
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.
This commit is contained in:
29
day-10/solution.py
Normal file
29
day-10/solution.py
Normal file
@@ -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)
|
||||||
@@ -2,12 +2,6 @@
|
|||||||
|
|
||||||
rundir()
|
rundir()
|
||||||
{
|
{
|
||||||
if hash pypy &> /dev/null; then
|
|
||||||
python=pypy
|
|
||||||
else
|
|
||||||
python=python
|
|
||||||
fi
|
|
||||||
|
|
||||||
input=""
|
input=""
|
||||||
if [ -f $1/input.txt ]; then
|
if [ -f $1/input.txt ]; then
|
||||||
input="$1/input.txt"
|
input="$1/input.txt"
|
||||||
@@ -15,7 +9,8 @@ rundir()
|
|||||||
|
|
||||||
for i in $1/*.py; do
|
for i in $1/*.py; do
|
||||||
echo "$i" "$input"
|
echo "$i" "$input"
|
||||||
$python "$i" "$input"
|
python "$i" "$input"
|
||||||
|
echo
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user