Skip to content

Instantly share code, notes, and snippets.

@nifarius
Last active March 11, 2020 08:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save nifarius/9ac2bbf39cf1ed408aa2c334c65aec82 to your computer and use it in GitHub Desktop.
Save nifarius/9ac2bbf39cf1ed408aa2c334c65aec82 to your computer and use it in GitHub Desktop.
=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