OSDN Git Service

Working on bug #15
[joypy/Thun.git] / docs / Multiples of 3 and 5.ipynb
1 {
2  "cells": [
3   {
4    "cell_type": "markdown",
5    "id": "754f6c90",
6    "metadata": {},
7    "source": [
8     "# [Project Euler, first problem](https://projecteuler.net/problem=1)\n",
9     "\n",
10     "## Multiples of 3 and 5\n",
11     "\n",
12     "> If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.\n",
13     "\n",
14     "> Find the sum of all the multiples of 3 or 5 below 1000."
15    ]
16   },
17   {
18    "cell_type": "markdown",
19    "id": "73e9f177",
20    "metadata": {},
21    "source": [
22     "Let's create a predicate that returns `True` if a number is a multiple of 3 or 5 and `False` otherwise.  It is simple enough using the modulus operator."
23    ]
24   },
25   {
26    "cell_type": "code",
27    "execution_count": 1,
28    "id": "5e19337b",
29    "metadata": {},
30    "outputs": [
31     {
32      "name": "stdout",
33      "output_type": "stream",
34      "text": [
35       "[false false true false false true false true]"
36      ]
37     }
38    ],
39    "source": [
40     "[1 2 3 4 5 6 10 15] [3 % not] map"
41    ]
42   },
43   {
44    "cell_type": "code",
45    "execution_count": 2,
46    "id": "1fde6380",
47    "metadata": {},
48    "outputs": [
49     {
50      "name": "stdout",
51      "output_type": "stream",
52      "text": []
53     }
54    ],
55    "source": [
56     "clear"
57    ]
58   },
59   {
60    "cell_type": "code",
61    "execution_count": 3,
62    "id": "13b54b65",
63    "metadata": {},
64    "outputs": [
65     {
66      "name": "stdout",
67      "output_type": "stream",
68      "text": [
69       "[false false false false true false true true]"
70      ]
71     }
72    ],
73    "source": [
74     "[1 2 3 4 5 6 10 15] [5 % not] map"
75    ]
76   },
77   {
78    "cell_type": "code",
79    "execution_count": 4,
80    "id": "8babb9ca",
81    "metadata": {},
82    "outputs": [
83     {
84      "name": "stdout",
85      "output_type": "stream",
86      "text": []
87     }
88    ],
89    "source": [
90     "clear"
91    ]
92   },
93   {
94    "cell_type": "markdown",
95    "id": "07d952db",
96    "metadata": {},
97    "source": [
98     "Now we can run them both using `fork` and then `or` the results:"
99    ]
100   },
101   {
102    "cell_type": "code",
103    "execution_count": 5,
104    "id": "0d89ddfa",
105    "metadata": {},
106    "outputs": [
107     {
108      "name": "stdout",
109      "output_type": "stream",
110      "text": [
111       "23 false"
112      ]
113     }
114    ],
115    "source": [
116     "23 [3 % not] [5 % not] fork or"
117    ]
118   },
119   {
120    "cell_type": "code",
121    "execution_count": 6,
122    "id": "d32ee42e",
123    "metadata": {},
124    "outputs": [
125     {
126      "name": "stdout",
127      "output_type": "stream",
128      "text": []
129     }
130    ],
131    "source": [
132     "clear"
133    ]
134   },
135   {
136    "cell_type": "code",
137    "execution_count": 7,
138    "id": "f6d9f728",
139    "metadata": {},
140    "outputs": [
141     {
142      "name": "stdout",
143      "output_type": "stream",
144      "text": [
145       "[false false true false true true true true]"
146      ]
147     }
148    ],
149    "source": [
150     "[1 2 3 4 5 6 10 15] [[3 % not] [5 % not] fork or] map"
151    ]
152   },
153   {
154    "cell_type": "code",
155    "execution_count": 8,
156    "id": "c6a05e39",
157    "metadata": {},
158    "outputs": [
159     {
160      "name": "stdout",
161      "output_type": "stream",
162      "text": []
163     }
164    ],
165    "source": [
166     "clear"
167    ]
168   },
169   {
170    "cell_type": "markdown",
171    "id": "109f6b8a",
172    "metadata": {},
173    "source": [
174     "Given the predicate function (and a `filter` function, to be defined later) a suitable program is:\n",
175     "\n",
176     "    1000 range [[3 % not] [5 % not] fork or] filter sum"
177    ]
178   },
179   {
180    "cell_type": "markdown",
181    "id": "241fad42",
182    "metadata": {},
183    "source": [
184     "This function generates a list of the integers from 0 to 999, filters that list by the predicate, and then sums the result.\n",
185     "\n",
186     "Logically this is fine, but pragmatically we are doing more work than we should.  We generate one thousand integers but actually use less than half of them.  A better solution would be to generate just the multiples we want to sum, and to add them as we go rather than storing them and adding summing them at the end."
187    ]
188   },
189   {
190    "cell_type": "markdown",
191    "id": "7b1ed895",
192    "metadata": {},
193    "source": [
194     "Consider the first few terms in the series:\n",
195     "\n",
196     "    3 5 6 9 10 12 15 18 20 21 ...\n",
197     "\n",
198     "Subtract each number from the one after it (subtracting 0 from 3):\n",
199     "\n",
200     "    3 5 6 9 10 12 15 18 20 21 24 25 27 30 ...\n",
201     "    0 3 5 6  9 10 12 15 18 20 21 24 25 27 ...\n",
202     "    -------------------------------------------\n",
203     "    3 2 1 3  1  2  3  3  2  1  3  1  2  3 ...\n",
204     "\n",
205     "You get this lovely repeating palindromic sequence:\n",
206     "\n",
207     "    3 2 1 3 1 2 3\n",
208     "\n",
209     "To make a counter that increments by factors of 3 and 5 you just add\n",
210     "these differences to the counter one-by-one in a loop."
211    ]
212   },
213   {
214    "cell_type": "markdown",
215    "id": "e0e27e85",
216    "metadata": {},
217    "source": [
218     "To make use of this sequence to increment a counter and sum terms as we go we need a function that will accept the sum, the counter, and the next term to add, and that adds the term to the counter and a copy of the counter to the running sum.  This function will do that:\n",
219     "\n",
220     "    + [+] dupdip"
221    ]
222   },
223   {
224    "cell_type": "code",
225    "execution_count": 9,
226    "id": "c53bfbd2",
227    "metadata": {},
228    "outputs": [
229     {
230      "name": "stdout",
231      "output_type": "stream",
232      "text": [
233       "  0 0 3 â€¢ + [+] dupdip\n",
234       "    0 3 â€¢ [+] dupdip\n",
235       "0 3 [+] â€¢ dupdip\n",
236       "    0 3 â€¢ + 3\n",
237       "      3 â€¢ 3\n",
238       "    3 3 â€¢ \n",
239       "\n",
240       "3 3"
241      ]
242     }
243    ],
244    "source": [
245     "0 0 3 [+ [+] dupdip] trace"
246    ]
247   },
248   {
249    "cell_type": "code",
250    "execution_count": 10,
251    "id": "a49d3728",
252    "metadata": {},
253    "outputs": [
254     {
255      "name": "stdout",
256      "output_type": "stream",
257      "text": []
258     }
259    ],
260    "source": [
261     "clear"
262    ]
263   },
264   {
265    "cell_type": "code",
266    "execution_count": 11,
267    "id": "20587ac5",
268    "metadata": {},
269    "outputs": [
270     {
271      "name": "stdout",
272      "output_type": "stream",
273      "text": [
274       "60 15"
275      ]
276     }
277    ],
278    "source": [
279     "0 0 [3 2 1 3 1 2 3] [+ [+] dupdip] step"
280    ]
281   },
282   {
283    "cell_type": "markdown",
284    "id": "f560b91e",
285    "metadata": {},
286    "source": [
287     "So one `step` through all seven terms brings the counter to 15 and the total to 60."
288    ]
289   },
290   {
291    "cell_type": "code",
292    "execution_count": 12,
293    "id": "f68bf653",
294    "metadata": {},
295    "outputs": [
296     {
297      "name": "stdout",
298      "output_type": "stream",
299      "text": [
300       "0 0"
301      ]
302     }
303    ],
304    "source": [
305     "clear 0 0"
306    ]
307   },
308   {
309    "cell_type": "code",
310    "execution_count": 13,
311    "id": "b7780729",
312    "metadata": {},
313    "outputs": [
314     {
315      "name": "stdout",
316      "output_type": "stream",
317      "text": [
318       "60 15"
319      ]
320     }
321    ],
322    "source": [
323     "[3 2 1 3 1 2 3] [+ [+] dupdip] step"
324    ]
325   },
326   {
327    "cell_type": "code",
328    "execution_count": 14,
329    "id": "9316698e",
330    "metadata": {},
331    "outputs": [
332     {
333      "name": "stdout",
334      "output_type": "stream",
335      "text": [
336       "225 30"
337      ]
338     }
339    ],
340    "source": [
341     "[3 2 1 3 1 2 3] [+ [+] dupdip] step"
342    ]
343   },
344   {
345    "cell_type": "code",
346    "execution_count": 15,
347    "id": "07671594",
348    "metadata": {},
349    "outputs": [
350     {
351      "name": "stdout",
352      "output_type": "stream",
353      "text": [
354       "495 45"
355      ]
356     }
357    ],
358    "source": [
359     "[3 2 1 3 1 2 3] [+ [+] dupdip] step"
360    ]
361   },
362   {
363    "cell_type": "code",
364    "execution_count": 16,
365    "id": "adee52a7",
366    "metadata": {},
367    "outputs": [
368     {
369      "name": "stdout",
370      "output_type": "stream",
371      "text": [
372       "870 60"
373      ]
374     }
375    ],
376    "source": [
377     "[3 2 1 3 1 2 3] [+ [+] dupdip] step"
378    ]
379   },
380   {
381    "cell_type": "markdown",
382    "id": "42302528",
383    "metadata": {},
384    "source": [
385     "Going through one sequence of the palindrome counts off 15 of the 1000.  So how many \"flights\" in total do we need?"
386    ]
387   },
388   {
389    "cell_type": "code",
390    "execution_count": 17,
391    "id": "4e9d4907",
392    "metadata": {},
393    "outputs": [
394     {
395      "name": "stdout",
396      "output_type": "stream",
397      "text": []
398     }
399    ],
400    "source": [
401     "clear"
402    ]
403   },
404   {
405    "cell_type": "code",
406    "execution_count": 18,
407    "id": "bfa89997",
408    "metadata": {},
409    "outputs": [
410     {
411      "name": "stdout",
412      "output_type": "stream",
413      "text": [
414       "66"
415      ]
416     }
417    ],
418    "source": [
419     "1000 15 /"
420    ]
421   },
422   {
423    "cell_type": "markdown",
424    "id": "a04fe808",
425    "metadata": {},
426    "source": [
427     "So sixty-six times and a few left over.  How many?"
428    ]
429   },
430   {
431    "cell_type": "code",
432    "execution_count": 19,
433    "id": "86e454a7",
434    "metadata": {},
435    "outputs": [
436     {
437      "name": "stdout",
438      "output_type": "stream",
439      "text": [
440       "990"
441      ]
442     }
443    ],
444    "source": [
445     "15 *"
446    ]
447   },
448   {
449    "cell_type": "code",
450    "execution_count": 20,
451    "id": "7e9b42b5",
452    "metadata": {},
453    "outputs": [
454     {
455      "name": "stdout",
456      "output_type": "stream",
457      "text": [
458       "     990 â€¢ 1000 swap -\n",
459       "990 1000 â€¢ swap -\n",
460       "1000 990 â€¢ -\n",
461       "      10 â€¢ \n",
462       "\n",
463       "10"
464      ]
465     }
466    ],
467    "source": [
468     "[1000 swap -] trace"
469    ]
470   },
471   {
472    "cell_type": "markdown",
473    "id": "67ce48f8",
474    "metadata": {},
475    "source": [
476     "We only want the terms *less than* 1000."
477    ]
478   },
479   {
480    "cell_type": "code",
481    "execution_count": 21,
482    "id": "5f3d0371",
483    "metadata": {},
484    "outputs": [
485     {
486      "name": "stdout",
487      "output_type": "stream",
488      "text": [
489       "9"
490      ]
491     }
492    ],
493    "source": [
494     "clear 999 990 -"
495    ]
496   },
497   {
498    "cell_type": "code",
499    "execution_count": 22,
500    "id": "fc10c5c5",
501    "metadata": {},
502    "outputs": [
503     {
504      "name": "stdout",
505      "output_type": "stream",
506      "text": [
507       "9 9"
508      ]
509     }
510    ],
511    "source": [
512     "[3 2 1 3] sum"
513    ]
514   },
515   {
516    "cell_type": "code",
517    "execution_count": 23,
518    "id": "d5fb8099",
519    "metadata": {},
520    "outputs": [
521     {
522      "name": "stdout",
523      "output_type": "stream",
524      "text": [
525       "true"
526      ]
527     }
528    ],
529    "source": [
530     "="
531    ]
532   },
533   {
534    "cell_type": "markdown",
535    "id": "0fa9a216",
536    "metadata": {},
537    "source": [
538     "That means we want to run the full list of numbers sixty-six times to get to 990 and then the first four numbers 3 2 1 3 to get to 999."
539    ]
540   },
541   {
542    "cell_type": "code",
543    "execution_count": 24,
544    "id": "52e22965",
545    "metadata": {},
546    "outputs": [
547     {
548      "name": "stdout",
549      "output_type": "stream",
550      "text": [
551       "0 0"
552      ]
553     }
554    ],
555    "source": [
556     "clear 0 0"
557    ]
558   },
559   {
560    "cell_type": "code",
561    "execution_count": 25,
562    "id": "741e0688",
563    "metadata": {},
564    "outputs": [
565     {
566      "name": "stdout",
567      "output_type": "stream",
568      "text": [
569       "229185 990"
570      ]
571     }
572    ],
573    "source": [
574     "66 [[3 2 1 3 1 2 3] [+ [+] dupdip] step] times"
575    ]
576   },
577   {
578    "cell_type": "code",
579    "execution_count": 26,
580    "id": "40e1379d",
581    "metadata": {},
582    "outputs": [
583     {
584      "name": "stdout",
585      "output_type": "stream",
586      "text": [
587       "233168 999"
588      ]
589     }
590    ],
591    "source": [
592     "[3 2 1 3] [+ [+] dupdip] step"
593    ]
594   },
595   {
596    "cell_type": "code",
597    "execution_count": 27,
598    "id": "e6be7907",
599    "metadata": {},
600    "outputs": [
601     {
602      "name": "stdout",
603      "output_type": "stream",
604      "text": [
605       "233168"
606      ]
607     }
608    ],
609    "source": [
610     "pop"
611    ]
612   },
613   {
614    "cell_type": "markdown",
615    "id": "f361dae9",
616    "metadata": {},
617    "source": [
618     "Ta-da!"
619    ]
620   },
621   {
622    "cell_type": "markdown",
623    "id": "9ef9d882",
624    "metadata": {},
625    "source": [
626     "## Wee Hack\n",
627     "\n",
628     "This form uses no extra storage and produces no unused summands.  It's good but there's one more trick we can apply.  The list of seven terms takes up at least seven bytes.  But notice that all of the terms are less than four, and so each can fit in just two bits.  We could store all seven terms in just fourteen bits and use masking and shifts to pick out each term as we go.  This will use less space and save time loading whole integer terms from the list.\n",
629     "\n",
630     "        3  2  1  3  1  2  3\n",
631     "    0b 11 10 01 11 01 10 11 == 14811"
632    ]
633   },
634   {
635    "cell_type": "code",
636    "execution_count": 28,
637    "id": "4c358435",
638    "metadata": {},
639    "outputs": [
640     {
641      "name": "stdout",
642      "output_type": "stream",
643      "text": [
644       "14811"
645      ]
646     }
647    ],
648    "source": [
649     "clear 14811"
650    ]
651   },
652   {
653    "cell_type": "code",
654    "execution_count": 29,
655    "id": "97615452",
656    "metadata": {},
657    "outputs": [
658     {
659      "name": "stdout",
660      "output_type": "stream",
661      "text": [
662       "3 3702"
663      ]
664     }
665    ],
666    "source": [
667     "[3 &] [2 >>] cleave"
668    ]
669   },
670   {
671    "cell_type": "code",
672    "execution_count": 30,
673    "id": "3acbda7d",
674    "metadata": {},
675    "outputs": [
676     {
677      "name": "stdout",
678      "output_type": "stream",
679      "text": [
680       "3 2 925"
681      ]
682     }
683    ],
684    "source": [
685     "[3 &] [2 >>] cleave"
686    ]
687   },
688   {
689    "cell_type": "code",
690    "execution_count": 31,
691    "id": "dcffaa52",
692    "metadata": {},
693    "outputs": [
694     {
695      "name": "stdout",
696      "output_type": "stream",
697      "text": [
698       "3 2 1 231"
699      ]
700     }
701    ],
702    "source": [
703     "[3 &] [2 >>] cleave"
704    ]
705   },
706   {
707    "cell_type": "code",
708    "execution_count": 32,
709    "id": "39cb9487",
710    "metadata": {},
711    "outputs": [
712     {
713      "name": "stdout",
714      "output_type": "stream",
715      "text": [
716       "3 2 1 3 57"
717      ]
718     }
719    ],
720    "source": [
721     "[3 &] [2 >>] cleave"
722    ]
723   },
724   {
725    "cell_type": "code",
726    "execution_count": 33,
727    "id": "95924445",
728    "metadata": {},
729    "outputs": [
730     {
731      "name": "stdout",
732      "output_type": "stream",
733      "text": [
734       "3 2 1 3 1 14"
735      ]
736     }
737    ],
738    "source": [
739     "[3 &] [2 >>] cleave"
740    ]
741   },
742   {
743    "cell_type": "code",
744    "execution_count": 34,
745    "id": "c5334a6e",
746    "metadata": {},
747    "outputs": [
748     {
749      "name": "stdout",
750      "output_type": "stream",
751      "text": [
752       "3 2 1 3 1 2 3"
753      ]
754     }
755    ],
756    "source": [
757     "[3 &] [2 >>] cleave"
758    ]
759   },
760   {
761    "cell_type": "code",
762    "execution_count": 35,
763    "id": "72f6bce6",
764    "metadata": {},
765    "outputs": [
766     {
767      "name": "stdout",
768      "output_type": "stream",
769      "text": [
770       "3 2 1 3 1 2 3 0"
771      ]
772     }
773    ],
774    "source": [
775     "[3 &] [2 >>] cleave"
776    ]
777   },
778   {
779    "cell_type": "code",
780    "execution_count": 36,
781    "id": "feeeac23",
782    "metadata": {},
783    "outputs": [
784     {
785      "name": "stdout",
786      "output_type": "stream",
787      "text": [
788       "3 2 1 3 1 2 3 0 0"
789      ]
790     }
791    ],
792    "source": [
793     "[3 &] [2 >>] cleave"
794    ]
795   },
796   {
797    "cell_type": "code",
798    "execution_count": 37,
799    "id": "fb419282",
800    "metadata": {},
801    "outputs": [
802     {
803      "name": "stdout",
804      "output_type": "stream",
805      "text": [
806       "3 2 1 3 1 2 3 0 0 0"
807      ]
808     }
809    ],
810    "source": [
811     "[3 &] [2 >>] cleave"
812    ]
813   },
814   {
815    "cell_type": "markdown",
816    "id": "0e2956c9",
817    "metadata": {},
818    "source": [
819     "We can run it in a `loop`..."
820    ]
821   },
822   {
823    "cell_type": "code",
824    "execution_count": 38,
825    "id": "5e637fc3",
826    "metadata": {},
827    "outputs": [
828     {
829      "name": "stdout",
830      "output_type": "stream",
831      "text": [
832       "14811"
833      ]
834     }
835    ],
836    "source": [
837     "clear 14811"
838    ]
839   },
840   {
841    "cell_type": "code",
842    "execution_count": 39,
843    "id": "335e0432",
844    "metadata": {},
845    "outputs": [
846     {
847      "name": "stdout",
848      "output_type": "stream",
849      "text": [
850       "3 2 1 3 1 2 3"
851      ]
852     }
853    ],
854    "source": [
855     "? [[3 &] [2 >>] cleave ?] loop pop"
856    ]
857   },
858   {
859    "cell_type": "markdown",
860    "id": "4160f1aa",
861    "metadata": {},
862    "source": [
863     "?"
864    ]
865   },
866   {
867    "cell_type": "code",
868    "execution_count": 40,
869    "id": "6f3ed92b",
870    "metadata": {},
871    "outputs": [
872     {
873      "name": "stdout",
874      "output_type": "stream",
875      "text": [
876       "0 0 14811"
877      ]
878     }
879    ],
880    "source": [
881     "clear 0 0 14811"
882    ]
883   },
884   {
885    "cell_type": "code",
886    "execution_count": 41,
887    "id": "eb742eef",
888    "metadata": {},
889    "outputs": [
890     {
891      "name": "stdout",
892      "output_type": "stream",
893      "text": [
894       "0 0 3 3702"
895      ]
896     }
897    ],
898    "source": [
899     "[3 &] [2 >>] cleave"
900    ]
901   },
902   {
903    "cell_type": "code",
904    "execution_count": 42,
905    "id": "8b935622",
906    "metadata": {},
907    "outputs": [
908     {
909      "name": "stdout",
910      "output_type": "stream",
911      "text": [
912       "3 3 3702"
913      ]
914     }
915    ],
916    "source": [
917     "[+ [+] dupdip] dip"
918    ]
919   },
920   {
921    "cell_type": "code",
922    "execution_count": 43,
923    "id": "68904907",
924    "metadata": {},
925    "outputs": [
926     {
927      "name": "stdout",
928      "output_type": "stream",
929      "text": [
930       "3 3 2 925"
931      ]
932     }
933    ],
934    "source": [
935     "[3 &] [2 >>] cleave"
936    ]
937   },
938   {
939    "cell_type": "code",
940    "execution_count": 44,
941    "id": "dd0ed2f5",
942    "metadata": {},
943    "outputs": [
944     {
945      "name": "stdout",
946      "output_type": "stream",
947      "text": [
948       "8 5 925"
949      ]
950     }
951    ],
952    "source": [
953     "[+ [+] dupdip] dip"
954    ]
955   },
956   {
957    "cell_type": "code",
958    "execution_count": 45,
959    "id": "d110d282",
960    "metadata": {},
961    "outputs": [
962     {
963      "name": "stdout",
964      "output_type": "stream",
965      "text": [
966       "14 6 231"
967      ]
968     }
969    ],
970    "source": [
971     "[3 &] [2 >>] cleave [+ [+] dupdip] dip"
972    ]
973   },
974   {
975    "cell_type": "code",
976    "execution_count": 46,
977    "id": "a29055bb",
978    "metadata": {},
979    "outputs": [
980     {
981      "name": "stdout",
982      "output_type": "stream",
983      "text": [
984       "23 9 57"
985      ]
986     }
987    ],
988    "source": [
989     "[3 &] [2 >>] cleave [+ [+] dupdip] dip"
990    ]
991   },
992   {
993    "cell_type": "code",
994    "execution_count": 47,
995    "id": "ad0897e8",
996    "metadata": {},
997    "outputs": [
998     {
999      "name": "stdout",
1000      "output_type": "stream",
1001      "text": [
1002       "33 10 14"
1003      ]
1004     }
1005    ],
1006    "source": [
1007     "[3 &] [2 >>] cleave [+ [+] dupdip] dip"
1008    ]
1009   },
1010   {
1011    "cell_type": "code",
1012    "execution_count": 48,
1013    "id": "5434a3c8",
1014    "metadata": {},
1015    "outputs": [
1016     {
1017      "name": "stdout",
1018      "output_type": "stream",
1019      "text": [
1020       "45 12 3"
1021      ]
1022     }
1023    ],
1024    "source": [
1025     "[3 &] [2 >>] cleave [+ [+] dupdip] dip"
1026    ]
1027   },
1028   {
1029    "cell_type": "code",
1030    "execution_count": 49,
1031    "id": "55e94d15",
1032    "metadata": {},
1033    "outputs": [
1034     {
1035      "name": "stdout",
1036      "output_type": "stream",
1037      "text": [
1038       "60 15 0"
1039      ]
1040     }
1041    ],
1042    "source": [
1043     "[3 &] [2 >>] cleave [+ [+] dupdip] dip"
1044    ]
1045   },
1046   {
1047    "cell_type": "code",
1048    "execution_count": null,
1049    "id": "d7daba3f",
1050    "metadata": {},
1051    "outputs": [],
1052    "source": []
1053   },
1054   {
1055    "cell_type": "code",
1056    "execution_count": 50,
1057    "id": "31f009b5",
1058    "metadata": {},
1059    "outputs": [
1060     {
1061      "name": "stdout",
1062      "output_type": "stream",
1063      "text": [
1064       "0 0"
1065      ]
1066     }
1067    ],
1068    "source": [
1069     "clear 0 0"
1070    ]
1071   },
1072   {
1073    "cell_type": "code",
1074    "execution_count": 51,
1075    "id": "ffec3de6",
1076    "metadata": {},
1077    "outputs": [
1078     {
1079      "name": "stdout",
1080      "output_type": "stream",
1081      "text": [
1082       "60 15"
1083      ]
1084     }
1085    ],
1086    "source": [
1087     "14811 7 [[3 &] [2 >>] cleave [+ [+] dupdip] dip] times pop"
1088    ]
1089   },
1090   {
1091    "cell_type": "code",
1092    "execution_count": 52,
1093    "id": "ac639fe0",
1094    "metadata": {},
1095    "outputs": [
1096     {
1097      "name": "stdout",
1098      "output_type": "stream",
1099      "text": [
1100       "225 30"
1101      ]
1102     }
1103    ],
1104    "source": [
1105     "14811 7 [[3 &] [2 >>] cleave [+ [+] dupdip] dip] times pop"
1106    ]
1107   },
1108   {
1109    "cell_type": "code",
1110    "execution_count": null,
1111    "id": "885bf996",
1112    "metadata": {},
1113    "outputs": [],
1114    "source": []
1115   },
1116   {
1117    "cell_type": "code",
1118    "execution_count": 53,
1119    "id": "e72ab115",
1120    "metadata": {},
1121    "outputs": [
1122     {
1123      "name": "stdout",
1124      "output_type": "stream",
1125      "text": [
1126       "0 0"
1127      ]
1128     }
1129    ],
1130    "source": [
1131     "clear 0 0"
1132    ]
1133   },
1134   {
1135    "cell_type": "code",
1136    "execution_count": 54,
1137    "id": "6c44ab00",
1138    "metadata": {},
1139    "outputs": [
1140     {
1141      "name": "stdout",
1142      "output_type": "stream",
1143      "text": [
1144       "229185 990"
1145      ]
1146     }
1147    ],
1148    "source": [
1149     "66 [14811 7 [[3 &] [2 >>] cleave [+ [+] dupdip] dip] times pop] times"
1150    ]
1151   },
1152   {
1153    "cell_type": "code",
1154    "execution_count": 55,
1155    "id": "7f4c4931",
1156    "metadata": {},
1157    "outputs": [
1158     {
1159      "name": "stdout",
1160      "output_type": "stream",
1161      "text": [
1162       "233168 999"
1163      ]
1164     }
1165    ],
1166    "source": [
1167     "14811 4 [[3 &] [2 >>] cleave [+ [+] dupdip] dip] times pop"
1168    ]
1169   },
1170   {
1171    "cell_type": "code",
1172    "execution_count": 56,
1173    "id": "25dc0fd8",
1174    "metadata": {},
1175    "outputs": [
1176     {
1177      "name": "stdout",
1178      "output_type": "stream",
1179      "text": [
1180       "233168"
1181      ]
1182     }
1183    ],
1184    "source": [
1185     "pop"
1186    ]
1187   },
1188   {
1189    "cell_type": "code",
1190    "execution_count": null,
1191    "id": "02228693",
1192    "metadata": {},
1193    "outputs": [],
1194    "source": []
1195   },
1196   {
1197    "cell_type": "code",
1198    "execution_count": 57,
1199    "id": "4bd5cd29",
1200    "metadata": {},
1201    "outputs": [
1202     {
1203      "name": "stdout",
1204      "output_type": "stream",
1205      "text": [
1206       "[0 swap [dup [pop 14811] [] branch [3 &] [2 >>] cleave] dip rest cons]"
1207      ]
1208     }
1209    ],
1210    "source": [
1211     "clear\n",
1212     "[0 swap [dup [pop 14811] [] branch [3 &] [2 >>] cleave] dip rest cons]"
1213    ]
1214   },
1215   {
1216    "cell_type": "code",
1217    "execution_count": 58,
1218    "id": "537162b4",
1219    "metadata": {},
1220    "outputs": [
1221     {
1222      "name": "stdout",
1223      "output_type": "stream",
1224      "text": [
1225       "3 [3702 swap [dup [pop 14811] [] branch [3 &] [2 >>] cleave] dip rest cons]"
1226      ]
1227     }
1228    ],
1229    "source": [
1230     "x"
1231    ]
1232   },
1233   {
1234    "cell_type": "code",
1235    "execution_count": 59,
1236    "id": "051a539b",
1237    "metadata": {},
1238    "outputs": [
1239     {
1240      "name": "stdout",
1241      "output_type": "stream",
1242      "text": [
1243       "3 2 1 3 1 2 3"
1244      ]
1245     }
1246    ],
1247    "source": [
1248     "x x x x x x pop"
1249    ]
1250   },
1251   {
1252    "cell_type": "code",
1253    "execution_count": 60,
1254    "id": "b37462f1",
1255    "metadata": {},
1256    "outputs": [
1257     {
1258      "name": "stdout",
1259      "output_type": "stream",
1260      "text": [
1261       "466"
1262      ]
1263     }
1264    ],
1265    "source": [
1266     "clear\n",
1267     "7 66 * 4 +"
1268    ]
1269   },
1270   {
1271    "cell_type": "code",
1272    "execution_count": 61,
1273    "id": "d5fc7e8f",
1274    "metadata": {},
1275    "outputs": [
1276     {
1277      "name": "stdout",
1278      "output_type": "stream",
1279      "text": []
1280     }
1281    ],
1282    "source": [
1283     "clear"
1284    ]
1285   },
1286   {
1287    "cell_type": "code",
1288    "execution_count": null,
1289    "id": "f4719ad5",
1290    "metadata": {},
1291    "outputs": [],
1292    "source": []
1293   },
1294   {
1295    "cell_type": "code",
1296    "execution_count": 62,
1297    "id": "0c68ecd4",
1298    "metadata": {},
1299    "outputs": [
1300     {
1301      "name": "stdout",
1302      "output_type": "stream",
1303      "text": [
1304       "[0 swap [dup [pop 14811] [] branch [3 &] [2 >>] cleave] dip rest cons]"
1305      ]
1306     }
1307    ],
1308    "source": [
1309     "clear\n",
1310     "[0 swap [dup [pop 14811] [] branch [3 &] [2 >>] cleave] dip rest cons]"
1311    ]
1312   },
1313   {
1314    "cell_type": "code",
1315    "execution_count": 63,
1316    "id": "c9d44724",
1317    "metadata": {},
1318    "outputs": [
1319     {
1320      "name": "stdout",
1321      "output_type": "stream",
1322      "text": [
1323       "3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3"
1324      ]
1325     }
1326    ],
1327    "source": [
1328     "466 [x] times pop"
1329    ]
1330   },
1331   {
1332    "cell_type": "code",
1333    "execution_count": 64,
1334    "id": "f38a9ba9",
1335    "metadata": {},
1336    "outputs": [
1337     {
1338      "name": "stdout",
1339      "output_type": "stream",
1340      "text": [
1341       "999"
1342      ]
1343     }
1344    ],
1345    "source": [
1346     "enstacken sum"
1347    ]
1348   },
1349   {
1350    "cell_type": "code",
1351    "execution_count": null,
1352    "id": "4d66d76f",
1353    "metadata": {},
1354    "outputs": [],
1355    "source": []
1356   },
1357   {
1358    "cell_type": "code",
1359    "execution_count": 65,
1360    "id": "4929fa6b",
1361    "metadata": {},
1362    "outputs": [
1363     {
1364      "name": "stdout",
1365      "output_type": "stream",
1366      "text": [
1367       "0 0 [0 swap [dup [pop 14811] [] branch [3 &] [2 >>] cleave] dip rest cons]"
1368      ]
1369     }
1370    ],
1371    "source": [
1372     "clear 0 0\n",
1373     "[0 swap [dup [pop 14811] [] branch [3 &] [2 >>] cleave] dip rest cons]"
1374    ]
1375   },
1376   {
1377    "cell_type": "code",
1378    "execution_count": 66,
1379    "id": "c57bf8a2",
1380    "metadata": {},
1381    "outputs": [
1382     {
1383      "name": "stdout",
1384      "output_type": "stream",
1385      "text": [
1386       "233168"
1387      ]
1388     }
1389    ],
1390    "source": [
1391     "466 [x [+ [+] dupdip] dip] times popop"
1392    ]
1393   },
1394   {
1395    "cell_type": "code",
1396    "execution_count": null,
1397    "id": "61a83de1",
1398    "metadata": {},
1399    "outputs": [],
1400    "source": []
1401   }
1402  ],
1403  "metadata": {
1404   "kernelspec": {
1405    "display_name": "Joypy",
1406    "language": "",
1407    "name": "thun"
1408   },
1409   "language_info": {
1410    "file_extension": ".joy",
1411    "mimetype": "text/plain",
1412    "name": "Joy"
1413   }
1414  },
1415  "nbformat": 4,
1416  "nbformat_minor": 5
1417 }