all tasks
This commit is contained in:
parent
b83f433714
commit
68f8f3e56b
14735 changed files with 178959 additions and 0 deletions
19
Task/Sierpinski-triangle/JavaScript/sierpinski-triangle.js
Normal file
19
Task/Sierpinski-triangle/JavaScript/sierpinski-triangle.js
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
function triangle(o) {
|
||||
var n = 1<<o, line = new Array(2*n), i,j,t,u;
|
||||
for (i=0; i<line.length; ++i) line[i] = ' ';
|
||||
line[n] = '*';
|
||||
for (i=0; i<n; ++i) {
|
||||
document.write(line.join('')+"\n");
|
||||
u ='*';
|
||||
for(j=n-i; j<n+i+1; ++j) {
|
||||
t = (line[j-1] == line[j+1] ? ' ' : '*');
|
||||
line[j-1] = u;
|
||||
u = t;
|
||||
}
|
||||
line[n+i] = t;
|
||||
line[n+i+1] = '*';
|
||||
}
|
||||
}
|
||||
document.write("<pre>\n");
|
||||
triangle(6);
|
||||
document.write("</pre>");
|
||||
Loading…
Add table
Add a link
Reference in a new issue