title: Ruby - Finding the longest palindromic substring in a string
body: <p>I understand how to find if one string is a palindrome</p>
  
  <pre><code>string1 == string1.reverse
  </code></pre>
  
  <p>It's a little more difficult though with multiple palindromes in a string</p>
  
  <pre><code>"abcdxyzyxabcdaaa"
  </code></pre>
  
  <p>In the above string, there are 4 palindromes of length greater than 1</p>
  
  <pre><code>"xyzyx", "yzy", "aaa" and "aa"
  </code></pre>
  
  <p>In this case, the longest palindrome is "xyxyx", which is 5 characters long.</p>
  
  <p>How would I go about solving this problem though.</p>
  
  <p>I know of the array#combination method, but that won't work in this case.</p>
  
  <p>I was thinking of implementing something like this</p>
  
  <pre><code>def longest_palindrome(string)
    palindromes = []
    for i in 2..string.length-1
      string.chars.each_cons(i).each {|x|palindromes.push(x) if x == x.reverse}
    end
    palindromes.map(&amp;:join).max_by(&amp;:length)
  end
  </code></pre>