Spaces:
Sleeping
Sleeping
File size: 1,231 Bytes
e3af2b1 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# μλ λμμλ κ·μΉμ νλ‘λ‘ λ§λ ν¨μ μμμλ§ μ μ©
# νμ©λ ν¨μ: return, μ¬μ©μκ° μ μν ν¨μ
# νμ©λ μ°μ°μ(λ κ°μ μ°μ°μΌλ‘ μ¬μ©λ λ): !, &, |, ^, =
# νμ©λ μλ£ν: bool, tuple
def main() -> None:
from functools import wraps
# κΈ°λ³Έ ν¨μ (νλ‘ λ°μμλ§)
def circuit(func): # decorator function
@wraps(func)
def wrapper(*args): # wrapper function
return func(*args)
return wrapper
def BoolToStr(bools: tuple[bool]):
retstr = ''
for i in range(len(bools)):
if bools[i]:
retstr += '1'
else:
retstr += '0'
return retstr
# νλ‘ λ§λ€κΈ°
@circuit
def Add1Dgt(in1: bool, in2: bool) -> tuple:
firstdgt: bool = in1 ^ in2
seconddgt: bool = in1 & in2
return (seconddgt, firstdgt)
def Add2dgt(in1: bool, in2: bool) -> tuple:
# ν
μ€νΈ
print(BoolToStr(Add1Dgt(1, 1)))
print(BoolToStr(Add1Dgt(1, 0)))
print(BoolToStr(Add1Dgt(0, 1)))
print(BoolToStr(Add1Dgt(0, 0)))
if __name__ == '__main__':
main() |