Skip to content

Instantly share code, notes, and snippets.

@danielyaa5
Created May 16, 2020 00:57
Show Gist options
  • Save danielyaa5/a0bb389caa8e3b0a5cd023d0521ddd48 to your computer and use it in GitHub Desktop.
Save danielyaa5/a0bb389caa8e3b0a5cd023d0521ddd48 to your computer and use it in GitHub Desktop.
def validCoords?(coord_strings)
coords = parseCoords(coords) # take ["a1", "b3"] => [["b", 3], ["a", 1]]
if coords.length == 0
return false
start_a = coords[0][0]
start_b = coords[0][1]
if increasingNumbers?(coords[0], coords[1])
# for each coord make sure number is increasing
return eachNumberIncreasingBy1?(coords)
return eachLetterIncreasingBy1?(coords)
def eachNumberIncreasingBy1?(coords)
last = nil
result = true
coords.each do |coord|
if last == nil
return
number = coord[1]
if last + 1 != number
result = false
break
end
return result
end
def eachLetterIncreasingBy1?(coords)
last = nil
result = true
coords.each do |coord|
if last == nil
return
letter = coord[0].ord
if last + 1 != letter
result = false
break
end
return result
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment