-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaoc9
More file actions
43 lines (36 loc) · 1011 Bytes
/
Copy pathaoc9
File metadata and controls
43 lines (36 loc) · 1011 Bytes
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
arr = document.getElementsByTagName("pre")[0].innerText.split("\n").filter(function(n){return n;});
basins = [];
var visited = []
arr.forEach(function(row, x){
row.split("").forEach(function(cell,y) {
if (x>0 && cell >= arr[x-1][y] || y>0 && cell >= arr[x][y-1] ||
x<99 && cell >= arr[x+1][y] || y<99 && cell >= arr[x][y+1]) {
return;
}
console.log("SEARCHING",x,y,cell )
basinSearch = function(a, b) {
if (visited.find(function(x){return x[0]==a && x[1]==b}) || arr[a][b]==9) {
return 0;
}
size = 1;
visited.push([a,b]);
if (a>0 && arr[a][b] <= arr[a-1][b]) {
size += basinSearch(a-1,b);
}
if (b>0 && arr[a][b] <= arr[a][b-1]) {
size += basinSearch(a,b-1);
}
if (a<99 && arr[a][b] <= arr[a+1][b]) {
size += basinSearch(a+1,b);
}
if (b<99 && arr[a][b] <= arr[a][b+1]) {
size += basinSearch(a,b+1);
}
return size;
}
basins.push(basinSearch(x,y));
});
})
basins
On Thu, De
Sure it's easier, I can read your mail, right?