Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
20
Task/Spiral-matrix/Sidef/spiral-matrix.sidef
Normal file
20
Task/Spiral-matrix/Sidef/spiral-matrix.sidef
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
func spiral(n) {
|
||||
var (x, y, dx, dy, a) = (0, 0, 1, 0, []);
|
||||
{ |i|
|
||||
a[y][x] = i;
|
||||
var (nx, ny) = (x+dx, y+dy);
|
||||
( if (dx == 1 && (nx == n || a[ny][nx]!=nil)) { [ 0, 1] }
|
||||
elsif (dy == 1 && (ny == n || a[ny][nx]!=nil)) { [-1, 0] }
|
||||
elsif (dx == -1 && (nx < 0 || a[ny][nx]!=nil)) { [ 0, -1] }
|
||||
elsif (dy == -1 && (ny < 0 || a[ny][nx]!=nil)) { [ 1, 0] }
|
||||
else { [dx, dy] }
|
||||
) » (\dx, \dy);
|
||||
x = x+dx;
|
||||
y = y+dy;
|
||||
} * n**2;
|
||||
return a;
|
||||
}
|
||||
|
||||
spiral(5).each { |row|
|
||||
row.map {"%3d" % _}.join(' ').say;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue