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)]"
44 "execution_count": 56,
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": 59,
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": 43,
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": 45,
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": 47,
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": 17,
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": 17,
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": 18,
609 "def transpose(grid):\n",
610 " return list(zip(*grid))"
615 "execution_count": 19,
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": 19,
677 "output_type": "execute_result"
681 "transpose(trantor_grid)"
686 "execution_count": 20,
692 "def count_empty_rows(grid, col):\n",
693 " return len(list(itertools.takewhile(lambda c: c == '.', transpose(grid)[col-1])))"
698 "execution_count": 21,
758 "execution_count": 21,
760 "output_type": "execute_result"
764 "[count_empty_rows(trantor_grid, i) for i in range(1, WIDTH+1)]"
769 "execution_count": 22,
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": 23,
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": 23,
836 "output_type": "execute_result"
845 "execution_count": 24,
853 "['rotate column 19 1',\n",
854 " 'rotate column 46 1',\n",
855 " 'rotate column 10 1',\n",
856 " 'rotate column 25 2',\n",
857 " 'rotate column 39 1',\n",
858 " 'rotate column 3 1',\n",
859 " 'rotate column 4 1',\n",
860 " 'rotate column 41 1',\n",
861 " 'rotate column 47 1',\n",
862 " 'rotate column 14 2',\n",
863 " 'rotate column 21 2',\n",
864 " 'rotate column 48 1',\n",
865 " 'rotate column 34 1',\n",
866 " 'rotate column 49 2',\n",
867 " 'rotate column 28 1',\n",
868 " 'rotate column 32 1',\n",
869 " 'rotate column 18 1',\n",
870 " 'rotate column 45 1',\n",
871 " 'rotate column 12 1',\n",
872 " 'rotate column 38 2',\n",
873 " 'rotate column 24 1',\n",
874 " 'rotate column 40 1',\n",
875 " 'rotate column 17 2',\n",
876 " 'rotate column 7 1',\n",
877 " 'rotate column 31 1',\n",
878 " 'rotate column 5 1',\n",
879 " 'rotate column 26 3',\n",
880 " 'rotate column 6 1',\n",
881 " 'rotate column 35 1',\n",
882 " 'rotate column 20 1',\n",
883 " 'rotate column 42 2',\n",
884 " 'rotate column 11 1',\n",
885 " 'rotate column 33 1',\n",
886 " 'rotate column 13 1',\n",
887 " 'rotate column 27 5']"
890 "execution_count": 24,
892 "output_type": "execute_result"
896 "lift_cols(tg(), randomise=True)"
901 "execution_count": 25,
907 "def count_empty_cols(grid, row):\n",
908 " return len(list(itertools.takewhile(lambda r: r == '.', grid[row-1])))"
913 "execution_count": 26,
919 "[2, 0, 4, 4, 4, 4, 0, 50]"
922 "execution_count": 26,
924 "output_type": "execute_result"
928 "[count_empty_cols(trantor_grid, i) for i in range(1, HEIGHT+1)]"
933 "execution_count": 27,
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": 28,
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": 29,
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": 30,
1001 "['***********.******.*****.*..***********.******....',\n",
1002 " '*....*...*..*...*..*...*....*....*...*..*...*.....',\n",
1003 " '*....*..*...*...*..*.*.*....*....*...*..*..*......',\n",
1004 " '*....*.**...*..**..*.*.*....*....*...*..*.**......',\n",
1005 " '*....*...*..*...*..*...*....*........*..*...*.....',\n",
1006 " '*........*......*...........*.......*.......*.....',\n",
1007 " '..................................................',\n",
1008 " '..................................................']"
1011 "execution_count": 30,
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": 31,
1040 "['top 1 11', 'top 13 18', 'top 20 24', 'top 26 26', 'top 29 39', 'top 41 46']"
1043 "execution_count": 31,
1045 "output_type": "execute_result"
1049 "g = interpret(cmds, tg(), uninterpret=True)\n",
1054 "cell_type": "code",
1055 "execution_count": 32,
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": 33,
1104 "output_type": "stream",
1106 "..................................................\n",
1107 "..................................................\n",
1108 "..................................................\n",
1109 "..................................................\n",
1110 "..................................................\n",
1111 "..................................................\n",
1112 "..................................................\n",
1113 "..................................................\n"
1122 "execution_count": 33,
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": 34,
1162 "['..................................................',\n",
1163 " '..................................................',\n",
1164 " '..................................................',\n",
1165 " '..................................................',\n",
1166 " '..................................................',\n",
1167 " '..................................................',\n",
1168 " '..................................................',\n",
1169 " '..................................................']"
1172 "execution_count": 34,
1174 "output_type": "execute_result"
1179 "interpret(cmds, g, uninterpret=True)"
1183 "cell_type": "code",
1184 "execution_count": 35,
1190 "['..................................................',\n",
1191 " '..*****..****....***...*...*..*****...***...****..',\n",
1192 " '....*....*...*..*...*..**..*....*....*...*..*...*.',\n",
1193 " '....*....*..*...*...*..*.*.*....*....*...*..*..*..',\n",
1194 " '....*....****...*****..*.*.*....*....*...*..****..',\n",
1195 " '....*....*...*..*...*..*..**....*....*...*..*...*.',\n",
1196 " '....*....*...*..*...*..*...*....*.....***...*...*.',\n",
1197 " '..................................................']"
1200 "execution_count": 35,
1202 "output_type": "execute_result"
1210 "cell_type": "code",
1211 "execution_count": 36,
1219 " 'rotate column 2 2',\n",
1220 " 'rotate column 25 2',\n",
1227 " 'rotate column 7 2',\n",
1228 " 'rotate column 5 2',\n",
1229 " 'rotate column 4 2',\n",
1230 " 'rotate column 6 1',\n",
1231 " 'rotate column 8 2',\n",
1232 " 'rotate column 13 2',\n",
1233 " 'rotate column 22 1',\n",
1234 " 'rotate column 2 2',\n",
1235 " 'rotate column 18 2',\n",
1236 " 'rotate column 25 1',\n",
1245 " 'rotate column 19 1',\n",
1246 " 'rotate column 9 3',\n",
1247 " 'rotate column 25 1',\n",
1248 " 'rotate column 3 5',\n",
1249 " 'rotate column 33 3',\n",
1250 " 'rotate column 5 1',\n",
1251 " 'rotate column 2 1',\n",
1252 " 'rotate column 12 3',\n",
1253 " 'rotate column 21 3',\n",
1254 " 'rotate column 14 3',\n",
1255 " 'rotate column 22 1',\n",
1256 " 'rotate column 6 2',\n",
1257 " 'rotate column 26 3',\n",
1258 " 'rotate column 10 1',\n",
1259 " 'rotate column 35 3',\n",
1260 " 'rotate column 16 3',\n",
1261 " 'rotate column 18 2',\n",
1262 " 'rotate column 30 3',\n",
1263 " 'rotate column 13 2',\n",
1264 " 'rotate column 15 1',\n",
1265 " 'rotate column 37 3',\n",
1266 " 'rotate column 8 2',\n",
1267 " 'rotate column 4 2',\n",
1268 " 'rotate column 29 4',\n",
1269 " 'rotate column 7 3',\n",
1270 " 'rotate column 34 3',\n",
1272 " 'rotate row 5 4',\n",
1273 " 'rotate row 6 15',\n",
1274 " 'rotate row 2 3',\n",
1275 " 'rotate row 4 1',\n",
1276 " 'rotate row 3 4',\n",
1278 " 'rotate row 4 1',\n",
1279 " 'rotate row 2 4',\n",
1280 " 'rotate row 3 4',\n",
1281 " 'rotate row 6 7',\n",
1282 " 'rotate row 5 3',\n",
1284 " 'rotate row 2 7',\n",
1285 " 'rotate row 4 1',\n",
1286 " 'rotate row 6 7',\n",
1287 " 'rotate row 3 3',\n",
1288 " 'rotate row 5 4',\n",
1297 " 'rotate column 38 1',\n",
1298 " 'rotate column 33 2',\n",
1299 " 'rotate column 25 1',\n",
1300 " 'rotate column 3 1',\n",
1301 " 'rotate column 40 2',\n",
1302 " 'rotate column 31 1',\n",
1303 " 'rotate column 16 1',\n",
1304 " 'rotate column 42 1',\n",
1305 " 'rotate column 32 1',\n",
1306 " 'rotate column 19 2',\n",
1307 " 'rotate column 37 1',\n",
1308 " 'rotate column 10 1',\n",
1309 " 'rotate column 21 1',\n",
1310 " 'rotate column 18 5',\n",
1311 " 'rotate column 30 1',\n",
1312 " 'rotate column 44 1',\n",
1313 " 'rotate column 8 1',\n",
1314 " 'rotate column 4 1',\n",
1315 " 'rotate column 5 2',\n",
1316 " 'rotate column 36 1',\n",
1317 " 'rotate column 24 2',\n",
1318 " 'rotate column 29 1',\n",
1319 " 'rotate column 2 1',\n",
1320 " 'rotate column 15 1',\n",
1321 " 'rotate column 12 2',\n",
1322 " 'rotate column 9 1',\n",
1323 " 'rotate column 43 1',\n",
1324 " 'rotate column 45 1',\n",
1325 " 'rotate column 17 1',\n",
1326 " 'rotate column 11 4',\n",
1327 " 'rotate column 28 1',\n",
1328 " 'rotate column 7 1',\n",
1329 " 'rotate column 39 3',\n",
1331 " 'rotate row 2 1',\n",
1332 " 'rotate row 6 5',\n",
1333 " 'rotate row 5 5',\n",
1334 " 'rotate row 3 5',\n",
1335 " 'rotate row 4 5',\n",
1336 " 'rotate row 7 5',\n",
1338 " 'rotate row 4 4',\n",
1339 " 'rotate row 2 2',\n",
1340 " 'rotate row 3 4',\n",
1341 " 'rotate row 5 4',\n",
1342 " 'rotate row 7 4',\n",
1343 " 'rotate row 6 4']"
1346 "execution_count": 36,
1348 "output_type": "execute_result"
1356 "cell_type": "code",
1357 "execution_count": 37,
1362 "output_type": "stream",
1365 "..................................................\n",
1366 "..*****..****....***...*...*..*****...***...****..\n",
1367 "....*....*...*..*...*..**..*....*....*...*..*...*.\n",
1368 "....*....*..*...*...*..*.*.*....*....*...*..*..*..\n",
1369 "....*....****...*****..*.*.*....*....*...*..****..\n",
1370 "....*....*...*..*...*..*..**....*....*...*..*...*.\n",
1371 "....*....*...*..*...*..*...*....*.....***...*...*.\n",
1372 "..................................................\n"
1378 "['..................................................',\n",
1379 " '..*****..****....***...*...*..*****...***...****..',\n",
1380 " '....*....*...*..*...*..**..*....*....*...*..*...*.',\n",
1381 " '....*....*..*...*...*..*.*.*....*....*...*..*..*..',\n",
1382 " '....*....****...*****..*.*.*....*....*...*..****..',\n",
1383 " '....*....*...*..*...*..*..**....*....*...*..*...*.',\n",
1384 " '....*....*...*..*...*..*...*....*.....***...*...*.',\n",
1385 " '..................................................']"
1388 "execution_count": 37,
1390 "output_type": "execute_result"
1395 "interpret(cmds, g, show_each_step=True, overprint=True)"
1399 "cell_type": "code",
1400 "execution_count": 38,
1405 "output_type": "stream",
1408 "..................................................\n",
1409 "..................................................\n",
1410 "..................................................\n",
1411 "..................................................\n",
1412 "..................................................\n",
1413 "..................................................\n",
1414 "..................................................\n",
1415 "..................................................\n"
1421 "['..................................................',\n",
1422 " '..................................................',\n",
1423 " '..................................................',\n",
1424 " '..................................................',\n",
1425 " '..................................................',\n",
1426 " '..................................................',\n",
1427 " '..................................................',\n",
1428 " '..................................................']"
1431 "execution_count": 38,
1433 "output_type": "execute_result"
1438 "interpret(cmds, g, show_each_step=True, overprint=True, uninterpret=True)"
1442 "cell_type": "code",
1443 "execution_count": 39,
1452 "execution_count": 39,
1454 "output_type": "execute_result"
1458 "sum(1 for c in ''.join(tg()) if c == '*')"
1462 "cell_type": "code",
1463 "execution_count": 41,
1472 "execution_count": 41,
1474 "output_type": "execute_result"
1478 "open('03-pixels.txt', 'w').write('\\n'.join(cmds))"
1482 "cell_type": "code",
1483 "execution_count": 48,
1488 "output_type": "stream",
1490 "................................................................................\n",
1491 "................................................................................\n",
1492 "................................................................................\n",
1493 "................................................................................\n",
1494 "................................................................................\n",
1495 "................................................................................\n",
1496 "................................................................................\n",
1497 "................................................................................\n"
1506 "execution_count": 48,
1508 "output_type": "execute_result"
1512 "g = jantar_mantar() \n",
1515 "while '*' in ''.join(g):\n",
1516 " if random.choice([True, False]):\n",
1517 " c = slide_rows(g, randomise=True)\n",
1518 " interpret(c, g, uninterpret=True)\n",
1519 " cmds = c + cmds\n",
1521 " c = unleft(g, randomise=True)\n",
1522 " interpret(c, g, uninterpret=True)\n",
1523 " cmds = c + cmds\n",
1526 " c = lift_cols(g, randomise=True)\n",
1527 " interpret(c, g, uninterpret=True)\n",
1528 " cmds = c + cmds\n",
1530 " c = untop(g, randomise=True)\n",
1531 " interpret(c, g, uninterpret=True)\n",
1532 " cmds = c + cmds\n",
1539 "cell_type": "code",
1540 "execution_count": 61,
1545 "output_type": "stream",
1548 "...****..............*...................*.....*..............*.................\n",
1549 "......*..............*...................***..**..............*.................\n",
1550 "......*.*****.*****.****.*****..****.....*.*.***.*****.*****.****.*****..****...\n",
1551 "......*.....*.*...*..*.......*..*........*..**.*.....*.*...*..*.......*..*......\n",
1552 "......*.*****.*...*..*...*****..*........*..*..*.*****.*...*..*...*****..*......\n",
1553 "......*.*...*.*...*..*...*...*..*........*.....*.*...*.*...*..*...*...*..*......\n",
1554 "...*..*.*..**.*...*..**..*..**..*........*.....*.*..**.*...*..**..*..**..*......\n",
1555 "....**...**.*.*...*...**..**.*..*........*.....*..**.*.*...*...**..**.*..*......\n"
1561 "['...****..............*...................*.....*..............*.................',\n",
1562 " '......*..............*...................***..**..............*.................',\n",
1563 " '......*.*****.*****.****.*****..****.....*.*.***.*****.*****.****.*****..****...',\n",
1564 " '......*.....*.*...*..*.......*..*........*..**.*.....*.*...*..*.......*..*......',\n",
1565 " '......*.*****.*...*..*...*****..*........*..*..*.*****.*...*..*...*****..*......',\n",
1566 " '......*.*...*.*...*..*...*...*..*........*.....*.*...*.*...*..*...*...*..*......',\n",
1567 " '...*..*.*..**.*...*..**..*..**..*........*.....*.*..**.*...*..**..*..**..*......',\n",
1568 " '....**...**.*.*...*...**..**.*..*........*.....*..**.*.*...*...**..**.*..*......']"
1571 "execution_count": 61,
1573 "output_type": "execute_result"
1577 "g = new_grid(w=80)\n",
1578 "interpret(cmds, g, show_each_step=True, overprint=True)"
1582 "cell_type": "code",
1583 "execution_count": 50,
1592 "execution_count": 50,
1594 "output_type": "execute_result"
1598 "len(jantar_mantar()[0])"
1602 "cell_type": "code",
1603 "execution_count": 51,
1612 "execution_count": 51,
1614 "output_type": "execute_result"
1618 "open('03-pixels.txt', 'w').write('\\n'.join(cmds))"
1622 "cell_type": "code",
1623 "execution_count": 57,
1628 "output_type": "stream",
1632 " * ***** ***** **** ***** **** * * *** ***** ***** **** ***** **** \n",
1633 " * * * * * * * * ** * * * * * * * \n",
1634 " * ***** * * * ***** * * * * ***** * * * ***** * \n",
1635 " * * * * * * * * * * * * * * * * * * * \n",
1636 " * * * ** * * ** * ** * * * * ** * * ** * ** * \n",
1637 " ** ** * * * ** ** * * * * ** * * * ** ** * * \n"
1642 "print_grid(jantar_mantar(), suppress_dots=True)"
1646 "cell_type": "code",
1647 "execution_count": null,
1657 "display_name": "Python 3",
1658 "language": "python",
1662 "codemirror_mode": {
1666 "file_extension": ".py",
1667 "mimetype": "text/x-python",
1669 "nbconvert_exporter": "python",
1670 "pygments_lexer": "ipython3",