0 Replies - 539 Views - Last Post: 23 March 2014 - 01:08 PM

#1 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2263
  • View blog
  • Posts: 9,469
  • Joined: 29-May 08

Fibonacci Sequence (>= .net 4.0)

Posted 23 March 2014 - 01:08 PM

Requires a reference to Framework Assembly System.Numerics

Imports System.Numerics

Public Module Numerics

  Public Iterator Function FibonacciSeq() As IEnumerable(of BigInteger)
    Dim n = { BigInteger.Zero, BigInteger.One }
    While True
      Yield n(0)
      n = {n(1),n(0) + n(1) }
    End While
  End Function
  
End Module



Example2


Dim ListOfTheFirst1000 = FibonacciSeq.Take(1000).ToList

Dim Euler2 = FibonacciSeq.TakeWhile(Function(x) x < 4000000).Where(Function(x) x.IsEven).Sum


The Euler2 result relies on the following additional extension method.

Spoiler


Is This A Good Question/Topic? 0
  • +

Page 1 of 1