You are on page 1of 2

<!

DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style media="screen">
body {
display: inline-flex;
}
textarea {
border: 1px solid black;
}
</style>
</head>
<body>
<textarea id="input" name="name" rows="10" cols="30" placeholder="PUT INPUT
HERE"></textarea>
<button type="button" name="button" onclick="Test2()">Click Me<br>For
Result</button>
<textarea id="output" name="name" rows="10" cols="10"
placeholder="OUTPUT..."></textarea>
</body>
<script type="text/javascript">

function searchLand(y, x) {

function Test2() {

var output = "",


dir = [0, -1, 0, 1, 0],
cases = document.getElementById("input").value,
input = cases.replace(/\n/g, " ").split(" ").map(function(x){
return isNaN(parseInt(x)) ? x : parseInt(x);
});

// if (1 > input[0] || input[0] > 100) {


// document.getElementById("output").value = "Inputs must have at least 1
case and not more than 100.";
// return;
// }

for (var i = 0, j = 1; i < input[0]; j+=input[j]+2, i++) {


console.log("case " + (i+1));
var map = new Array(input[j]),
word = input[((j+2) + input[j])],
domTotal = 0,
region = 1;

// if (1 > input[j] || input[j] > 100 || 1 > input[j+1] || input[j+1] > 100
||
// 1 > word.length || word.length > 100) {
// output = "Case(s) Invalid";
// break;
// }

for (var a = 0; a < map.length; a++) {


map[a] = input[j+2+a].split("");
}

for (var y = 0; y < map.length; y++) {


for(var x = 0; x < map[y].length; x++) {
console.log("searching...");
if (map[y][x] != "#") {
map[y][x] = filler = region;
region++;
console.log("land found at [" + y + "][" + x + "]");
while (map[y][x] != "#" || x < map[x].length) {
var filler = 0;
for (var d = 0; d < dir.length - 1; d++) {
var lookCoor = map[y+dir[d]][x+dir[d+1]];
console.log("checking " + y + " " + x);
if (y < 0 || y > grid.length - 1) break;
if (isFinite(lookCoor)) {
map[y][x] = filler = lookCoor;

}
else if ()
}
x++;
}
}
}
}
output += "Case " + (i+1) + ": " +domTotal + "\n";
}
document.getElementById("output").value = output;
}
</script>
</html>

You might also like