-
-
Save nifarius/9ac2bbf39cf1ed408aa2c334c65aec82 to your computer and use it in GitHub Desktop.
This file contains 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
=begin | |
Given | |
1. An array of strings where "L" indicates land and "W" indicates water, | |
2. a coordinate marking a starting point in the middle of the ocean | |
The Challenge: | |
Find and mark the ocean in the map by changing appropriate W's to O's. | |
An ocean coordinate is defined to be any coordinate directly adjacent to any other ocean coordinate. | |
Example: | |
map = [ "LLLLLLLLWW", | |
"LLLLLLLWWW", | |
"WWWLLLLLWW" ] | |
coordinate: [0,9] | |
RESULT: | |
[ "LLLLLLLLOO", | |
"LLLLLLLOOO", | |
"WWWLLLLLOO" ] | |
More examples: | |
map = [ "LLWWWWLLWW", | |
"LLWLLWWWWW", | |
"WWWLLLLLWW" ] | |
coordinate: [2,8] | |
RESULT: | |
[ "LLOOOOLLOO", | |
"LLOLLOOOOO", | |
"OOOLLLLLOO" ] | |
coordinate: [1,2] | |
Same result. | |
map = [ "LWWWWLLLWW", | |
"WWLLWLLWWW", | |
"WWWWWWWWWW" ] | |
coordinate: [0,9] | |
RESULT: | |
[ "LOOOOLLLOO", | |
"OOLLOLLOOO", | |
"OOOOOOOOOO" ] | |
=end | |
def find_ocean(map, x, y) | |
end | |
map = [ "LLLLLLLLWW", | |
"LLLLLLLWWW", | |
"WWWLLLLLWW" ] | |
find_ocean(map, 0, 9) | |
map.each{|x| puts x } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment