Test / CircuitProject.py
Drbrain0620's picture
Upload folder using huggingface_hub
e3af2b1 verified
# μ•„λž˜ λ‚˜μ™€μžˆλŠ” κ·œμΉ™μ€ 회둜둜 λ§Œλ“  ν•¨μˆ˜ μ•ˆμ—μ„œλ§Œ 적용
# ν—ˆμš©λœ ν•¨μˆ˜: 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()