第 40 关,质数工厂。指令集介绍请看:https://www.annhe.net/article-3828.html。
优化目标
28行399步
代码
28行247步
行数速度都满足,见 Github。
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 |
-- HUMAN RESOURCE MACHINE PROGRAM -- a: b: INBOX COPYTO 10 COPYFROM 24 COPYTO 22 BUMPUP 22 COPYTO 1 c: BUMPUP 1 d: COPYFROM 24 COPYTO 12 SUB 10 e: COPYTO 11 BUMPUP 12 COPYFROM 11 ADD 1 JUMPN e JUMPZ f BUMPDN 22 JUMPZ c COPYFROM 10 OUTBOX JUMP b f: COPYFROM 1 OUTBOX BUMPDN 12 JUMPZ a BUMPUP 12 COPYTO 10 JUMP d |
69行267步
提前准备前几个质数
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 |
COPYFROM 24 COPYTO 11 BUMPUP 11 BUMPUP 11 COPYTO 12 BUMPUP 12 ADD 11 COPYTO 13 ADD 11 COPYTO 14 ADD 12 COPYTO 15 BUMPUP 15 ADD 11 COPYTO 16 ADD 12 COPYTO 17 BUMPUP 17 ADD 11 COPYTO 18 JUMP start out: COPYFROM 23 OUTBOX start: COPYFROM 24 COPYTO 10 BUMPUP 10 INBOX COPYTO 23 SUB 11 JUMPZ out ADD 11 SUB 12 JUMPZ out ADD 12 SUB 13 JUMPZ out ADD 13 SUB 14 JUMPZ out ADD 14 SUB 15 JUMPZ out ADD 15 SUB 16 JUMPZ out ADD 16 SUB 17 JUMPZ out ADD 17 SUB 18 JUMPZ out continue: BUMPUP 10 prepare: COPYFROM 24 COPYTO 0 COPYFROM 23 test: SUB 10 JUMPN continue JUMPZ out2 COPYTO 22 BUMPUP 0 COPYFROM 22 JUMP test out2: COPYFROM 10 OUTBOX COPYFROM 0 JUMPZ start COPYTO 23 BUMPUP 23 JUMP prepare |
23行414步
参考 Github。相对于 439 步,将 test 中 COPYTO 22 移到了 JUMPZ,JUMPN 指令之后,并交换了 JUMPZ , JUMPN顺序
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 |
start: COPYFROM 24 COPYTO 10 BUMPUP 10 INBOX COPYTO 23 continue: BUMPUP 10 prepare: COPYFROM 24 COPYTO 0 COPYFROM 23 test: SUB 10 JUMPN continue JUMPZ out2 COPYTO 22 BUMPUP 0 COPYFROM 22 JUMP test out2: COPYFROM 10 OUTBOX COPYFROM 0 JUMPZ start COPYTO 23 BUMPUP 23 JUMP prepare |
23行439步
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 |
start: COPYFROM 24 COPYTO 10 BUMPUP 10 INBOX COPYTO 23 continue: BUMPUP 10 prepare: COPYFROM 24 COPYTO 0 COPYFROM 23 test: SUB 10 COPYTO 22 JUMPZ out2 JUMPN continue BUMPUP 0 COPYFROM 22 JUMP test out2: COPYFROM 10 OUTBOX COPYFROM 0 JUMPZ start COPYTO 23 BUMPUP 23 JUMP prepare |
27行500步
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 |
start: COPYFROM 24 COPYTO 0 COPYTO 10 BUMPUP 10 INBOX COPYTO 23 continue: BUMPDN 23 JUMPZ start BUMPUP 10 COPYFROM 24 COPYTO 0 BUMPUP 23 test: SUB 10 COPYTO 22 JUMPZ out2 JUMPN continue BUMPUP 0 COPYFROM 22 JUMP test out2: COPYFROM 10 OUTBOX BUMPUP 0 COPYTO 23 COPYFROM 24 COPYTO 0 COPYFROM 23 JUMP test |
第一次pass 29行508步
从2开始循环找出因子
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 |
start: COPYFROM 24 COPYTO 0 COPYTO 10 BUMPUP 10 BUMPUP 10 INBOX COPYTO 23 test: SUB 10 COPYTO 22 JUMPZ out2 JUMPN continue BUMPUP 0 COPYFROM 22 JUMP test out2: COPYFROM 10 OUTBOX BUMPUP 0 COPYTO 23 COPYFROM 24 COPYTO 0 COPYFROM 23 JUMP test continue: BUMPUP 10 COPYFROM 24 COPYTO 0 BUMPDN 23 JUMPZ start BUMPUP 23 JUMP test |
发表回复