title: Why is this F# code slower than the C# equivalent?
body: <p>I'm tackling the Project Euler problems again (did the 23 first ones before when I was learning C#) and I'm quite baffled at the subpar performance of my solution to problem 5.</p>
  
  <p>It reads as follow:</p>
  
  <blockquote>
    <p>2520 is the smallest number that can be divided by each of the numbers
    from 1 to 10 without any remainder.</p>
    
    <p>What is the smallest positive number that is evenly divisible by all
    of the numbers from 1 to 20?</p>
  </blockquote>
  
  <p>Now my incredibly primitive brute-force solution of C# tugs through this problem in roughly 25 seconds.</p>
  
  <pre><code>var numbers = Enumerable.Range(1, 20);
  int start = 1;
  int result;
  while (true)
  {
     if (numbers.All(n =&gt; start % n == 0))
     {
         result = start;
         break;
     }
     start++;
  }
  </code></pre>
  
  <p>Now my F# solution uses brute forcing as well but at least it does a bit more discrimination and such so that it "should" in my mind run faster but it clocks out at ~45 secs so it's nearly twice as slow as the C# one.</p>
  
  <pre><code>let p5BruteForce =
      let divisors = List.toSeq ([3..20] |&gt; List.rev)
      let isDivOneToTwenty n =
          let dividesBy = 
              divisors |&gt; Seq.takeWhile(fun x -&gt; n % x = 0)                
          Seq.length dividesBy = Seq.length divisors
  
      let findNum n =
          let rec loop n = 
              match isDivOneToTwenty n with
              | true -&gt; n
              | false -&gt; loop (n + 2)
          loop n
      findNum 2520
  </code></pre>
  
  <p>P.S - I know that my solution could be better, in this case I am simply wondering how it could be that a better brute-force solution can be so much slower than a primitive one.</p>