1
0

More BefunGen desc

This commit is contained in:
2014-07-16 19:10:02 +02:00
parent 14f3d5df3b
commit 03e0ae3214
14 changed files with 1781 additions and 0 deletions

View File

@@ -0,0 +1,77 @@
###Sieve of Erasthothenes
Calculates the primes between 0 and 19200 with the sieve of Erasthothenes
```textfunge
program SieveOfEratosthenes : display[240, 80]
begin
// Init all Fields with '?'
init();
// Set an 'X' to every Primenumberfield
calculate();
// Output the primes
output();
end
void init()
var
int i;
begin
for(i = 0; i < DISPLAY_SIZE; i++) do
display[i % DISPLAY_WIDTH, i / DISPLAY_WIDTH] = '?';
end
display[0, 0] = ' ';
display[1, 0] = ' ';
end
void calculate()
var
int i;
begin
for(i = 2; i < DISPLAY_SIZE; i++) do
doNumber(i);
end
end
void doNumber(int i)
var
char c;
begin
c = display[i % DISPLAY_WIDTH, i / DISPLAY_WIDTH];
if (c == 'X' || c == ' ') then
return;
elsif (c == '?') then
display[i % DISPLAY_WIDTH, i / DISPLAY_WIDTH] = 'X';
clear(i);
end
end
void clear(int n)
var
int p;
begin
for(p = 2*n; p < DISPLAY_SIZE; p += n) do
display[p % DISPLAY_WIDTH, p / DISPLAY_WIDTH] = ' ';
end
end
void output()
var
int i;
begin
out "Prime Numbers:\r\n";
for(i = 2; i < DISPLAY_SIZE; i++) do
if (display[i % DISPLAY_WIDTH, i / DISPLAY_WIDTH] == 'X') then
outf i, "\r\n";
end
end
end
end
```
> **Note:** *This and other examples are included in the BefunGen download*