forked from sorear/metamath-turing-machines
-
Notifications
You must be signed in to change notification settings - Fork 0
/
goldbach.nql
82 lines (65 loc) · 1.39 KB
/
goldbach.nql
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
proc zero(x) {
x = 0;
}
proc one(x) {
x = 1;
}
proc incr(x) {
x = x + 1;
}
/* Computes x modulo y */
proc modulus(x, y, out) {
out = x;
while (out >= y) {
out = out - y;
}
}
proc assignXtoYminusX(x, y) {
x = y - x;
}
/* Figures out if x is prime, and puts the output in y */
/* Does not modify x, modifies y */
proc isPrime(x, h, y) {
if (x == 1) {
zero(y);
return;
}
y = 2;
while (x > y) {
modulus(x, y, h);
if (h == 0) {
zero(y);
return;
}
incr(y);
}
}
global evenNumber;
global primeCounter;
global isThisOnePrime;
global foundSum;
global h;
proc main() {
evenNumber = 2;
one(foundSum);
while (0 < foundSum) {
zero(foundSum);
evenNumber = evenNumber + 2;
one(primeCounter);
while (primeCounter < evenNumber) {
isPrime(primeCounter, h, isThisOnePrime);
if (0 < isThisOnePrime) {
assignXtoYminusX(primeCounter, evenNumber);
isPrime(primeCounter, h, isThisOnePrime);
assignXtoYminusX(primeCounter, evenNumber);
if (0 < isThisOnePrime) {
/* print evenNumber;
print primeCounter; */
one(foundSum);
}
}
incr(primeCounter);
}
}
return;
}