9 "def enflip(items, flips, burnt=False, debug=False):\n",
10 " if debug: i0 = items\n",
11 " for flip in flips:\n",
13 " items = [-i for i in reversed(items[:flip])] + items[flip:]\n",
15 " items = [i for i in reversed(items[:flip])] + items[flip:]\n",
16 " if debug: print('{} -{}-> {}'.format(i0, flip, items))\n",
17 " if debug: i0 = items\n",
23 "execution_count": 11,
27 "def burnt_sorted(pancakes):\n",
28 " return pancakes == sorted(pancakes)\n",
30 "def unburnt_sorted(pancakes):\n",
31 " simple_pancakes = [abs(p) for p in pancakes]\n",
32 " return simple_pancakes == sorted(simple_pancakes)"
37 "execution_count": 12,
41 "flips_t = [l.strip().split(': ') for l in open('../../data/07-flips.txt')]"
46 "execution_count": 13,
50 "stack = [[int(p) for p in l.split()] for c, l in flips_t if c == 'burgers'][0]\n",
51 "flips = {int(c): [int(p) for p in l.split()] for c, l in flips_t if c != 'burgers'}"
56 "execution_count": 14,
65 "execution_count": 14,
67 "output_type": "execute_result"
71 "sum(1 for f in flips.values()\n",
72 " if unburnt_sorted(enflip(stack, f)))"
77 "execution_count": 15,
86 "execution_count": 15,
88 "output_type": "execute_result"
92 "[f for f in flips\n",
93 " if burnt_sorted(enflip(stack, flips[f], burnt=True))][0]"
98 "execution_count": null,
106 "display_name": "Python 3",
107 "language": "python",
115 "file_extension": ".py",
116 "mimetype": "text/x-python",
118 "nbconvert_exporter": "python",
119 "pygments_lexer": "ipython3",