aboutsummaryrefslogtreecommitdiff
path: root/main.py
blob: d571bacc3a7b11eb3fcc6a57d70e3b349098e714 (plain)
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
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()