Four sides of square: Difference between revisions
m
syntax highlighting fixup automation
(Initial Haskell version.) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 8:
=={{header|Ada}}==
<
with Ada.Command_Line;
Line 44:
when others =>
Ada.Text_Io.Put_Line ("Usage: ./four_sides <length>");
end Four_Sides;</
{{out}}
<pre>
Line 64:
=={{header|ALGOL 68}}==
<
# draws a matrix with height and width = n with 1s on the edges #
PROC draw square = ( INT n )VOID:
Line 78:
draw square( 7 )
END
</syntaxhighlight>
{{out}}
<pre>
Line 98:
=={{header|Arturo}}==
<
loop 1..side 'x ->
print map 1..side 'y [
Line 107:
drawSquare 4
print ""
drawSquare 6</
{{out}}
Line 124:
=={{header|AWK}}==
<syntaxhighlight lang="awk">
# syntax: GAWK -f FOUR_SIDES_OF_SQUARE.AWK
BEGIN {
Line 139:
exit(0)
}
</syntaxhighlight>
{{out}}
<pre>
Line 159:
=={{header|C}}==
<
void hollowMatrix(unsigned int n) {
Line 180:
hollowMatrix(11);
return 0;
}</
{{out}}
Line 209:
=={{header|C++}}==
<
#include <iostream>
Line 239:
}
</syntaxhighlight>
{{out}}
<pre> 1 1 1 1 1 1 1 1
Line 262:
=={{header|F_Sharp|F#}}==
<
// Four sides of square. Nigel Galloway: February 18th., 2022
let m11 m=Array2D.init m m (fun n g->if n=0 || g=0 || g=m-1 || n=m-1 then 1 else 0)
printfn "%A\n\n%A" (m11 5) (m11 6)
</syntaxhighlight>
{{out}}
<pre>
Line 286:
=={{header|FreeBASIC}}==
===Text based===
<
For i As Integer = 0 To n
For j As Integer = 0 To n
Line 296:
hollowMatrix(9)
Sleep</
{{out}}
<pre>1 1 1 1 1 1 1 1 1
Line 309:
===Graphical===
<
Screenres size, size, 24
Cls
Line 330:
Next x
Bsave "hollowMatrix.bmp",0
Sleep</
{{out}}
https://www.dropbox.com/s/9g5ahfzw1muuzgm/hollowMatrix.bmp?dl=0
Line 336:
=={{header|Go}}==
<
import "fmt"
Line 357:
fmt.Println()
hollowMatrix(9)
}</
{{out}}
Line 382:
=={{header|Haskell}}==
<
import Data.List.Split (chunksOf)
import System.Environment (getArgs)
Line 397:
main = do
sizes <- map read <$> getArgs
putStrLn $ intercalate "\n\n" $ map square sizes</
{{out}}
<pre>
Line 427:
Implementation:
<
Some examples:
<
fsosq 1
1
Line 456:
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</
Gui examples are not visible here, but, for example:
<
viewmat fsosq 20
viewmat fsosq 5</
=={{header|jq}}==
{{works with|jq}}
'''Works with gojq, the Go implementation of jq'''
<
[range(0; .) | 1] as $top
| [1, (range(0; .-2) | 0), 1] as $two
Line 472:
def display:
map(join(" ")) | join("\n");</
'''Example''':
<
</syntaxhighlight>
{{out}}
<pre>
Line 491:
=={{header|Julia}}==
Gtk graphical version.
<
function set_gtk_style!(widget::Gtk.GtkWidget, style::String, value::Int)
Line 518:
squareonesapp(8)
</syntaxhighlight>
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<
=={{header|Perl}}==
<
use warnings;
use feature 'say';
my $n = 5;
say join ' ', @$_ for ([(1)x$n], (map { [1, (0)x($n-2), 1] } 0..$n-3), [(1)x$n]);</
{{out}}
<pre>1 1 1 1 1
Line 541:
=={{header|Processing}}==
<
//Aamrun, 27th June 2022
Line 561:
}
}
</syntaxhighlight>
=={{header|Python}}==
===Procedural===
<
for row in range(size):
for col in range(size):
Line 572:
else:
print("0", end=" ")
print()</
{{out}}
Line 580:
The following version illustrates several features of Python, such as default arguments, nested functions with lexical scoping, generators, and convenient syntax for creating sets and performing set operations such as intersection.
<
def is_at_border(row, col):
Line 594:
suqare()
</syntaxhighlight>
===Functional===
<
Line 649:
# MAIN ---
if __name__ == '__main__':
main()</
{{Out}}
<pre>1 1 1 1 1 1 1
Line 672:
=={{header|Quackery}}==
<
1 tuck join join nested
over 2 - of
Line 684:
9 four-sides
witheach
[ witheach [ echo sp ] cr ]</
{{out}}
Line 711:
This isn't a matrix, especially if it is supposed to be graphical; it's a very small (or extremely low resolution) bitmap.
<syntaxhighlight lang="raku"
.put for hollow 7;
put '';
.put for hollow 10;</
{{out}}
<pre>1 1 1 1 1 1 1
Line 739:
=={{header|Red}}==
<
view-square: function [size][
Line 761:
]
view-square 9</
{{out}}
https://commons.wikimedia.org/wiki/File:Hollow_matrix_gui.png
=={{header|Ring}}==
<
# Project : Identity Matrix
# Date : 2022/16/02
Line 832:
next
next
</syntaxhighlight>
Output image:
<br>
Line 838:
=={{header|Sidef}}==
<
[n.of(1), (n-2).of([1, (n-2).of(0)..., 1])..., n.of(1)].each {|row|
say row.join(' ')
}</
{{out}}
<pre>
Line 854:
=={{header|Wren}}==
===Text based===
<
for (i in 0...n) {
for (j in 0...n) {
Line 863:
}
hollowMatrix.call(9)</
{{out}}
Line 881:
{{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.
<
import "graphics" for Canvas, Color, Font
class Main {
Line 916:
}
var Game = Main.new(9)</
{{out}}
Line 924:
=={{header|XPL0}}==
<
int S, I, J;
[for I:= 0 to S-1 do
Line 934:
[DrawMat(6); CrLf(0);
DrawMat(7); CrLf(0);
]</
{{out}}
|