html
html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<!DOCTYPE html>
<html>
<head>
<title>Title </title>
</head>
<body>
<div id="header">
<h3>N x N</h3>
<h1>Filled Matrix</h1>
<h3>Reverse Triangular</h3>
</div>
<div id="content">
<div id="label">Enter size of square array:</div>
<div id="input">
<input type="number" id="entry" size="5" />
<input type="button" id="submit" value="OK" />
</div>
<div id="output"> </div>
</div>
<div id="footer"><p><a href="https://www.sololearn.com/Discuss/650079/daily-mini-challenge-write-a-function-that-gets-a-positive-int-n-as-input-and-print-the-filled" target=_blank>
*DAILY-MINI-CHALLENGE* : Write a function that gets a positive int n as input and print the filled matrix (n*n) to the screen!</a>
<br>by <a href="https://www.sololearn.com/Profile/698148/" target=_blank>Julian Fechner</a></p>
<dl id="note">
<dt><em>(Click to show Example)</em><br/>Example of reverse triangular filled Matrix?</dt>
<dd style="display: none;">
EXAMPLE n=3:<br>
<pre>
4 2 1
Enter to Rename, Shift+Enter to Preview
css
css
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
body {
text-align: center;
background-color: #48C;
font-family: Tahoma, Verdana, sans-serif;
font-size: .9em;
color: #777;
}
table {
margin: auto;
}
table tr td {
text-align: center;
padding-left: 4px;
padding-right: 4px;
}
div, span, input {
font-family: inherit;
font-size: inherit;
}
#header {
margin-bottom: 1em;
}
Enter to Rename, Shift+Enter to Preview
js
js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
Array.matrix = function(numrows, numcols, initial){
var arr = [];
for (var i = 0; i < numrows; ++i){
var columns = [];
for (var j = 0; j < numcols; ++j){
columns[j] = initial;
}
arr[i] = columns;
}
return arr;
};
function fill(N,d,val,Crow,Ccol,row,col,count) {
if(val<=N*N){
d[row][col]=val;
if(count>1){
fill(N,d,val+1,Crow,Ccol,row+1,col+1,count-1);
}
else if(val<((N+1)*(N/2))){
fill(N,d,val+1,Crow,Ccol-1,Crow,Ccol-1,count=N-(Ccol+Crow-1));
}
else {
fill(N,d,val+1,Crow+1,Ccol,Crow+1,Ccol,count=N-(Ccol+Crow+1));
}
}return d;
}
Enter to Rename, Shift+Enter to Preview
BROWSER
Console
Run