Four sides of square: Difference between revisions
Content added Content deleted
No edit summary |
(→{{header|Ruby}}: Add Ruby) |
||
Line 1,186: | Line 1,186: | ||
[http://keptarhely.eu/view.php?file=20220218v00x6hugz.jpeg Four sides of square] |
[http://keptarhely.eu/view.php?file=20220218v00x6hugz.jpeg Four sides of square] |
||
=={{header|Ruby}}== |
|||
<syntaxhighlight lang="ruby">def square_sides(size = 9) |
|||
Array.new(size){|n| n==0 || n==size-1 ? [1]*size : [1]+[0]*(size-2)+[1]} |
|||
end |
|||
puts square_sides.map{|line| line.join (" ") } |
|||
</syntaxhighlight> |
|||
{{out}} |
|||
<pre>1 1 1 1 1 1 1 1 1 |
|||
1 0 0 0 0 0 0 0 1 |
|||
1 0 0 0 0 0 0 0 1 |
|||
1 0 0 0 0 0 0 0 1 |
|||
1 0 0 0 0 0 0 0 1 |
|||
1 0 0 0 0 0 0 0 1 |
|||
1 0 0 0 0 0 0 0 1 |
|||
1 0 0 0 0 0 0 0 1 |
|||
1 1 1 1 1 1 1 1 1 |
|||
</pre> |
|||
=={{header|Sidef}}== |
=={{header|Sidef}}== |
||
<syntaxhighlight lang="ruby">var n = 5 |
<syntaxhighlight lang="ruby">var n = 5 |