Skip to content

Commit 2625edb

Browse files
committed
update ABC
1 parent 5aebc8c commit 2625edb

1 file changed

Lines changed: 119 additions & 34 deletions

File tree

notebooks/ABC.ipynb

Lines changed: 119 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,7 @@
601601
},
602602
{
603603
"cell_type": "code",
604-
"execution_count": null,
604+
"execution_count": 2,
605605
"id": "24ae95be",
606606
"metadata": {},
607607
"outputs": [],
@@ -624,28 +624,50 @@
624624
},
625625
{
626626
"cell_type": "code",
627-
"execution_count": null,
627+
"execution_count": 3,
628628
"id": "3f9f0595",
629629
"metadata": {},
630-
"outputs": [],
630+
"outputs": [
631+
{
632+
"data": {
633+
"text/plain": [
634+
"frozenset({'roll'})"
635+
]
636+
},
637+
"execution_count": 3,
638+
"metadata": {},
639+
"output_type": "execute_result"
640+
}
641+
],
631642
"source": [
632643
"Die.__abstractmethods__"
633644
]
634645
},
635646
{
636647
"cell_type": "code",
637-
"execution_count": null,
648+
"execution_count": 4,
638649
"id": "9ee9b370",
639650
"metadata": {},
640-
"outputs": [],
651+
"outputs": [
652+
{
653+
"data": {
654+
"text/plain": [
655+
"True"
656+
]
657+
},
658+
"execution_count": 4,
659+
"metadata": {},
660+
"output_type": "execute_result"
661+
}
662+
],
641663
"source": [
642664
"# can also check if a method is abstract method\n",
643665
"Die.roll.__isabstractmethod__"
644666
]
645667
},
646668
{
647669
"cell_type": "code",
648-
"execution_count": null,
670+
"execution_count": 5,
649671
"id": "a563237f",
650672
"metadata": {},
651673
"outputs": [],
@@ -664,7 +686,7 @@
664686
},
665687
{
666688
"cell_type": "code",
667-
"execution_count": null,
689+
"execution_count": 6,
668690
"id": "efdf18a0",
669691
"metadata": {},
670692
"outputs": [],
@@ -684,7 +706,7 @@
684706
},
685707
{
686708
"cell_type": "code",
687-
"execution_count": null,
709+
"execution_count": 7,
688710
"id": "be8d1c4c",
689711
"metadata": {},
690712
"outputs": [],
@@ -698,7 +720,7 @@
698720
},
699721
{
700722
"cell_type": "code",
701-
"execution_count": null,
723+
"execution_count": 8,
702724
"id": "5a84300d",
703725
"metadata": {},
704726
"outputs": [],
@@ -708,7 +730,7 @@
708730
},
709731
{
710732
"cell_type": "code",
711-
"execution_count": null,
733+
"execution_count": 9,
712734
"id": "c96244be",
713735
"metadata": {},
714736
"outputs": [],
@@ -719,10 +741,21 @@
719741
},
720742
{
721743
"cell_type": "code",
722-
"execution_count": null,
744+
"execution_count": 10,
723745
"id": "66039237",
724746
"metadata": {},
725-
"outputs": [],
747+
"outputs": [
748+
{
749+
"data": {
750+
"text/plain": [
751+
"14"
752+
]
753+
},
754+
"execution_count": 10,
755+
"metadata": {},
756+
"output_type": "execute_result"
757+
}
758+
],
726759
"source": [
727760
"sd.total"
728761
]
@@ -755,11 +788,13 @@
755788
"class YachtDice(Dice):\n",
756789
" def __init__(self) -> None:\n",
757790
" super().__init__(5, D6)\n",
791+
" # keep track of saved dice positions; these dice are not rolled\n",
758792
" self.saved: Set[int] = set()\n",
759793
" \n",
760794
" # save dice positions in the saved set\n",
795+
" # save dice positions are not rolled\n",
761796
" def saving(self, positions: Iterable[int]) -> \"YactDice\":\n",
762-
" if not all(0 <= n < 6 for n in positions):\n",
797+
" if not all(0 <= n < 5 for n in positions):\n",
763798
" raise ValueError(\"Invalid position\")\n",
764799
" self.saved = set(positions)\n",
765800
" return self\n",
@@ -774,17 +809,28 @@
774809
},
775810
{
776811
"cell_type": "code",
777-
"execution_count": null,
812+
"execution_count": 12,
778813
"id": "928a03b4",
779814
"metadata": {},
780-
"outputs": [],
815+
"outputs": [
816+
{
817+
"data": {
818+
"text/plain": [
819+
"frozenset()"
820+
]
821+
},
822+
"execution_count": 12,
823+
"metadata": {},
824+
"output_type": "execute_result"
825+
}
826+
],
781827
"source": [
782828
"YachtDice.__abstractmethods__"
783829
]
784830
},
785831
{
786832
"cell_type": "code",
787-
"execution_count": null,
833+
"execution_count": 13,
788834
"id": "294f3571",
789835
"metadata": {},
790836
"outputs": [],
@@ -794,7 +840,7 @@
794840
},
795841
{
796842
"cell_type": "code",
797-
"execution_count": null,
843+
"execution_count": 14,
798844
"id": "be908eed",
799845
"metadata": {},
800846
"outputs": [],
@@ -804,17 +850,28 @@
804850
},
805851
{
806852
"cell_type": "code",
807-
"execution_count": null,
853+
"execution_count": 15,
808854
"id": "70ae5f89",
809855
"metadata": {},
810-
"outputs": [],
856+
"outputs": [
857+
{
858+
"data": {
859+
"text/plain": [
860+
"[5, 2, 5, 4, 2]"
861+
]
862+
},
863+
"execution_count": 15,
864+
"metadata": {},
865+
"output_type": "execute_result"
866+
}
867+
],
811868
"source": [
812869
"yd.dice"
813870
]
814871
},
815872
{
816873
"cell_type": "code",
817-
"execution_count": null,
874+
"execution_count": 16,
818875
"id": "bbce1428",
819876
"metadata": {},
820877
"outputs": [],
@@ -824,17 +881,28 @@
824881
},
825882
{
826883
"cell_type": "code",
827-
"execution_count": null,
884+
"execution_count": 17,
828885
"id": "7101639e",
829886
"metadata": {},
830-
"outputs": [],
887+
"outputs": [
888+
{
889+
"data": {
890+
"text/plain": [
891+
"[5, 5, 1, 4, 2]"
892+
]
893+
},
894+
"execution_count": 17,
895+
"metadata": {},
896+
"output_type": "execute_result"
897+
}
898+
],
831899
"source": [
832900
"yd.dice"
833901
]
834902
},
835903
{
836904
"cell_type": "code",
837-
"execution_count": null,
905+
"execution_count": 18,
838906
"id": "733f13c2",
839907
"metadata": {},
840908
"outputs": [],
@@ -844,20 +912,42 @@
844912
},
845913
{
846914
"cell_type": "code",
847-
"execution_count": null,
915+
"execution_count": 19,
848916
"id": "300b2bc4",
849917
"metadata": {},
850-
"outputs": [],
918+
"outputs": [
919+
{
920+
"data": {
921+
"text/plain": [
922+
"[5, 5, 1, 3, 2]"
923+
]
924+
},
925+
"execution_count": 19,
926+
"metadata": {},
927+
"output_type": "execute_result"
928+
}
929+
],
851930
"source": [
852931
"yd.dice"
853932
]
854933
},
855934
{
856935
"cell_type": "code",
857-
"execution_count": null,
936+
"execution_count": 20,
858937
"id": "ac973bc5",
859938
"metadata": {},
860-
"outputs": [],
939+
"outputs": [
940+
{
941+
"data": {
942+
"text/plain": [
943+
"16"
944+
]
945+
},
946+
"execution_count": 20,
947+
"metadata": {},
948+
"output_type": "execute_result"
949+
}
950+
],
861951
"source": [
862952
"yd.total"
863953
]
@@ -1090,7 +1180,7 @@
10901180
],
10911181
"metadata": {
10921182
"kernelspec": {
1093-
"display_name": "Python 3 (ipykernel)",
1183+
"display_name": "Python 3",
10941184
"language": "python",
10951185
"name": "python3"
10961186
},
@@ -1104,12 +1194,7 @@
11041194
"name": "python",
11051195
"nbconvert_exporter": "python",
11061196
"pygments_lexer": "ipython3",
1107-
"version": "3.10.8"
1108-
},
1109-
"vscode": {
1110-
"interpreter": {
1111-
"hash": "1a1af0ee75eeea9e2e1ee996c87e7a2b11a0bebd85af04bb136d915cefc0abce"
1112-
}
1197+
"version": "3.9.6"
11131198
}
11141199
},
11151200
"nbformat": 4,

0 commit comments

Comments
 (0)