Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
33
Task/Cantor-set/D/cantor-set.d
Normal file
33
Task/Cantor-set/D/cantor-set.d
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
import std.stdio;
|
||||
|
||||
enum WIDTH = 81;
|
||||
enum HEIGHT = 5;
|
||||
|
||||
char[WIDTH*HEIGHT] lines;
|
||||
|
||||
void cantor(int start, int len, int index) {
|
||||
int seg = len / 3;
|
||||
if (seg == 0) return;
|
||||
for (int i=index; i<HEIGHT; i++) {
|
||||
for (int j=start+seg; j<start+seg*2; j++) {
|
||||
int pos = i*WIDTH + j;
|
||||
lines[pos] = ' ';
|
||||
}
|
||||
}
|
||||
cantor(start, seg, index+1);
|
||||
cantor(start+seg*2, seg, index+1);
|
||||
}
|
||||
|
||||
void main() {
|
||||
// init
|
||||
lines[] = '*';
|
||||
|
||||
// calculate
|
||||
cantor(0, WIDTH, 1);
|
||||
|
||||
// print
|
||||
for (int i=0; i<HEIGHT; i++) {
|
||||
int beg = WIDTH * i;
|
||||
writeln(lines[beg..beg+WIDTH]);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue