From e7b049e703a0fbce5aa31aac196606e1b6474d06 Mon Sep 17 00:00:00 2001 From: Neil Smith Date: Wed, 17 May 2017 10:57:57 +0100 Subject: [PATCH] Done puzzle 2 --- 02-lifts/02-lifts.txt | 1 + 02-lifts/lifts-generator.ipynb | 385 +++++++++++++++++++++++++++++++++ 02-lifts/lifts-solution.ipynb | 199 +++++++++++++++++ 3 files changed, 585 insertions(+) create mode 100644 02-lifts/02-lifts.txt create mode 100644 02-lifts/lifts-generator.ipynb create mode 100644 02-lifts/lifts-solution.ipynb diff --git a/02-lifts/02-lifts.txt b/02-lifts/02-lifts.txt new file mode 100644 index 0000000..f591c54 --- /dev/null +++ b/02-lifts/02-lifts.txt @@ -0,0 +1 @@ +vvv^^v^v=vv^v^^vvvv^^v=^=^^=^^^=^^^v=^^^=^^v^^v^vv^^v^^^=v^v^^^v=^vvv^^^^v^^^^^v^v^v^^v=^^^^^v=v^^v=^v^^=v^^vvv=^^^vv=^^=^vv^v^^^vv^v^^vvv^v=^=^=^^v^v^^=vvvv^v^vv=^^^=^^^v^v^vv^^vv^vv^^=v=v=v^=^=^^=v^^^=v^=^vvv^^vv^^=^v^vvv=v^vv^v^^^=^v^v^vv^^^^v^vv^vv^^v=v^^v^^^^vv=vv^v=^^=vv=^v^v^^^^^vv^v=^=^^vvv^v^vvvvv^^vv^v^v^^v^=^v^^^^vvvv=^=vv^^^^^^^^v^vv^^^^v^^^v^^^v^^v^vv^^^^=vv=^v^^^vvvv^v^vvv^v^=^=v^^^^^=vvv^vvvvv^^vv^^vv^vvv^^^=v^=^=^v^^^=v=^^vvv^v^^^v=^^^=^^vv=v^^^^^^^vv^v^vv=v^^^vv=v^v^=^v^^=^^v^v^v^v^^v=v^^vvv^^v^^v^v=vvv^v^^v^=v^=^^^=^^v^^=v^vv^v^=^^v=vvvv^vvvvv^v^vvv=vv^^=^^^vv^vvvv^vv=v^=v^=v^vv=^^vv^^=^v^^^=v^v=v^v^v^v^vvv^=v=^^=^^=v^^^=v^=^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v^^^^^v^^v^^=^=^^^v^v^^^v=v^^=^^vv=^vvv=^=v^^vvv=^=^^v=v^=v^v=^=^^^^=v^^v^^v^^v=vv=^^^v=vvv^vv^^v=vvv=vv^v^v^vv^^^^^=vv=^v=vv^v=^v^^= \ No newline at end of file diff --git a/02-lifts/lifts-generator.ipynb b/02-lifts/lifts-generator.ipynb new file mode 100644 index 0000000..2bc8fc3 --- /dev/null +++ b/02-lifts/lifts-generator.ipynb @@ -0,0 +1,385 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "import random" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['^', '^', '^', 'v', 'v', 'v', '=']" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "instructions = list('^^^vvv=')\n", + "instructions" + ] + }, + { + "cell_type": "code", + "execution_count": 59, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "def build_sequence(instructions, length=100):\n", + " non_exits = [i for i in instructions if i != '=']\n", + " seq = [random.choice(non_exits)]\n", + " last_was_exit = False\n", + " for _ in range(length-2):\n", + " if last_was_exit:\n", + " seq.append(random.choice(non_exits))\n", + " last_was_exit = False\n", + " else:\n", + " i = random.choice(instructions)\n", + " last_was_exit = (i == '=')\n", + " seq.append(i)\n", + " seq.append(instructions[-1])\n", + " return ''.join(seq)" + ] + }, + { + "cell_type": "code", + "execution_count": 62, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'v=^^^vv^=='" + ] + }, + "execution_count": 62, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "build_sequence(instructions, 10)" + ] + }, + { + "cell_type": "code", + "execution_count": 66, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'vvv^v^^^^v^v=^vvv=v^vvv^=v^^v=v^^^^vv^=v^vvv^v^^vv^^vvvvv^^vv^v=^v=v^^^vvv^v^vv=v^vv^^=^vv^^vvvv=^^='" + ] + }, + "execution_count": 66, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "seq = build_sequence(instructions)\n", + "seq" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "def value(instr):\n", + " if instr == '^':\n", + " return 1\n", + " elif instr == 'v':\n", + " return -1\n", + " else:\n", + " return 0 " + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "def final(sequence):\n", + " return sum(value(i) for i in sequence)" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "-1" + ] + }, + "execution_count": 22, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "final(seq)" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "def running(sequence):\n", + " current = 0\n", + " currents = []\n", + " exits = []\n", + " for i in sequence:\n", + " if value(i) == 0:\n", + " exits.append(current)\n", + " else:\n", + " current += value(i)\n", + " currents.append(current)\n", + " return currents, exits" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "data": { + "text/plain": [ + "([1,\n", + " 2,\n", + " 3,\n", + " 2,\n", + " 3,\n", + " 4,\n", + " 5,\n", + " 4,\n", + " 5,\n", + " 4,\n", + " 5,\n", + " 4,\n", + " 3,\n", + " 4,\n", + " 3,\n", + " 2,\n", + " 3,\n", + " 4,\n", + " 3,\n", + " 2,\n", + " 3,\n", + " 4,\n", + " 5,\n", + " 6,\n", + " 5,\n", + " 4,\n", + " 3,\n", + " 4,\n", + " 3,\n", + " 2,\n", + " 1,\n", + " 2,\n", + " 3,\n", + " 4,\n", + " 3,\n", + " 4,\n", + " 3,\n", + " 2,\n", + " 1,\n", + " 2,\n", + " 1,\n", + " 2,\n", + " 3,\n", + " 2,\n", + " 3,\n", + " 4,\n", + " 3,\n", + " 2,\n", + " 1,\n", + " 0,\n", + " -1,\n", + " -2,\n", + " -3,\n", + " -4,\n", + " -3,\n", + " -2,\n", + " -1,\n", + " -2,\n", + " -3,\n", + " -4,\n", + " -3,\n", + " -2,\n", + " -1,\n", + " -2,\n", + " -3,\n", + " -2,\n", + " -3,\n", + " -4,\n", + " -5,\n", + " -4,\n", + " -3,\n", + " -4,\n", + " -5,\n", + " -4,\n", + " -5,\n", + " -4,\n", + " -3,\n", + " -2,\n", + " -1,\n", + " 0,\n", + " -1,\n", + " 0,\n", + " -1,\n", + " -2,\n", + " -3,\n", + " -2,\n", + " -1,\n", + " 0,\n", + " -1],\n", + " [5, 4, 2, 1, -2, -2, -3, -5, -5, -1, -1])" + ] + }, + "execution_count": 24, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "running(seq)" + ] + }, + { + "cell_type": "code", + "execution_count": 33, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "^vvv^^v^=vv=v^v=^vvvv^=^vv^vvv^=v=v^^v=^^v=v^=v^^vv^^==v^^v^v=vvv^^^^=vvv^^v=v=vv^^^^v^v=vv^v^=^^^^v=v=v^^^vv^vv^v^^vvv^v==^vv=^vv^vv^^vv=^=v=vv^vv^=v^^^^vvvvv=vv^^^v=^=^=vv^v=v^^^^vv=^^^^vv^^v=vv^^v^^v^vv^^==^v^=^^^^v=^v^v^v=vv^=vvv^v=^v^^^^vv^v^v^^v^v^v^^^vv^^v^^v=v^v^v^v^^v^vvvv^=^v=^^vvvv^^vv^vv^v=^v=^vvvvv^vv=vv^=v^=^^^^^=^vvvvv^=^v^=^^^v^^v^=v^^^vv^v^^vv^=^v^^^vvv=^v^^v^v^^vvvvv^vvv=^v=^^vv^^v^^vvvv=v^=v^vvvvvvv=^==^vv=v=vv=^^^^=vv^vvv^^v^vv^^^v^^v=v^^=^^^^vv^v==v^v^^v^^v^=^^^==v^^^vv^==vvvvvvv^=vv^=vv^^=v^^vvv^^^vvv^^vv=v=^^vvv^^^^v=^^vv^v^^=^v=v=^vv^^vvv^^^^vv^=v^^v^^v^v=v^^^^vvv^^=vv^=vv^^v^v^^v=v^^vv^=^v^^^=v^^v=v^vv^=^v^^v=vv^=^v^^^v^=v==v^vvvvv^vvvv^^v=^^vv^^v^^^^^=^v=^v^=^vv^v=^^^vvvv^^vv^^==^==^^^^v=v^vvvv=^v^=^vv^^v^^vvvvv=^v^^==^=^^v==v=vv^vv^^vvv=^vvvv=v=^vv=^v^^vv==vvv^^^=vv^^^vv=v=^vvv^^v^v=v^^v=^=v^vvvvvvvv===^=^vvv^vv^^vvvv^=^v^^^=^^^vvvvv^==v^^v=vvv^v=vv^vv^vv=vvv^vv^=^^^v^vv^vvv=v^vv^v^vvvvvv^^v^^^^vv^v=^=^v=v^^vvv^vv^^=^v^vv^v^=v=v^v^vvv=^^=^vv^vvv==^^v^^vvv^v^=\n", + "Final: -48\n", + "Highest 1, lowest -49, final -48.\n", + "Highest exit 0, lowest exit -49.\n" + ] + } + ], + "source": [ + "seq = build_sequence(instructions, 1000)\n", + "print(seq)\n", + "print('Final: ', final(seq))\n", + "fs, es = running(seq)\n", + "print('Highest {}, lowest {}, final {}.'.format(max(fs), min(fs), fs[-1]))\n", + "print('Highest exit {}, lowest exit {}.'.format(max(es), min(es)))" + ] + }, + { + "cell_type": "code", + "execution_count": 67, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Highest 216, lowest -6, final 209.\n", + "Highest exit 215, lowest exit -5.\n" + ] + } + ], + "source": [ + "valid_seq = False\n", + "while not valid_seq:\n", + " seq = build_sequence(instructions, 10000)\n", + " fs, es = running(seq)\n", + " if min(fs) > -10 and fs[-1] > 0:\n", + " valid_seq = True\n", + "\n", + "open('02-lifts.txt', 'w').write(seq)\n", + "print('Highest {}, lowest {}, final {}.'.format(max(fs), min(fs), fs[-1]))\n", + "print('Highest exit {}, lowest exit {}.'.format(max(es), min(es)))" + ] + }, + { + "cell_type": "code", + "execution_count": 80, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "('v^^^^^v=v=', ([-1, 0, 1, 2, 3, 4, 3, 2], [3, 2]))" + ] + }, + "execution_count": 80, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "small_seq = build_sequence(instructions, 10)\n", + "small_seq, running(small_seq)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.6.1" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/02-lifts/lifts-solution.ipynb b/02-lifts/lifts-solution.ipynb new file mode 100644 index 0000000..e938ff7 --- /dev/null +++ b/02-lifts/lifts-solution.ipynb @@ -0,0 +1,199 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Puzzle 2: Lifts\n", + "\n", + "## Part 1: using the lifts\n", + "\n", + "You've chosen your holiday, now it's time to catch your flight. You arrive at Heathwick airport and have to find the departures floor. However, getting around Terminal $\\pi$ is a real pain. The instructions for how to use the lifts are rather complex.\n", + "\n", + "You start in the car park (the basement level, floor 0) and follow this instructions one step at a time. The instructions are each one character:\n", + "* `^` : go up one floor\n", + "* `v` : go down one floor\n", + "* `=` : open the doors, without moving floors.\n", + "\n", + "The input contains no other characters.\n", + "\n", + "If you follow the instructions and get out at the end, what floor do you end up on?\n", + "\n", + "Terminal $\\pi$ is large and there's no limit to the number of floors, both up and down.\n", + "\n", + "For instance, the sequence '^=' takes you to floor 1. \n", + "\n", + "The sequence `vv^=` takes you down two floors to the sub basement (floor -2), then up one floor, and you get out in the sub-basement on floor 0.\n", + "\n", + "The sequence `^^v=^=` would start on floor 0, go up two floors, then down one. The doors would then open on floor 1, but you'd stay in the lift. You'd then move up to floor 2, the doors open, and you get out on floor 2. \n", + "\n", + "The sequence `v^^^^^v=v=` would go down one floor (to floor -1), up five floors (to floor 4), down one floor (to floor 3), open the doors, go down another floor, and you'd finally get out at floor 2.\n", + "\n", + "Given the input in [02-lifts.txt](02-lifts.txt), where would you get out?" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "def value(instr):\n", + " if instr == '^':\n", + " return 1\n", + " elif instr == 'v':\n", + " return -1\n", + " else:\n", + " return 0" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "def final(sequence):\n", + " current = 0\n", + " for c in sequence:\n", + " current += value(c)\n", + " return current" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "209" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "with open('02-lifts.txt') as f:\n", + " instructions = f.read()\n", + " exit = final(instructions)\n", + "exit" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Smart-alec one line solution" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "209" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "sum(value(i) for i in open('02-lifts.txt').read())" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Part 2: getting out\n", + "You can only leave the lift where the doors are open. What is the highest floor you could leave from?\n", + "\n", + "For instance, the sequence `^^v=^=` would allow you to exit on floors 1 and 2, so the highest floor you could leave from would be floor 2. \n", + "\n", + "The sequence `v^^^^^v=v=` would allow you to exit on floors 3 and 2, so the highest floor you could leave from would be floor 3 (even though the lift reaches floor 4)." + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "def exits(sequence):\n", + " current = 0\n", + " exits = []\n", + " for i in sequence:\n", + " if value(i) == 0:\n", + " exits.append(current)\n", + " else:\n", + " current += value(i)\n", + " return exitsto" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "215" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "max(exits(instructions))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.6.1" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} -- 2.34.1