-
Notifications
You must be signed in to change notification settings - Fork 0
/
cpu.yuk
executable file
·63 lines (52 loc) · 1.46 KB
/
cpu.yuk
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/awful
:set ®ister :dict
:set &highest-ever i0
!fun :check-condition $reg $op $val
# Referring an un-set key will yield NIL.
# This will either left the register value unchanged,
# or set it to 0, if it wasn't yet set.
:set ®-val :mkint ®ister[®]
:writeln s':check-condition: ' $reg s', ' $op s', ' $val s'; ' $reg-val
!if :eq &op s'=='
:return :eq ®-val &val
!elif :eq &op s'!='
:return :neq ®-val &val
!elif :eq &op s'<='
:return :le ®-val &val
!elif :eq &op s'>='
:return :ge ®-val &val
!elif :eq &op s'<'
:return :lt ®-val &val
!elif :eq &op s'>'
:return :gt ®-val &val
!else
:writeln s':check-condition: watafuq? op: ' $op
:exit
!fi
!nuf
!fun :change-register $reg $op $val
# The same dirty trick as in the :check-condition function.
:mkint ®ister[®]
:writeln s':change-register: ' $reg s', ' $op s', ' $val s'; ' $register[$reg]
!if :eq $op s'inc'
:add ®ister[®] &val
!elif :eq $op s'dec'
:sub ®ister[®] &val
!else
:writeln s':change-register: watafuq? op: ' $op
:exit
!fi
!if :gt ®ister[®] &highest-ever
:set &highest-ever ®ister[®]
!fi
!nuf
:set &line s''
!while :not :stdin-eof
:readln &line
:set &parts :str-explode $line s' '
!if :check-condition $parts[i4] $parts[i5] $parts[i6]
:change-register $parts[i0] $parts[i1] $parts[i2]
!fi
!done
:writeln s'highest now: ' :arr-max :dict-values ®ister
:writeln s'highest ever: ' &highest-ever