Skip to content

Instantly share code, notes, and snippets.

@Johnsalzarulo
Created January 7, 2018 05:16
Show Gist options
  • Save Johnsalzarulo/da24068be122ef5178a9bbb3364e8ade to your computer and use it in GitHub Desktop.
Save Johnsalzarulo/da24068be122ef5178a9bbb3364e8ade to your computer and use it in GitHub Desktop.
#My anwer for https://www.interviewcake.com/question/ruby/permutation-palindrome
class Palindrome
def self.test_string(text)
characters = text.split(//)
odd_char = characters.select {|char| characters.count(char).odd?}.uniq
if odd_char.count == 1 or odd_char.count == 0
true
else
false
end
end
def self.test_all
strings = ['civic', 'ivicc', 'civil', 'livci', 'racecar','a but tuba', 'notpalindrome']
strings.each do |string|
puts "#{string}: #{Palindrome.test_string(string)}"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment