-
Notifications
You must be signed in to change notification settings - Fork 0
/
year28-fast.hrm
105 lines (94 loc) · 1.68 KB
/
year28-fast.hrm
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
-- HUMAN RESOURCE MACHINE PROGRAM --
-- 28: Three Sort
-- INSTRUCTIONS: "For each THREE THINGS in the INBOX, send them to the
-- OUTBOX in order from smallest to largest."
-- AVAILABLE COMMANDS: INBOX, OUTBOX, COPYFROM, COPYTO, ADD, SUB,
-- BUMPUP, BUMPDN, JUMP, JUMPZ, JUMPN, COMMENT
-- SIZE: 58 commands (challenge 34)
-- AVERAGE RUNTIME: 78 steps (challenge 78)
-- Tile 0: First item in each set of three
-- Tile 1: Second item in each set of three
-- Tile 2: Third item in each set of three
-- Place the items on the floor immediately, compare them to each other
-- to determine total ordering, and pick them up in order to place in
-- the outbox.
a:
b:
c:
d:
e:
f:
-- Copy the three items to tiles 0, 1, and 2 in the order they come out
-- of the inbox.
INBOX
COPYTO 0
INBOX
COPYTO 1
INBOX
COPYTO 2
SUB 1
JUMPN i
COPYFROM 1
SUB 0
JUMPN g
-- 0 <= 1 <= 2
COPYFROM 0
OUTBOX
COPYFROM 1
OUTBOX
COPYFROM 2
OUTBOX
JUMP f
g:
-- 1 is smallest
COPYFROM 1
OUTBOX
COPYFROM 0
SUB 2
JUMPN h
-- 1 < 2 <= 0
COPYFROM 2
OUTBOX
COPYFROM 0
OUTBOX
JUMP e
h:
-- 1 < 0 <= 2
COPYFROM 0
OUTBOX
COPYFROM 2
OUTBOX
JUMP d
i:
COPYFROM 0
SUB 2
JUMPN k
-- 2 is smallest
COPYFROM 2
OUTBOX
COPYFROM 1
SUB 0
JUMPN j
-- 2 <= 0 <= 1
COPYFROM 0
OUTBOX
COPYFROM 1
OUTBOX
JUMP c
j:
-- 2 <= 1 <= 0
COPYFROM 1
OUTBOX
COPYFROM 0
OUTBOX
JUMP b
k:
-- 0 <= 2 <= 1
COPYFROM 0
OUTBOX
COPYFROM 2
OUTBOX
COPYFROM 1
OUTBOX
JUMP a
-- vim: set autoindent: