title: F# Codewars Integers: Recreation Two
body: <p>Trying to solve <a href="https://www.codewars.com/kata/integers-recreation-two" rel="nofollow noreferrer">task</a> with </p>
  
  <p><strong>Code</strong></p>
  
  <pre><code>open System
  
  let rec distribute e = function
    | [] -&gt; [[e]]
    | x::xs' as xs -&gt; (e::xs)::[for xs in distribute e xs' -&gt; x::xs]
  
  let rec permute = function
    | [] -&gt; [[]]
    | e::xs -&gt; List.collect (distribute e) (permute xs)
  
  let MoreRule (a: int) (b: int) (c: int) (d: int) = 
      let permutations = permute [a;b;c;d]
      let sums = permutations |&gt; List.map(fun x -&gt; x.[0]*x.[1] + x.[2]*x.[3])
      let diffs = permutations |&gt; List.map(fun x -&gt; x.[0]*x.[1] - x.[2]*x.[3])
      List.append sums diffs
      |&gt; List.distinct
      |&gt; List.filter(fun x -&gt; x&gt;0)
      |&gt; List.sort
  
  let factor number list = [
      for i in list do 
          let t = Math.Floor(Math.Sqrt((number-Math.Pow((float)i,2.0)))) |&gt; int
          if (List.exists ((=)t) list) then 
              yield [|i;t|]
      ]
  
  let prod2Sum (a: int) (b: int) (c: int) (d: int): int[] list = 
      let number = (float)(((a*a)+(b*b))*((c*c)+(d*d)))   
      let coefficients = MoreRule a b c d
      factor number coefficients
      |&gt; List.map(fun arr -&gt; if (arr.[0]&gt;arr.[1]) then [|arr.[1];arr.[0]|] else [|arr.[0];arr.[1]|])
      |&gt; List.distinct
  </code></pre>
  
  <p>When clicking on Attemp button on page i get response Failed Exit Code 1</p>
  
  <blockquote>
    <p>Expected: [[|75; 104|]; [|85; 96|]] Actual: []</p>
  </blockquote>
  
  <p>But on my local PC <code>prod2Sum 4 5 20 1</code> return proper result <code>[[|75; 104|]; [|85; 96|]]</code></p>
  
  <p>The main question what I am doing wrong? How to improve this code? Thank you!</p>