title: Find all integers between m and n whose sum of squared divisors is itself a square
body: <h2>Problem Question</h2>
  <p>Divisors of 42 are : 1, 2, 3, 6, 7, 14, 21, 42. These divisors squared are: 1, 4, 9, 36, 49, 196, 441, 1764. The sum of the squared divisors is 2500 which is 50 * 50, a square!</p>
  <p>Given two integers m, n (1 &lt;= m &lt;= n) we want to find all integers between m and n whose sum of squared divisors is itself a square. 42 is such a number.</p>
  <p>The result will be an array of arrays, each subarray having two elements, first the number whose squared divisors is a square and then the sum of the squared divisors.</p>
  <h1>Code below</h1>
  <p>How can I make this specific program run faster? My current code times out after n &gt; 9999.</p>
  <pre><code>#returns the divisors of each number in an array of arrays
  
  r = (m..n).to_a.map { |z| (1..z).select { |x| z % x == 0} }
  
  #this finds all integers between m and n whose sum of squared divisors is itself a square
  
  squarenumbers = r.map { |x| x.map { |c| c**2 }.inject(:+) }.select { |x| Math.sqrt(x) % 1 == 0 }
  
  #returns an array of booleans. 
  
  booleans = r.map { |x| x.map { |c| c**2 }.inject(:+) }.map { |x| Math.sqrt(x) % 1 == 0 }
  
  #returns the index of each of the true values in booleans as an array
  
  indexer = booleans.map.with_index{|x, i| i if x == true }.compact
  
  #returns the numbers whose squared divisors is a square in an array
  
  unsqr = indexer.map { |x| (m..n).to_a[x] }
  
  #merges the two arrays together, element for element and creates an array of arrays
  
  unsqr.zip(squarenumbers) 
  
  # for m = 1 and n = 1000 the result would be
  
  # [[1, 1], [42, 2500], [246, 84100], [287, 84100], [728, 722500]]
  </code></pre>