Four sides of square: Difference between revisions

m
(Created Nim solution.)
 
(6 intermediate revisions by 4 users not shown)
Line 1:
{{Draft task|Matrices}}
 
;Task:
Line 6:
<br>
[http://keptarhely.eu/view.php?file=20220218v00x6hugz.jpeg Four sides of square - image]
 
 
===See also===
Line 14 ⟶ 13:
=={{header|11l}}==
{{trans|Python}}
 
<syntaxhighlight lang="11l">
V size = 9
Line 435 ⟶ 433:
 
=={{header|Arturo}}==
 
<syntaxhighlight lang="rebol">drawSquare: function [side][
loop 1..side 'x ->
Line 495 ⟶ 492:
1 1 1 1 1 1 1
</pre>
 
=={{header|BQN}}==
<syntaxhighlight lang="bqn">Square ← ∨⌜˜1⌽↑⟜1‿1
 
Square 5</syntaxhighlight>
{{out}}
<pre>┌─
╵ 1 1 1 1 1
1 0 0 0 1
1 0 0 0 1
1 0 0 0 1
1 1 1 1 1
┘</pre>
 
=={{header|C}}==
Line 519 ⟶ 529:
return 0;
}</syntaxhighlight>
 
{{out}}
<pre>
Line 649 ⟶ 658:
</pre>
 
=={{header|EasyLang}}==
<syntaxhighlight>
proc holmat n . .
for i to n
for j to n
if i = 1 or i = n or j = 1 or j = n
write "1 "
else
write "0 "
.
.
print ""
.
.
holmat 10
</syntaxhighlight>
{{out}}
<pre>
1 1 1 1 1 1 1 1 1 1
1 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 1
1 1 1 1 1 1 1 1 1 1
</pre>
 
=={{header|F_Sharp|F#}}==
Line 671 ⟶ 709:
[1; 1; 1; 1; 1; 1]]
</pre>
 
 
=={{header|FreeBASIC}}==
Line 722 ⟶ 759:
{{out}}
https://www.dropbox.com/s/9g5ahfzw1muuzgm/hollowMatrix.bmp?dl=0
 
 
=={{header|Go}}==
Line 855 ⟶ 891:
 
=={{header|J}}==
 
Implementation:
<syntaxhighlight lang="j">fsosq=: {{+./~(+.|.)y{.1}}</syntaxhighlight>
Line 949 ⟶ 984:
squareonesapp(8)
</syntaxhighlight>
 
=={{header|K}}==
<syntaxhighlight lang="k">square: {x|/:x}{x||x}@~-':!:
 
square 5</syntaxhighlight>
{{out}}
<pre>(1 1 1 1 1
1 0 0 0 1
1 0 0 0 1
1 0 0 0 1
1 1 1 1 1)</pre>
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<syntaxhighlight lang="mathematica">Manipulate[ArrayPad[ConstantArray[0, {1, 1} n - 1], 1, 1] // Grid, {n, 2, 20, 1}]</syntaxhighlight>
 
=={{header|Maxima}}==
<syntaxhighlight lang="maxima">
/* Function that returns a square matrix with square pattern in their entries */
square(n):=genmatrix(lambda([x,y],if x=1 or y=1 or x=n or y=n then 1 else 0),n,n)$
 
/* Example */
square(6);
</syntaxhighlight>
{{out}}
<pre>
matrix(
[1, 1, 1, 1, 1, 1],
[1, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 1],
[1, 1, 1, 1, 1, 1]
)
</pre>
 
=={{header|Nim}}==
Line 1,174 ⟶ 1,240:
 
=={{header|Quackery}}==
 
<syntaxhighlight lang="quackery"> [ 0 over 2 - of
1 tuck join join nested
Line 1,356 ⟶ 1,421:
1 1 1 1
</pre>
 
 
=={{header|Ruby}}==
Line 1,394 ⟶ 1,458:
=={{header|Wren}}==
===Text based===
<syntaxhighlight lang="ecmascriptwren">var hollowMatrix = Fn.new { |n|
for (i in 0...n) {
for (j in 0...n) {
Line 1,421 ⟶ 1,485:
{{libheader|Go-fonts}}
This is designed to look as close as possible to the Red entry's image so that we don't have to fill up Wikimedia Commons with similar looking images.
<syntaxhighlight lang="ecmascriptwren">import "dome" for Window
import "graphics" for Canvas, Color, Font
class Main {
1,978

edits