diff options
author | Anthony Wang | 2023-11-09 16:22:29 -0500 |
---|---|---|
committer | Anthony Wang | 2023-11-09 16:22:29 -0500 |
commit | d6f7ab88dc4a5a919a831d4ad6d99f7617a163d0 (patch) | |
tree | 342a0a0498323baeb9470afe7b9975ddaff96357 /main.py | |
parent | 07f67815ef01231e16c6f444ed57c77dc972603d (diff) |
Diffstat (limited to 'main.py')
-rw-r--r-- | main.py | 41 |
1 files changed, 41 insertions, 0 deletions
@@ -0,0 +1,41 @@ +import random +import threading +import time +import sys + +mem = {} +threads = [] + +def thread(a, b, c, d): + def f(): + # print(a, b, c, d) + try: + match a: + case 'set': + try: + mem[b] = int(c) + except: + mem[b] = c + case 'print': + print(mem[c]) + case 'add': + mem[b] += mem[c] + case 'sub': + mem[b] -= mem[c] + case 'mul': + mem[b] *= mem[c] + case 'div': + mem[b] /= mem[c] + if mem[b] > 0 and int(d) > 0: + time.sleep(0.001) + threads[int(d) - 1]() + except: + return + return f + +with open(sys.argv[1]) as f: + for line in f.readlines(): + threads.append(thread(*line.split())) + +for thread in sorted(threads, key=lambda _: random.random()): + threading.Thread(target=thread).start() |