Created
December 16, 2011 00:06
-
-
Save freddiefujiwara/1483616 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var fields = "W........WW."; | |
| fields += ".WWW.....WWW"; | |
| fields += "....WW...WW."; | |
| fields += ".........WW."; | |
| fields += ".........W.."; | |
| fields += "..W......W.."; | |
| fields += ".W.W.....WW."; | |
| fields += "W.W.W.....W."; | |
| fields += ".W.W......W."; | |
| fields += "..W.......W."; | |
| var width = 12; | |
| fields = fields.split(new RegExp("")); | |
| var walk = function(i){ | |
| fields[i] = "."; | |
| $.each([i-width-1,i-width,i-width+1,i-1,i+1,i+width-1,i+width,i+width+1],function(n,m){ | |
| if("W"===fields[m]){walk(m);}; | |
| }); | |
| }; | |
| var count = 0; | |
| $.each(fields,function(n,m){ | |
| if("W"===fields[n]){walk(n);count++;}; | |
| }); | |
| console.log(count); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment