Last active
June 2, 2021 09:34
-
-
Save dboyliao/cfb7b993780cd8ec5a9cab8daacbf44e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Just for fun: https://www.facebook.com/groups/706762492694458/permalink/4414710665232937/ | |
""" | |
import numpy as np | |
class Word: | |
__map = { | |
("金", "金"): "鍂", | |
("金", "木"): "鈢", | |
("金", "火"): "鈥", | |
("金", "水"): "淦", | |
("金", "土"): "釷", | |
("木", "金"): "鈢", | |
("木", "木"): "林", | |
("木", "火"): "炑", | |
("木", "水"): "沐", | |
("木", "土"): "杜", | |
("水", "金"): "淦", | |
("水", "木"): "沐", | |
("水", "火"): "淡", | |
("水", "水"): "沝", | |
("水", "土"): "汢", | |
("火", "金"): "鈥", | |
("火", "木"): "炑", | |
("火", "火"): "炎", | |
("火", "水"): "淡", | |
("火", "土"): "灶", | |
("土", "金"): "釷", | |
("土", "木"): "杜", | |
("土", "火"): "灶", | |
("土", "水"): "汢", | |
("土", "土"): "圭", | |
} | |
def __init__(self, word=""): | |
self._word = word | |
def __add__(self, other): | |
cls = type(self) | |
if isinstance(other, cls): | |
word = " ".join(sorted([self._word, other._word])) | |
return cls(word) | |
return NotImplemented | |
def __mul__(self, other): | |
cls = type(self) | |
if isinstance(other, cls): | |
word = cls.__map.get( | |
(self._word, other._word), "".join(sorted([self._word, other._word])) | |
) | |
return cls(word) | |
return NotImplemented | |
def __repr__(self): | |
return self._word | |
@classmethod | |
def add_mul_map(cls, words, new_word): | |
cls.__map[tuple(words)] = new_word | |
cls.__map[tuple(words[::-1])] = new_word | |
v = np.array([Word("金"), Word("木"), Word("水"), Word("火"), Word("土")])[:, np.newaxis] | |
print(v.dot(v.T)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment