14 "from IPython.display import clear_output\n",
38 "def new_grid(w=WIDTH, h=HEIGHT):\n",
39 " return ['.' * w for r in range(1, h+1)]"
50 "def print_grid(grid, md=False, suppress_dots=False):\n",
53 " for row in grid:\n",
54 " if suppress_dots:\n",
55 " print(re.sub(r'\\.', ' ', row))\n",
70 "def top(grid, l, r):\n",
71 " new_segment = ''\n",
72 " for i in range(l-1, r):\n",
73 " if grid[0][i] == '.':\n",
74 " new_segment += '*'\n",
76 " new_segment += '.'\n",
77 " grid[0] = grid[0][:l-1] + new_segment + grid[0][r:]\n",
89 "def left(grid, t, b):\n",
90 " for i in range(t-1, b):\n",
91 " if grid[i][0] == '.':\n",
92 " grid[i] = '*' + grid[i][1:]\n",
94 " grid[i] = '.' + grid[i][1:]\n",
100 "execution_count": 7,
106 "def rotate_column(grid, c, raw_n):\n",
107 " n = raw_n % len(grid)\n",
108 " col = [row[c-1] for row in grid]\n",
109 " new_col = col[-n:] + col[:-n]\n",
110 " for i in range(len(grid)):\n",
111 " grid[i] = grid[i][:c-1] + new_col[i] + grid[i][c:]\n",
117 "execution_count": 8,
123 "def rotate_row(grid, r, raw_n):\n",
124 " n = raw_n % len(grid[0])\n",
125 " grid[r-1] = grid[r-1][-n:] + grid[r-1][:-n]\n",
131 "execution_count": 9,
137 "command_dispatch = {'left': left, 'top': top,\n",
138 " 'rotate row': rotate_row,\n",
139 " 'rotate column': rotate_column}"
144 "execution_count": 10,
150 "def parse(command):\n",
151 " cmd, a, b = command.rsplit(maxsplit=2)\n",
152 " return cmd, int(a), int(b) "
157 "execution_count": 11,
163 "def interpret(commands, grid=None, w=WIDTH, h=HEIGHT, \n",
164 " uninterpret=False,\n",
165 " show_each_step=False, md=False, overprint=False,\n",
166 " suppress_dots=False):\n",
167 " if grid is None:\n",
168 " grid = new_grid(w, h)\n",
169 " if uninterpret:\n",
170 " ordered_commands = reversed(commands)\n",
172 " ordered_commands = commands\n",
173 " for c in ordered_commands:\n",
174 " cmd, a, b = parse(c)\n",
175 " if uninterpret and cmd in uncommand_dispatch:\n",
176 " uncommand_dispatch[cmd](grid, a, b)\n",
177 " elif not uninterpret and cmd in command_dispatch:\n",
178 " command_dispatch[cmd](grid, a, b)\n",
180 " raise ValueError('Unknown command')\n",
181 " if show_each_step:\n",
183 " time.sleep(0.25)\n",
185 " print('`{}`'.format(c))\n",
188 " print_grid(grid, md=md, suppress_dots=suppress_dots)\n",
191 " clear_output(wait=True)\n",
192 " if show_each_step: \n",
194 " print_grid(grid, md=md, suppress_dots=suppress_dots)\n",
198 "# for i in range(10):\n",
199 "# time.sleep(0.25)\n",
201 "# clear_output(wait=True)"
205 "cell_type": "markdown",
208 "For instance, with a smaller grid that is 10 pixels wide and 4 tall, this is what a sample sequence of instructions would do.\n",
210 "* `toggle 1 6` turns on the first six pixels on the top row.\n",
218 "* `rotate column 2 3` moves the lit pixel on the second column to the bottom row.\n",
226 "* `toggle 3 10` turns off the pixels in columns 4, 5, and 6, and turns on the pixels in columns 7 to 10.\n",
235 "* `rotate column 8 1` moves the one lit pixel in column 8 down one row.\n",
243 "* `rotate row 2 6` moves that pixel off the right edge of the display, to it wraps around to appear in column 4.\n",
251 "* `left 1 3` toggles the pixels in rows 1, 2, and 3 of the first column. The top left pixel (previously on) turns off, while the pixels in rows 2 and 3 come on.\n",
263 "execution_count": 12,
268 "output_type": "stream",
278 "`rotate column 2 3`\n",
294 "`rotate column 8 1`\n",
302 "`rotate row 2 6`\n",
330 "['......*.**', '*..*......', '*.........', '.*........']"
333 "execution_count": 12,
335 "output_type": "execute_result"
341 "rotate column 2 3\n",
343 "rotate column 8 1\n",
346 "'''.split('\\n')[1:-1]\n",
347 "interpret(cmds, w=10, h=4, show_each_step=True, md=True)"
352 "execution_count": 13,
358 "def unrotate_column(grid, c, raw_n):\n",
359 " return rotate_column(grid, c, (-1 * raw_n) % len(grid))\n",
361 "def unrotate_row(grid, r, raw_n):\n",
362 " return rotate_row(grid, r, (-1 * raw_n) % len(grid[0]))\n"
367 "execution_count": 14,
373 "uncommand_dispatch = {'left': left, 'top': top,\n",
374 " 'rotate row': unrotate_row,\n",
375 " 'rotate column': unrotate_column}"
380 "execution_count": 15,
386 "['..................................................',\n",
387 " '..*****..****....***...*...*..*****...***...****..',\n",
388 " '....*....*...*..*...*..**..*....*....*...*..*...*.',\n",
389 " '....*....*..*...*...*..*.*.*....*....*...*..*..*..',\n",
390 " '....*....****...*****..*.*.*....*....*...*..****..',\n",
391 " '....*....*...*..*...*..*..**....*....*...*..*...*.',\n",
392 " '....*....*...*..*...*..*...*....*.....***...*...*.',\n",
393 " '..................................................']"
396 "execution_count": 15,
398 "output_type": "execute_result"
402 "trantor_grid = '''\n",
403 "..................................................\n",
404 "..*****..****....***...*...*..*****...***...****..\n",
405 "....*....*...*..*...*..**..*....*....*...*..*...*.\n",
406 "....*....*..*...*...*..*.*.*....*....*...*..*..*..\n",
407 "....*....****...*****..*.*.*....*....*...*..****..\n",
408 "....*....*...*..*...*..*..**....*....*...*..*...*.\n",
409 "....*....*...*..*...*..*...*....*.....***...*...*.\n",
410 "..................................................\n",
411 "'''.split('\\n')[1:-1]\n",
417 "execution_count": 16,
425 "..................................................\n",
426 "..*****..****....***...*...*..*****...***...****..\n",
427 "....*....*...*..*...*..**..*....*....*...*..*...*.\n",
428 "....*....*..*...*...*..*.*.*....*....*...*..*..*..\n",
429 "....*....****...*****..*.*.*....*....*...*..****..\n",
430 "....*....*...*..*...*..*..**....*....*...*..*...*.\n",
431 "....*....*...*..*...*..*...*....*.....***...*...*.\n",
432 "..................................................\n",
433 "'''.split('\\n')[1:-1]"
438 "execution_count": 17,
443 "output_type": "stream",
445 "....................................................................................................\n",
446 "....................................................................................................\n",
447 "....................................................................................................\n",
448 "....................................................................................................\n",
449 "....................................................................................................\n",
450 "....................................................................................................\n",
451 "....................................................................................................\n",
452 "....................................................................................................\n"
457 "print_grid(new_grid(100, 8))"
462 "execution_count": 18,
468 "def jantar_mantar():\n",
470 "..*****.............................................................................................\n",
471 ".....*..............................................................................................\n",
472 ".....*..............................................................................................\n",
473 ".....*..............................................................................................\n",
474 ".....*..............................................................................................\n",
475 ".....*..............................................................................................\n",
476 ".*...*..............................................................................................\n",
477 "..***...............................................................................................\n",
478 "'''.split('\\n')[1:-1]"
483 "execution_count": 19,
489 "def jantar_mantar():\n",
491 "...****..............*...................*.....*..............*.................\n",
492 "......*..............*...................***..**..............*.................\n",
493 "......*.*****.*****.****.*****..****.....*.*.***.*****.*****.****.*****..****...\n",
494 "......*.....*.*...*..*.......*..*........*..**.*.....*.*...*..*.......*..*......\n",
495 "......*.*****.*...*..*...*****..*........*..*..*.*****.*...*..*...*****..*......\n",
496 "......*.*...*.*...*..*...*...*..*........*.....*.*...*.*...*..*...*...*..*......\n",
497 "...*..*.*..**.*...*..**..*..**..*........*.....*.*..**.*...*..**..*..**..*......\n",
498 "....**...**.*.*...*...**..**.*..*........*.....*..**.*.*...*...**..**.*..*......\n",
499 "'''.split('\\n')[1:-1]"
504 "execution_count": 20,
509 "output_type": "stream",
512 "..................................................\n",
513 "..*****..****....***...*...*..*****...***...****..\n",
514 "*...*....*...*..*...*..**..*....*....*...*..*...*.\n",
515 "*...*....*..*...*...*..*.*.*....*....*...*..*..*..\n",
516 "*...*....****...*****..*.*.*....*....*...*..****..\n",
517 "*...*....*...*..*...*..*..**....*....*...*..*...*.\n",
518 "*...*....*...*..*...*..*...*....*.....***...*...*.\n",
519 "..................................................\n",
521 "rotate column 1 1\n",
522 "..................................................\n",
523 "*.*****..****....***...*...*..*****...***...****..\n",
524 "*...*....*...*..*...*..**..*....*....*...*..*...*.\n",
525 "*...*....*..*...*...*..*.*.*....*....*...*..*..*..\n",
526 "*...*....****...*****..*.*.*....*....*...*..****..\n",
527 "*...*....*...*..*...*..*..**....*....*...*..*...*.\n",
528 "....*....*...*..*...*..*...*....*.....***...*...*.\n",
529 "..................................................\n",
532 "..................................................\n",
533 "*.*****..****....***...*...*..*****...***...****..\n",
534 "....*....*...*..*...*..**..*....*....*...*..*...*.\n",
535 "....*....*..*...*...*..*.*.*....*....*...*..*..*..\n",
536 "....*....****...*****..*.*.*....*....*...*..****..\n",
537 "....*....*...*..*...*..*..**....*....*...*..*...*.\n",
538 "*...*....*...*..*...*..*...*....*.....***...*...*.\n",
539 "..................................................\n",
541 "rotate column 3 1\n",
542 "..*...............................................\n",
543 "*..****..****....***...*...*..*****...***...****..\n",
544 "....*....*...*..*...*..**..*....*....*...*..*...*.\n",
545 "....*....*..*...*...*..*.*.*....*....*...*..*..*..\n",
546 "....*....****...*****..*.*.*....*....*...*..****..\n",
547 "....*....*...*..*...*..*..**....*....*...*..*...*.\n",
548 "*...*....*...*..*...*..*...*....*.....***...*...*.\n",
549 "..................................................\n",
552 "..*...............................................\n",
553 "*..****..****....***...*...*..*****...***...****..\n",
554 "....*....*...*..*...*..**..*....*....*...*..*...*.\n",
555 "....*....*..*...*...*..*.*.*....*....*...*..*..*..\n",
556 "....*....****...*****..*.*.*....*....*...*..****..\n",
557 "....*....*...*..*...*..*..**....*....*...*..*...*.\n",
558 "*...*....*...*..*...*..*...*....*.....***...*...*.\n",
559 "..................................................\n"
565 "['..*...............................................',\n",
566 " '*..****..****....***...*...*..*****...***...****..',\n",
567 " '....*....*...*..*...*..**..*....*....*...*..*...*.',\n",
568 " '....*....*..*...*...*..*.*.*....*....*...*..*..*..',\n",
569 " '....*....****...*****..*.*.*....*....*...*..****..',\n",
570 " '....*....*...*..*...*..*..**....*....*...*..*...*.',\n",
571 " '*...*....*...*..*...*..*...*....*.....***...*...*.',\n",
572 " '..................................................']"
575 "execution_count": 20,
577 "output_type": "execute_result"
581 "trantor_grid = '''\n",
582 "..................................................\n",
583 "..*****..****....***...*...*..*****...***...****..\n",
584 "....*....*...*..*...*..**..*....*....*...*..*...*.\n",
585 "....*....*..*...*...*..*.*.*....*....*...*..*..*..\n",
586 "....*....****...*****..*.*.*....*....*...*..****..\n",
587 "....*....*...*..*...*..*..**....*....*...*..*...*.\n",
588 "....*....*...*..*...*..*...*....*.....***...*...*.\n",
589 "..................................................\n",
590 "'''.split('\\n')[1:-1]\n",
593 "rotate column 3 1\n",
595 "rotate column 1 1\n",
597 "'''.split('\\n')[1:-1]\n",
598 "interpret(cmds, trantor_grid, show_each_step=True, uninterpret=True)"
603 "execution_count": 21,
609 "def transpose(grid):\n",
610 " return list(zip(*grid))"
615 "execution_count": 22,
623 "[('.', '*', '.', '.', '.', '.', '*', '.'),\n",
624 " ('.', '.', '.', '.', '.', '.', '.', '.'),\n",
625 " ('*', '.', '.', '.', '.', '.', '.', '.'),\n",
626 " ('.', '*', '.', '.', '.', '.', '.', '.'),\n",
627 " ('.', '*', '*', '*', '*', '*', '*', '.'),\n",
628 " ('.', '*', '.', '.', '.', '.', '.', '.'),\n",
629 " ('.', '*', '.', '.', '.', '.', '.', '.'),\n",
630 " ('.', '.', '.', '.', '.', '.', '.', '.'),\n",
631 " ('.', '.', '.', '.', '.', '.', '.', '.'),\n",
632 " ('.', '*', '*', '*', '*', '*', '*', '.'),\n",
633 " ('.', '*', '.', '.', '*', '.', '.', '.'),\n",
634 " ('.', '*', '.', '.', '*', '.', '.', '.'),\n",
635 " ('.', '*', '.', '*', '*', '.', '.', '.'),\n",
636 " ('.', '.', '*', '.', '.', '*', '*', '.'),\n",
637 " ('.', '.', '.', '.', '.', '.', '.', '.'),\n",
638 " ('.', '.', '.', '.', '.', '.', '.', '.'),\n",
639 " ('.', '.', '*', '*', '*', '*', '*', '.'),\n",
640 " ('.', '*', '.', '.', '*', '.', '.', '.'),\n",
641 " ('.', '*', '.', '.', '*', '.', '.', '.'),\n",
642 " ('.', '*', '.', '.', '*', '.', '.', '.'),\n",
643 " ('.', '.', '*', '*', '*', '*', '*', '.'),\n",
644 " ('.', '.', '.', '.', '.', '.', '.', '.'),\n",
645 " ('.', '.', '.', '.', '.', '.', '.', '.'),\n",
646 " ('.', '*', '*', '*', '*', '*', '*', '.'),\n",
647 " ('.', '.', '*', '.', '.', '.', '.', '.'),\n",
648 " ('.', '.', '.', '*', '*', '.', '.', '.'),\n",
649 " ('.', '.', '.', '.', '.', '*', '.', '.'),\n",
650 " ('.', '*', '*', '*', '*', '*', '*', '.'),\n",
651 " ('.', '.', '.', '.', '.', '.', '.', '.'),\n",
652 " ('.', '.', '.', '.', '.', '.', '.', '.'),\n",
653 " ('.', '*', '.', '.', '.', '.', '.', '.'),\n",
654 " ('.', '*', '.', '.', '.', '.', '.', '.'),\n",
655 " ('.', '*', '*', '*', '*', '*', '*', '.'),\n",
656 " ('.', '*', '.', '.', '.', '.', '.', '.'),\n",
657 " ('.', '*', '.', '.', '.', '.', '.', '.'),\n",
658 " ('.', '.', '.', '.', '.', '.', '.', '.'),\n",
659 " ('.', '.', '.', '.', '.', '.', '.', '.'),\n",
660 " ('.', '.', '*', '*', '*', '*', '.', '.'),\n",
661 " ('.', '*', '.', '.', '.', '.', '*', '.'),\n",
662 " ('.', '*', '.', '.', '.', '.', '*', '.'),\n",
663 " ('.', '*', '.', '.', '.', '.', '*', '.'),\n",
664 " ('.', '.', '*', '*', '*', '*', '.', '.'),\n",
665 " ('.', '.', '.', '.', '.', '.', '.', '.'),\n",
666 " ('.', '.', '.', '.', '.', '.', '.', '.'),\n",
667 " ('.', '*', '*', '*', '*', '*', '*', '.'),\n",
668 " ('.', '*', '.', '.', '*', '.', '.', '.'),\n",
669 " ('.', '*', '.', '.', '*', '.', '.', '.'),\n",
670 " ('.', '*', '.', '*', '*', '.', '.', '.'),\n",
671 " ('.', '.', '*', '.', '.', '*', '*', '.'),\n",
672 " ('.', '.', '.', '.', '.', '.', '.', '.')]"
675 "execution_count": 22,
677 "output_type": "execute_result"
681 "transpose(trantor_grid)"
686 "execution_count": 23,
692 "def count_empty_rows(grid, col):\n",
693 " return len(list(itertools.takewhile(lambda c: c == '.', transpose(grid)[col-1])))"
698 "execution_count": 24,
758 "execution_count": 24,
760 "output_type": "execute_result"
764 "[count_empty_rows(trantor_grid, i) for i in range(1, WIDTH+1)]"
769 "execution_count": 25,
775 "def lift_cols(grid, randomise=False):\n",
778 " for i in range(1, len(grid[0])+1):\n",
779 " n = count_empty_rows(grid, i)\n",
781 " commands.append('rotate column {} {}'.format(i, n))\n",
783 " random.shuffle(commands)\n",
789 "execution_count": 26,
797 "['rotate column 3 1',\n",
798 " 'rotate column 4 1',\n",
799 " 'rotate column 5 1',\n",
800 " 'rotate column 6 1',\n",
801 " 'rotate column 7 1',\n",
802 " 'rotate column 10 1',\n",
803 " 'rotate column 11 1',\n",
804 " 'rotate column 12 1',\n",
805 " 'rotate column 13 1',\n",
806 " 'rotate column 14 2',\n",
807 " 'rotate column 17 2',\n",
808 " 'rotate column 18 1',\n",
809 " 'rotate column 19 1',\n",
810 " 'rotate column 20 1',\n",
811 " 'rotate column 21 2',\n",
812 " 'rotate column 24 1',\n",
813 " 'rotate column 25 2',\n",
814 " 'rotate column 26 3',\n",
815 " 'rotate column 27 5',\n",
816 " 'rotate column 28 1',\n",
817 " 'rotate column 31 1',\n",
818 " 'rotate column 32 1',\n",
819 " 'rotate column 33 1',\n",
820 " 'rotate column 34 1',\n",
821 " 'rotate column 35 1',\n",
822 " 'rotate column 38 2',\n",
823 " 'rotate column 39 1',\n",
824 " 'rotate column 40 1',\n",
825 " 'rotate column 41 1',\n",
826 " 'rotate column 42 2',\n",
827 " 'rotate column 45 1',\n",
828 " 'rotate column 46 1',\n",
829 " 'rotate column 47 1',\n",
830 " 'rotate column 48 1',\n",
831 " 'rotate column 49 2']"
834 "execution_count": 26,
836 "output_type": "execute_result"
845 "execution_count": 27,
853 "['rotate column 24 1',\n",
854 " 'rotate column 41 1',\n",
855 " 'rotate column 10 1',\n",
856 " 'rotate column 18 1',\n",
857 " 'rotate column 39 1',\n",
858 " 'rotate column 3 1',\n",
859 " 'rotate column 6 1',\n",
860 " 'rotate column 14 2',\n",
861 " 'rotate column 42 2',\n",
862 " 'rotate column 32 1',\n",
863 " 'rotate column 20 1',\n",
864 " 'rotate column 38 2',\n",
865 " 'rotate column 34 1',\n",
866 " 'rotate column 31 1',\n",
867 " 'rotate column 35 1',\n",
868 " 'rotate column 28 1',\n",
869 " 'rotate column 45 1',\n",
870 " 'rotate column 13 1',\n",
871 " 'rotate column 40 1',\n",
872 " 'rotate column 5 1',\n",
873 " 'rotate column 4 1',\n",
874 " 'rotate column 12 1',\n",
875 " 'rotate column 47 1',\n",
876 " 'rotate column 25 2',\n",
877 " 'rotate column 7 1',\n",
878 " 'rotate column 49 2',\n",
879 " 'rotate column 46 1',\n",
880 " 'rotate column 26 3',\n",
881 " 'rotate column 27 5',\n",
882 " 'rotate column 19 1',\n",
883 " 'rotate column 11 1',\n",
884 " 'rotate column 17 2',\n",
885 " 'rotate column 48 1',\n",
886 " 'rotate column 33 1',\n",
887 " 'rotate column 21 2']"
890 "execution_count": 27,
892 "output_type": "execute_result"
896 "lift_cols(tg(), randomise=True)"
901 "execution_count": 28,
907 "def count_empty_cols(grid, row):\n",
908 " return len(list(itertools.takewhile(lambda r: r == '.', grid[row-1])))"
913 "execution_count": 29,
919 "[2, 0, 4, 4, 4, 4, 0, 50]"
922 "execution_count": 29,
924 "output_type": "execute_result"
928 "[count_empty_cols(trantor_grid, i) for i in range(1, HEIGHT+1)]"
933 "execution_count": 30,
939 "def slide_rows(grid, randomise=False):\n",
941 " w = len(grid[0])\n",
942 " for i in range(1, len(grid)+1):\n",
943 " n = count_empty_cols(grid, i)\n",
945 " commands.append('rotate row {} {}'.format(i, n))\n",
947 " random.shuffle(commands)\n",
953 "execution_count": 31,
959 "def untop(grid, randomise=False):\n",
960 " groups = [(k, len(list(g))) for k, g in itertools.groupby(grid[0])]\n",
963 " for c, l in groups:\n",
965 " commands.append('top {} {}'.format(col, col + l - 1))\n",
968 " random.shuffle(commands)\n",
974 "execution_count": 32,
980 "def unleft(grid, randomise=False):\n",
981 " groups = [(k, len(list(g))) for k, g in itertools.groupby(transpose(grid)[0])]\n",
984 " for c, l in groups:\n",
986 " commands.append('left {} {}'.format(row, row + l - 1))\n",
989 " random.shuffle(commands)\n",
995 "execution_count": 33,
1001 "['***********.******.*****.*..***********.******....',\n",
1002 " '*....*...*..*...*..*...*....*....*...*..*...*.....',\n",
1003 " '*....*..*...*...*..*.*.*....*....*...*..*..*......',\n",
1004 " '*....*.**...*..**..*.*.*....*....*...*..*.**......',\n",
1005 " '*....*...*..*...*..*...*....*........*..*...*.....',\n",
1006 " '*........*......*...........*.......*.......*.....',\n",
1007 " '..................................................',\n",
1008 " '..................................................']"
1011 "execution_count": 33,
1013 "output_type": "execute_result"
1017 "trantor_grid = tg() \n",
1021 "c = slide_rows(trantor_grid)\n",
1022 "cmds = c + cmds\n",
1024 "interpret(c, trantor_grid, uninterpret=True)\n",
1026 "c = lift_cols(trantor_grid)\n",
1027 "cmds = c + cmds\n",
1029 "interpret(c, trantor_grid, uninterpret=True)"
1033 "cell_type": "code",
1034 "execution_count": 34,
1040 "['top 1 11', 'top 13 18', 'top 20 24', 'top 26 26', 'top 29 39', 'top 41 46']"
1043 "execution_count": 34,
1045 "output_type": "execute_result"
1049 "g = interpret(cmds, tg(), uninterpret=True)\n",
1054 "cell_type": "code",
1055 "execution_count": 35,
1060 "output_type": "stream",
1062 "..................................................\n",
1063 ".....*...*..*...*..*...*....*....*...*..*...*.....\n",
1064 ".....*..*...*...*..*.*.*....*....*...*..*..*......\n",
1065 ".....*.**...*..**..*.*.*....*....*...*..*.**......\n",
1066 ".....*...*..*...*..*...*....*........*..*...*.....\n",
1067 ".........*......*...........*.......*.......*.....\n",
1068 "..................................................\n",
1069 "..................................................\n"
1078 "c = slide_rows(g, randomise=True)\n",
1079 "interpret(c, g, uninterpret=True)\n",
1080 "cmds = c + cmds\n",
1082 "c = lift_cols(g, randomise=True)\n",
1083 "interpret(c, g, uninterpret=True)\n",
1084 "cmds = c + cmds\n",
1086 "c = untop(g, randomise=True)\n",
1087 "interpret(c, g, uninterpret=True)\n",
1088 "cmds = c + cmds\n",
1090 "c = unleft(g, randomise=True)\n",
1091 "interpret(c, g, uninterpret=True)\n",
1092 "cmds = c + cmds\n",
1098 "cell_type": "code",
1099 "execution_count": 36,
1104 "output_type": "stream",
1106 "..................................................\n",
1107 "..................................................\n",
1108 "..................................................\n",
1109 "..................................................\n",
1110 "..................................................\n",
1111 "..................................................\n",
1112 "..................................................\n",
1113 "..................................................\n"
1122 "execution_count": 36,
1124 "output_type": "execute_result"
1131 "while '*' in ''.join(g):\n",
1132 " if random.choice([True, False]):\n",
1133 " c = slide_rows(g, randomise=True)\n",
1134 " interpret(c, g, uninterpret=True)\n",
1135 " cmds = c + cmds\n",
1137 " c = unleft(g, randomise=True)\n",
1138 " interpret(c, g, uninterpret=True)\n",
1139 " cmds = c + cmds\n",
1142 " c = lift_cols(g, randomise=True)\n",
1143 " interpret(c, g, uninterpret=True)\n",
1144 " cmds = c + cmds\n",
1146 " c = untop(g, randomise=True)\n",
1147 " interpret(c, g, uninterpret=True)\n",
1148 " cmds = c + cmds\n",
1155 "cell_type": "code",
1156 "execution_count": 37,
1162 "['..................................................',\n",
1163 " '..................................................',\n",
1164 " '..................................................',\n",
1165 " '..................................................',\n",
1166 " '..................................................',\n",
1167 " '..................................................',\n",
1168 " '..................................................',\n",
1169 " '..................................................']"
1172 "execution_count": 37,
1174 "output_type": "execute_result"
1179 "interpret(cmds, g, uninterpret=True)"
1183 "cell_type": "code",
1184 "execution_count": 38,
1190 "['..................................................',\n",
1191 " '..*****..****....***...*...*..*****...***...****..',\n",
1192 " '....*....*...*..*...*..**..*....*....*...*..*...*.',\n",
1193 " '....*....*..*...*...*..*.*.*....*....*...*..*..*..',\n",
1194 " '....*....****...*****..*.*.*....*....*...*..****..',\n",
1195 " '....*....*...*..*...*..*..**....*....*...*..*...*.',\n",
1196 " '....*....*...*..*...*..*...*....*.....***...*...*.',\n",
1197 " '..................................................']"
1200 "execution_count": 38,
1202 "output_type": "execute_result"
1210 "cell_type": "code",
1211 "execution_count": 39,
1221 " 'rotate column 29 1',\n",
1222 " 'rotate column 8 1',\n",
1223 " 'rotate column 12 1',\n",
1224 " 'rotate column 5 1',\n",
1232 " 'rotate column 5 1',\n",
1233 " 'rotate column 26 1',\n",
1234 " 'rotate column 12 1',\n",
1235 " 'rotate column 29 1',\n",
1236 " 'rotate column 8 1',\n",
1237 " 'rotate column 22 1',\n",
1238 " 'rotate column 17 1',\n",
1250 " 'rotate column 30 1',\n",
1251 " 'rotate column 5 1',\n",
1252 " 'rotate column 22 2',\n",
1253 " 'rotate column 33 1',\n",
1254 " 'rotate column 12 1',\n",
1255 " 'rotate column 21 1',\n",
1256 " 'rotate column 16 1',\n",
1257 " 'rotate column 2 1',\n",
1258 " 'rotate column 14 1',\n",
1259 " 'rotate column 9 1',\n",
1260 " 'rotate column 37 1',\n",
1261 " 'rotate column 26 1',\n",
1262 " 'rotate column 8 2',\n",
1263 " 'rotate column 17 2',\n",
1264 " 'rotate column 29 2',\n",
1266 " 'rotate row 2 3',\n",
1267 " 'rotate row 4 7',\n",
1268 " 'rotate row 5 7',\n",
1269 " 'rotate row 3 7',\n",
1278 " 'rotate column 9 3',\n",
1279 " 'rotate column 30 5',\n",
1280 " 'rotate column 37 3',\n",
1281 " 'rotate column 8 1',\n",
1282 " 'rotate column 4 2',\n",
1283 " 'rotate column 3 3',\n",
1284 " 'rotate column 19 1',\n",
1285 " 'rotate column 32 5',\n",
1286 " 'rotate column 40 3',\n",
1287 " 'rotate column 2 3',\n",
1288 " 'rotate column 29 1',\n",
1289 " 'rotate column 36 1',\n",
1290 " 'rotate column 24 1',\n",
1291 " 'rotate column 5 3',\n",
1292 " 'rotate column 31 5',\n",
1293 " 'rotate column 39 1',\n",
1294 " 'rotate column 15 1',\n",
1295 " 'rotate column 17 2',\n",
1296 " 'rotate column 38 3',\n",
1297 " 'rotate column 33 1',\n",
1298 " 'rotate column 12 1',\n",
1299 " 'rotate column 16 1',\n",
1300 " 'rotate column 10 3',\n",
1309 " 'rotate column 33 2',\n",
1310 " 'rotate column 3 1',\n",
1311 " 'rotate column 28 1',\n",
1312 " 'rotate column 24 2',\n",
1313 " 'rotate column 12 2',\n",
1314 " 'rotate column 36 1',\n",
1315 " 'rotate column 11 4',\n",
1316 " 'rotate column 10 1',\n",
1317 " 'rotate column 31 1',\n",
1318 " 'rotate column 5 2',\n",
1319 " 'rotate column 39 3',\n",
1320 " 'rotate column 32 1',\n",
1321 " 'rotate column 43 1',\n",
1322 " 'rotate column 18 5',\n",
1323 " 'rotate column 16 1',\n",
1324 " 'rotate column 45 1',\n",
1325 " 'rotate column 9 1',\n",
1326 " 'rotate column 40 2',\n",
1327 " 'rotate column 42 1',\n",
1328 " 'rotate column 4 1',\n",
1329 " 'rotate column 2 1',\n",
1330 " 'rotate column 44 1',\n",
1331 " 'rotate column 30 1',\n",
1332 " 'rotate column 19 2',\n",
1333 " 'rotate column 7 1',\n",
1334 " 'rotate column 38 1',\n",
1335 " 'rotate column 25 1',\n",
1336 " 'rotate column 21 1',\n",
1337 " 'rotate column 37 1',\n",
1338 " 'rotate column 8 1',\n",
1339 " 'rotate column 15 1',\n",
1340 " 'rotate column 17 1',\n",
1341 " 'rotate column 29 1',\n",
1343 " 'rotate row 7 5',\n",
1344 " 'rotate row 6 5',\n",
1345 " 'rotate row 5 5',\n",
1346 " 'rotate row 3 5',\n",
1347 " 'rotate row 4 5',\n",
1348 " 'rotate row 2 1',\n",
1350 " 'rotate row 2 2',\n",
1351 " 'rotate row 5 4',\n",
1352 " 'rotate row 7 4',\n",
1353 " 'rotate row 6 4',\n",
1354 " 'rotate row 3 4',\n",
1355 " 'rotate row 4 4']"
1358 "execution_count": 39,
1360 "output_type": "execute_result"
1368 "cell_type": "code",
1369 "execution_count": 40,
1374 "output_type": "stream",
1377 "..................................................\n",
1378 "..*****..****....***...*...*..*****...***...****..\n",
1379 "....*....*...*..*...*..**..*....*....*...*..*...*.\n",
1380 "....*....*..*...*...*..*.*.*....*....*...*..*..*..\n",
1381 "....*....****...*****..*.*.*....*....*...*..****..\n",
1382 "....*....*...*..*...*..*..**....*....*...*..*...*.\n",
1383 "....*....*...*..*...*..*...*....*.....***...*...*.\n",
1384 "..................................................\n"
1390 "['..................................................',\n",
1391 " '..*****..****....***...*...*..*****...***...****..',\n",
1392 " '....*....*...*..*...*..**..*....*....*...*..*...*.',\n",
1393 " '....*....*..*...*...*..*.*.*....*....*...*..*..*..',\n",
1394 " '....*....****...*****..*.*.*....*....*...*..****..',\n",
1395 " '....*....*...*..*...*..*..**....*....*...*..*...*.',\n",
1396 " '....*....*...*..*...*..*...*....*.....***...*...*.',\n",
1397 " '..................................................']"
1400 "execution_count": 40,
1402 "output_type": "execute_result"
1407 "interpret(cmds, g, show_each_step=True, overprint=True)"
1411 "cell_type": "code",
1412 "execution_count": 41,
1417 "output_type": "stream",
1420 "..................................................\n",
1421 "..................................................\n",
1422 "..................................................\n",
1423 "..................................................\n",
1424 "..................................................\n",
1425 "..................................................\n",
1426 "..................................................\n",
1427 "..................................................\n"
1433 "['..................................................',\n",
1434 " '..................................................',\n",
1435 " '..................................................',\n",
1436 " '..................................................',\n",
1437 " '..................................................',\n",
1438 " '..................................................',\n",
1439 " '..................................................',\n",
1440 " '..................................................']"
1443 "execution_count": 41,
1445 "output_type": "execute_result"
1450 "interpret(cmds, g, show_each_step=True, overprint=True, uninterpret=True)"
1454 "cell_type": "code",
1455 "execution_count": 42,
1464 "execution_count": 42,
1466 "output_type": "execute_result"
1470 "sum(1 for c in ''.join(tg()) if c == '*')"
1474 "cell_type": "code",
1475 "execution_count": 43,
1484 "execution_count": 43,
1486 "output_type": "execute_result"
1490 "open('05-pixels.txt', 'w').write('\\n'.join(cmds))"
1494 "cell_type": "code",
1495 "execution_count": 44,
1500 "output_type": "stream",
1502 "................................................................................\n",
1503 "................................................................................\n",
1504 "................................................................................\n",
1505 "................................................................................\n",
1506 "................................................................................\n",
1507 "................................................................................\n",
1508 "................................................................................\n",
1509 "................................................................................\n"
1518 "execution_count": 44,
1520 "output_type": "execute_result"
1524 "g = jantar_mantar() \n",
1527 "while '*' in ''.join(g):\n",
1528 " if random.choice([True, False]):\n",
1529 " c = slide_rows(g, randomise=True)\n",
1530 " interpret(c, g, uninterpret=True)\n",
1531 " cmds = c + cmds\n",
1533 " c = unleft(g, randomise=True)\n",
1534 " interpret(c, g, uninterpret=True)\n",
1535 " cmds = c + cmds\n",
1538 " c = lift_cols(g, randomise=True)\n",
1539 " interpret(c, g, uninterpret=True)\n",
1540 " cmds = c + cmds\n",
1542 " c = untop(g, randomise=True)\n",
1543 " interpret(c, g, uninterpret=True)\n",
1544 " cmds = c + cmds\n",
1551 "cell_type": "code",
1552 "execution_count": 45,
1557 "output_type": "stream",
1560 "...****..............*...................*.....*..............*.................\n",
1561 "......*..............*...................***..**..............*.................\n",
1562 "......*.*****.*****.****.*****..****.....*.*.***.*****.*****.****.*****..****...\n",
1563 "......*.....*.*...*..*.......*..*........*..**.*.....*.*...*..*.......*..*......\n",
1564 "......*.*****.*...*..*...*****..*........*..*..*.*****.*...*..*...*****..*......\n",
1565 "......*.*...*.*...*..*...*...*..*........*.....*.*...*.*...*..*...*...*..*......\n",
1566 "...*..*.*..**.*...*..**..*..**..*........*.....*.*..**.*...*..**..*..**..*......\n",
1567 "....**...**.*.*...*...**..**.*..*........*.....*..**.*.*...*...**..**.*..*......\n"
1573 "['...****..............*...................*.....*..............*.................',\n",
1574 " '......*..............*...................***..**..............*.................',\n",
1575 " '......*.*****.*****.****.*****..****.....*.*.***.*****.*****.****.*****..****...',\n",
1576 " '......*.....*.*...*..*.......*..*........*..**.*.....*.*...*..*.......*..*......',\n",
1577 " '......*.*****.*...*..*...*****..*........*..*..*.*****.*...*..*...*****..*......',\n",
1578 " '......*.*...*.*...*..*...*...*..*........*.....*.*...*.*...*..*...*...*..*......',\n",
1579 " '...*..*.*..**.*...*..**..*..**..*........*.....*.*..**.*...*..**..*..**..*......',\n",
1580 " '....**...**.*.*...*...**..**.*..*........*.....*..**.*.*...*...**..**.*..*......']"
1583 "execution_count": 45,
1585 "output_type": "execute_result"
1589 "g = new_grid(w=80)\n",
1590 "interpret(cmds, g, show_each_step=True, overprint=True)"
1594 "cell_type": "code",
1595 "execution_count": 46,
1604 "execution_count": 46,
1606 "output_type": "execute_result"
1610 "len(jantar_mantar()[0])"
1614 "cell_type": "code",
1615 "execution_count": 47,
1624 "execution_count": 47,
1626 "output_type": "execute_result"
1630 "open('05-pixels.txt', 'w').write('\\n'.join(cmds))"
1634 "cell_type": "code",
1635 "execution_count": 48,
1640 "output_type": "stream",
1644 " * ***** ***** **** ***** **** * * *** ***** ***** **** ***** **** \n",
1645 " * * * * * * * * ** * * * * * * * \n",
1646 " * ***** * * * ***** * * * * ***** * * * ***** * \n",
1647 " * * * * * * * * * * * * * * * * * * * \n",
1648 " * * * ** * * ** * ** * * * * ** * * ** * ** * \n",
1649 " ** ** * * * ** ** * * * * ** * * * ** ** * * \n"
1654 "print_grid(jantar_mantar(), suppress_dots=True)"
1658 "cell_type": "code",
1659 "execution_count": 49,
1664 "output_type": "stream",
1669 " * ***** ***** **** ***** **** * * *** ***** ***** **** ***** **** \n",
1670 " * * * * * * * * ** * * * * * * * \n",
1671 " * ***** * * * ***** * * * * ***** * * * ***** * \n",
1672 " * * * * * * * * * * * * * * * * * * * \n",
1673 " * * * ** * * ** * ** * * * * ** * * ** * ** * \n",
1674 " ** ** * * * ** ** * * * * ** * * * ** ** * * \n"
1679 "g = new_grid(w=80)\n",
1680 "interpret(cmds, g, show_each_step=True, overprint=True, suppress_dots=True);"
1684 "cell_type": "code",
1685 "execution_count": null,
1695 "display_name": "Python 3",
1696 "language": "python",
1700 "codemirror_mode": {
1704 "file_extension": ".py",
1705 "mimetype": "text/x-python",
1707 "nbconvert_exporter": "python",
1708 "pygments_lexer": "ipython3",