prime number generator using the sieve of eratosthenes | |
converted to ibm 650 floating poing interpretive system (is) | |
uses two extra o2 codes: o2=800 (set lbox) and o2=453 (tr zero) | |
warning: comments are allowed past column 28 but some characters | |
are forbidden: uppercase letters, question mark, exclamation, number char, | |
ampersand char. if these chars are used, the line (i.e. the card for this | |
line) will be interpreted as a load card, and program will crash on trying | |
to execute it. | |
100 -9 000 201 400 initp -move i1 prime initp: prime[c]=1 | |
101 +0 001 050 100 loop c 050 initp c++; if c<50 goto initp | |
102 +9 000 201 300 move i1 num num=1 | |
103 +1 300 201 300 loop1 add num i1 num loop1: num++ | |
104 +2 300 203 000 sub num i50 last | |
105 +0 201 120 106 tr sgn loope cont if num >= 50 goto loope | |
106 +0 800 002 300 set lbox b num b=num | |
107 -9 000 400 000 -move prime last last=prime[b] | |
108 +0 453 103 110 tr zero loop1 cont if last = 0 goto loop1 | |
110 +9 000 300 301 move num mult mult=num | |
111 +1 300 301 301 loop2 add num mult mult loop2: mult=mult+num | |
112 +2 301 203 000 sub mult i50 last | |
113 +0 201 103 114 tr sgn loop1 cont if mult >= 50 goto loop1 (go to b if +, go to c if -) | |
114 +0 800 003 301 set lbox c mult c=mult | |
115 -9 000 200 400 -move zero prime prime[c]=0 | |
116 +0 203 000 111 tr loop2 goto loop2 | |
120 +9 000 201 300 loope move i1 num loope: num=1 | |
121 +0 800 002 202 set lbox b i2 b=2 | |
122 +1 300 201 300 prt1 add num i1 num prt1: num++ | |
123 -9 000 400 000 -move prime last last=prime[b] | |
124 +0 453 127 126 tr zero prt2 cont if last = 0 goto prt2 | |
126 +0 410 300 300 pch num num punch num | |
127 +0 010 050 122 prt2 loop b 050 prt1 prt2: b++; if b<50 goto prt1 | |
128 +0 000 000 000 unc stop end | |
constants | |
200 +0 0000000 50 zero | |
201 +1 0000000 50 i1 | |
202 +2 0000000 50 i2 | |
203 +5 0000000 51 i50 | |
variables | |
300 +0 0000000 50 num current number to check for being prime | |
301 +0 0000000 50 mult multiple | |
400 +0 0000000 50 prime array of numbers 400-449 | |
100 program start address | |