GPT로 코드짰는데 평가좀 해주셈
triva(zomi12)
2024-02-03 21:22
추천 0
import random
import time
import threading
class NAND:
def __init__(self, name):
self.name = name
self.inputs = [None, None]
self.output = None
def connect(self, other):
available_inputs = [i for i, x in enumerate(self.inputs) if x is None]
if available_inputs:
self.inputs[random.choice(available_inputs)] = other
other.output = self
self.update_output()
def disconnect(self):
if self.inputs[0] is not None:
self.inputs[0].output = None
if self.inputs[1] is not None:
self.inputs[1].output = None
self.inputs = [None, None]
def update_output(self):
if all([i is not None for i in self.inputs]):
self.output = 0 if all([i.output == 1 for i in self.inputs]) else 1
def random_operation(gates, freq, input_freq):
while True:
for _ in range(freq):
gate1 = random.choice(gates)
gate2 = random.choice(gates)
if gate1 is not gate2 and random.choice([True, False]):
gate1.connect(gate2)
else:
gate1.disconnect()
for _ in range(input_freq):
gate = random.choice(gates)
if gate.inputs[0] is None:
gate.inputs[0] = random.choice([0, 1])
if gate.inputs[1] is None:
gate.inputs[1] = random.choice([0, 1])
gate.update_output()
time.sleep(1)
def main():
n_gates = int(input("Enter the number of NAND gates: "))
freq = int(input("Enter the frequency of random connections/disconnections per second: "))
input_freq = int(input("Enter the frequency of random inputs per second: "))
gates = [NAND(i) for i in range(n_gates)]
game_thread = threading.Thread(target=random_operation, args=(gates, freq, input_freq))
game_thread.start()
print("Game started. Type 'stop' to stop the game.")
while True:
command = input()
if command.lower() == 'stop':
game_thread.join()
print("Game stopped.")
break
if __name__ == "__main__":
main()
NAND게이트는 만능게이트니까 모든논리를 만들수 있잖음
그래서 그 NAND게이트를 일정시간동안 수정가능한 빈도로 랜덤하게 연결, 연결제거를 수행해서
랜덤한 논리를 나타나게함
그리고 NAND게이트중에 아무 입력도 연결되어있지않은 NAND게이트의 입력을 랜덤으로 바꾸는데, 그 바꾸는것의 빈도도 조절할수있음
이렇게 해서 얻고자 하는게 무엇이냐면
랜덤한 논리를 만들고, 상호작용시켜서, 적자생존이 일어나고
그 적자생존에서 뭔가가 탄생하기를 바라는것임
재밌는 생각이긴 한데 단순 랜덤 연결이 적자생존을 구현했는지에 대해서는 생각해볼 필요가 있지 않을까.
랜덤한 논리가 예를들어 (A->not B) 라면 이 논리는 B를 죽이는 논리가 될수 있다고 생각함 그러니까 죽고 죽일수 있다면 적자생존이 나타난다고 생각함
그리고 낸드는 당연히 알겠지만 불 대수를 표현하기 위해서 단위 논리회로가 필요함. 거기 부터가 단위 논리 구성 요소임.
나 컴공하나도 모름.. 쉽게 말해주셈
https://en.wikipedia.org/wiki/NAND_logic
불 대수 -> 클로드 섀넌이 디지털 논리회로로 물리설계 만듦 -> 각각의 부울 논리를 NAND로 치환해서 표현
그리고 그 NAND는 트랜지스터로 만듦. 여기서부터는 전자공학의 영역임.
더 내려가면 반도체 더 내려가면 solid state physics 더 내려가면 전자기학, 양자역학 ㄹㅇ
저기 나온 트랜지스터로 만들어진 낸드 칩으로 만든 게 집적회로임. ASIC 은 미리 설계 돼서 나온 거고, FPGA 같은 건 HDL로 회로 그릴 수 있음. CPU나 레지스터 뱅크, CU ALU 이런 거부터 ISA 자기가 정의해서 만들 수 있음. 요즘 올라온 거 보니까 뭔가 투자할 때 쓰는 모양이더라 ㄹㅇ.. 최적화 때문인가
저거 실제로 회로로 그려 놓으면 propagation delay 줄이고 하는 뭐 그런 최적화 작업도 잇음. 예전에 배워서 거의 다 까먹엇다.