title: Longest recurring cycle of digits
body: <p>I'm trying to find the number less than 1000 that produces the longest string of repeated numbers when it divides 1. I have a list of decimal numbers and have to find the ones which have the longest repeated sequence.</p>
  
  <p>Here's what I have so far</p>
  
  <pre><code>numbers = [*2..999]
  decimal_representations = numbers.map { |number| 1.to_f/number }
  decimal_representations.map!(&amp;:to_s)
  </code></pre>
  
  <p>I can produce a three dimensional array by using regex. Regex <code>/(.+)\1+/</code> produces an array of repeated substrings. I want to find the longest substring, so I used enumerable's <code>max_by</code> function.</p>
  
  <pre><code>decimal_representations.map! { |decimal| decimal.scan(/(.+)\1+/).max_by(&amp;:length) }.flatten
  </code></pre>
  
  <p>I have to compact my array to remove <code>nil</code> elements</p>
  
  <pre><code>decimal_representations.compact!
  </code></pre>
  
  <p>Then I can find out which had the longest length.</p>
  
  <pre><code>decimal_representations.max_by(&amp;:length)
  </code></pre>
  
  <p>I get <code>0090009009</code>, but I can't figure out which number had that decimal value, because I removed nil elements from my array.</p>
  
  <p>Any ideas?</p>