Skip to content

Instantly share code, notes, and snippets.

@maysam
Last active May 14, 2018 14:03
Show Gist options
  • Save maysam/8936e49679fdd4bb34973fa6268f2deb to your computer and use it in GitHub Desktop.
Save maysam/8936e49679fdd4bb34973fa6268f2deb to your computer and use it in GitHub Desktop.
is it palandrome, if we only consider numbers and letters
def isSomewhatPalandrome?(word)
i = 0
j = word.length-1 # 1
while(i<j) do
while ((i < word.length) && !(word[i].match /^[a-zA-Z0-9]$/)) do
i+=1 # 1
end
while ((j > 0) && !(word[j].match /^[a-zA-Z0-9]$/)) do
j-=1 # j -> 0
end
if (
i <= j &&
(word[i] != word[j]) &&
(word[i].upcase != word[j]) &&
(word[i] != word[j].upcase)
)
return false
end
i += 1 # 1
j -= 1 # 29
end
true
end
puts isSomewhatPalandrome?("A man, a plan, a canal, Panama!")
puts isSomewhatPalandrome?("Aan, a plan, a canal, Panama!")
puts isSomewhatPalandrome?(".1.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment