<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:georss="http://www.georss.org/georss" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:gd="http://schemas.google.com/g/2005" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" gd:etag="W/&quot;CkUARXs5cSp7ImA9WhdTGU8.&quot;"><id>tag:blogger.com,1999:blog-694679611587040520</id><updated>2011-07-17T09:30:44.529-07:00</updated><title>Carlos Quintanilla's blog</title><subtitle type="html">On (CLR, JVM) Programming Languagues</subtitle><link rel="http://schemas.google.com/g/2005#feed" type="application/atom+xml" href="http://carlosqt.blogspot.com/feeds/posts/default" /><link rel="alternate" type="text/html" href="http://carlosqt.blogspot.com/" /><link rel="next" type="application/atom+xml" href="http://www.blogger.com/feeds/694679611587040520/posts/default?start-index=26&amp;max-results=25&amp;redirect=false&amp;v=2" /><author><name>Carlos QT</name><uri>http://www.blogger.com/profile/15415604076909500411</uri><email>carlosqt@gmail.com</email></author><generator version="7.00" uri="http://www.blogger.com">Blogger</generator><openSearch:totalResults>69</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://feeds.feedburner.com/CarlosQuintanillasBlog" /><feedburner:info uri="carlosquintanillasblog" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><feedburner:emailServiceId>CarlosQuintanillasBlog</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><entry gd:etag="W/&quot;CkUARXs-fCp7ImA9WhdTGU8.&quot;"><id>tag:blogger.com,1999:blog-694679611587040520.post-275433060648050337</id><published>2011-07-11T15:40:00.000-07:00</published><updated>2011-07-17T09:30:44.554-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-07-17T09:30:44.554-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="IronPython" /><category scheme="http://www.blogger.com/atom/ns#" term="CLR" /><title>Factorial and Fibonacci in IronPython</title><content type="html">&lt;a class="twitter-share-button" data-count="horizontal" data-via="carlosqt" href="http://twitter.com/share"&gt;Tweet&lt;/a&gt;&lt;script src="http://platform.twitter.com/widgets.js" type="text/javascript"&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;br /&gt;
Here below a little program in IronPython that implements 2 classes. There is the main class, called Fiborial (Fibo(nnacci)+(Facto)rial) that implements the &lt;i&gt;Fibonacci&lt;/i&gt; and the &lt;i&gt;Factorial&lt;/i&gt; algorithms in two ways, one &lt;i&gt;Recursive&lt;/i&gt; (using recursion) and the other &lt;i&gt;Imperative&lt;/i&gt; (using loops and states). The second class is just an instance class that does the same thing, but its there just to show the difference between static and instance classes, and finally a main function called as module level code.&lt;br /&gt;
&lt;br /&gt;
You can also find 3 more little examples at the bottom. One prints out the Factorial's Series and Fibonacci's Series, the second one just shows a class that mixes both: static and instance members, and finally the third one that uses different return types for the Factorial method to compare the timing and result.&lt;br /&gt;
&lt;br /&gt;
As with the previous posts, you can copy and paste the code below in your favorite IDE/Editor and start playing and learning with it. This little "working" program will teach you some more basics of the Programming Language.&lt;br /&gt;
&lt;br /&gt;
There are some "comments" on the code added just to tell you what are or how are some features called. In case you want to review the theory, you can read my previous post, where I give a definition of each of the concepts mentioned on the code. You can find it here: &lt;a href="http://carlosqt.blogspot.com/2011/01/new-series-factorial-and-fibonacci.html"&gt;http://carlosqt.blogspot.com/2011/01/new-series-factorial-and-fibonacci.html&lt;/a&gt;&amp;nbsp;&lt;a href="http://carlosqt.blogspot.com/2010/08/new-series-languages-basics-by-example.html"&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
WARNING: the code that you will see below is not following python(ic) guidelines/idiomatic coding, I did it in purpose to compare python's syntax and features side by side with other programming languages... For instance, instead of using a python int or long I imported and used System.Numerics.BigInteger instead. Other examples, naming convention and so on, so bear with me!&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;The Fiborial Program&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="python" name="code"&gt;# Factorial and Fibonacci in IronPython
import clr
clr.AddReference('System.Numerics.dll')
from System.Numerics import BigInteger
from System import Console
from System.Diagnostics import Stopwatch

# Instance Class
# static classes are not supported in Python
class StaticFiborial:
    # Static Field
    __className = ''
    # no builtin static constructor/initializer support
    # you can initialize field at this point and even add extra code
    __className = 'Static Initializer'
    print __className
    # Static Method - Factorial Recursive  
    @staticmethod
    def factorialR(n):
        if n == 1:
            return BigInteger.One            
        else:            
            return BigInteger.Multiply(BigInteger(n), StaticFiborial.factorialR(n-1))            
    # Static Method - Factorial Imperative
    @staticmethod
    def factorialI(n):
        res = BigInteger.One        
        for i in range(n, 1, -1):
            res = BigInteger.Multiply(res, BigInteger(i))
        return res
    # Static Method - Fibonacci Recursive 
    @staticmethod
    def fibonacciR(n):
        if n &amp;lt; 2:
            return 1
        else:
            return StaticFiborial.fibonacciR(n - 1) + StaticFiborial.fibonacciR(n - 2)
    # Static Method - Fibonacci Imperative
    @staticmethod
    def fibonacciI(n):
        pre, cur, tmp = 0, 0, 0
        pre, cur = 1, 1
        for i in range(2, n + 1):  
            tmp = cur + pre  
            pre = cur  
            cur = tmp  
        return cur 
    # Static Method - Benchmarking Algorithms 
    @staticmethod
    def benchmarkAlgorithm(algorithm, values):
        timer = Stopwatch()
        i = 0  
        testValue = 0  
        facTimeResult = BigInteger.Zero
        fibTimeResult = 0    
          
        # 'if-elif-else' Flow Control Statement    
        if algorithm == 1:  
            print '\nFactorial Imperative:'  
            # 'For in range' Loop Statement   
            for i in range(values.Count):                  
                testValue = values[i]  
                # Taking Time    
                timer.Start()  
                facTimeResult = StaticFiborial.factorialI(testValue)  
                timer.Stop()                            
                # Getting Time    
                print ' (' + str(testValue) + ') = ', timer.Elapsed  
        elif algorithm == 2:  
            print '\nFactorial Recursive:'  
            # 'While' Loop Statement  
            while i &amp;lt; len(values):  
                testValue = values[i]  
                # Taking Time    
                timer.Start()  
                facTimeResult = StaticFiborial.factorialR(testValue)  
                timer.Stop()                            
                # Getting Time    
                print ' (' + str(testValue) + ') = ', timer.Elapsed
                i += 1  
        elif algorithm == 3:  
            print '\nFibonacci Imperative:'   
            # 'For in List' Loop Statement               
            for item in values:
                testValue = item  
                # Taking Time  
                timer.Start()  
                fibTimeResult = StaticFiborial.fibonacciI(testValue)  
                timer.Stop()  
                # Getting Time  
                print ' (' + str(testValue) + ') = ', timer.Elapsed                  
        elif algorithm == 4:
            print '\nFibonacci Recursive:'  
            # 'For in List' Loop Statement   
            for item in values:  
                testValue = item  
                # Taking Time  
                timer.Start()  
                fibTimeResult = StaticFiborial.fibonacciR(testValue)  
                timer.Stop()  
                # Getting Time                
                print ' (' + str(testValue) + ') = ', timer.Elapsed
        else:  
            print 'DONG!'

# Instance Class  
class InstanceFiborial(object):
    # Instances Field  
    __className = ''
    # Instance Constructor  
    def __init__(self):  
        self.__className = 'Instance Constructor'
        print self.__className  
    # Instance Method - Factorial Recursive  
    def factorialR(self, n):
        # Calling Static Method  
        return StaticFiborial.factorialR(n)  
    # Instance Method - Factorial Imperative  
    def factorialI(self, n):  
        # Calling Static Method  
        return StaticFiborial.factorialI(n)  
    # Instance Method - Fibonacci Recursive    
    def fibonacciR(self, n):
        # Calling Static Method  
        return StaticFiborial.fibonacciR(n)  
    # Instance Method - Fibonacci Imperative  
    def fibonacciI(self, n):  
        # Calling Static Method  
        return StaticFiborial.fibonacciI(n)  


# Console Program  
def main():
    print 'Static Class'  
    # Calling Static Class and Methods  
    # No instantiation needed. Calling method directly from the class  
    print 'FacImp(5) = ', StaticFiborial.factorialI(5)
    print 'FacRec(5) = ', StaticFiborial.factorialR(5)
    print 'FibImp(11)= ', StaticFiborial.fibonacciI(11)
    print 'FibRec(11)= ', StaticFiborial.fibonacciR(11)
  
    print '\nInstance Class'  
    # Calling Instance Class and Methods  
    # Need to instantiate before using. Calling method from instantiated object  
    ff = InstanceFiborial()
    print 'FacImp(5) = ', ff.factorialI(5)
    print 'FacRec(5) = ', ff.factorialR(5)
    print 'FibImp(11)= ', ff.fibonacciI(11)
    print 'FibRec(11)= ', ff.fibonacciR(11)
  
    # Create a (Python) list of values to test    
    # From 5 to 50 by 5  
    values = []
    for i in range(5,55,5):
        values.append(i)

    # Benchmarking Fibonacci  
    # 1 = Factorial Imperative  
    StaticFiborial.benchmarkAlgorithm(1, values)  
    # 2 = Factorial Recursive  
    StaticFiborial.benchmarkAlgorithm(2, values) 
    # Benchmarking Factorial  
    # 3 = Fibonacci Imperative  
    StaticFiborial.benchmarkAlgorithm(3, values)  
    # 4 = Fibonacci Recursive  
    StaticFiborial.benchmarkAlgorithm(4, values)
    
    # Stop and exit
    Console.Read()  
  
if __name__ == '__main__':
    main()
&lt;/pre&gt;&lt;br /&gt;
And the Output is: &lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-tnqFKsQMzR0/ThX8SkT41vI/AAAAAAAAF7g/rGR8Fwnh9a8/s1600/FiborialIPy.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="640" src="http://1.bp.blogspot.com/-tnqFKsQMzR0/ThX8SkT41vI/AAAAAAAAF7g/rGR8Fwnh9a8/s640/FiborialIPy.png" width="312" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Humm, looks like Fibonnaci's algorithm implemented using recursion is definitively more complex than the others 3 right? I will grab these results for this and each of the upcoming posts to prepare a comparison of time execution between all the programming languages, then we will be able to talk about the algorithm's complexity as well.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Printing the Factorial and Fibonacci Series&lt;/b&gt;&lt;br /&gt;
&lt;pre class="python" name="code"&gt;import clr
clr.AddReference('System.Numerics.dll')
from System.Numerics import BigInteger
from System.Text import StringBuilder
from System import Console

class Fiborial:  
    # Using a StringBuilder as a list of string elements    
    @staticmethod
    def getFactorialSeries(n):
        # Create the String that will hold the list    
        series = StringBuilder()   
        # We begin by concatenating the number you want to calculate    
        # in the following format: "!# ="    
        series.Append("!")  
        series.Append(n)  
        series.Append(" = ")
        # We iterate backwards through the elements of the series    
        for i in range(n, 0, -1):
            # and append it to the list    
            series.Append(i)  
            if i &amp;gt; 1:   
                series.Append(" * ")    
            else:     
                series.Append(" = ")  
        # Get the result from the Factorial Method    
        # and append it to the end of the list    
        series.Append(Fiborial.factorial(n).ToString())
        # return the list as a string    
        return series.ToString()  
  
    # Using a StringBuilder as a list of string elements    
    @staticmethod
    def getFibonnaciSeries(n):  
        # Create the String that will hold the list    
        series = StringBuilder()
        # We begin by concatenating the first 3 values which    
        # are always constant    
        series.Append("0, 1, 1")    
        # Then we calculate the Fibonacci of each element    
        # and add append it to the list    
        for i in range(2, n+1):  
            if i &amp;lt; n:  
                series.Append(", ")   
            else:  
                series.Append(" = ")    
            series.Append(Fiborial.fibonacci(i))  
        # return the list as a string    
        return series.ToString()  
    @staticmethod      
    def factorial(n):
        if n == 1:
            return BigInteger.One
        else:            
            return BigInteger.Multiply(BigInteger(n), Fiborial.factorial(n-1))
    @staticmethod  
    def fibonacci(n):  
        if n &amp;lt; 2:  
            return 1    
        else:    
            return Fiborial.fibonacci(n - 1) + Fiborial.fibonacci(n - 2)  
  
def main():
    # Printing Factorial Series    
    print ""  
    print Fiborial.getFactorialSeries(5)  
    print Fiborial.getFactorialSeries(7)  
    print Fiborial.getFactorialSeries(9)  
    print Fiborial.getFactorialSeries(11)  
    print Fiborial.getFactorialSeries(40)  
    # Printing Fibonacci Series    
    print ""  
    print Fiborial.getFibonnaciSeries(5)  
    print Fiborial.getFibonnaciSeries(7)  
    print Fiborial.getFibonnaciSeries(9)  
    print Fiborial.getFibonnaciSeries(11)  
    print Fiborial.getFibonnaciSeries(40)  
      
    Console.Read()  
  
if __name__ == '__main__':
    main()
&lt;/pre&gt;&lt;br /&gt;
And the Output is:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-XM4_l-j8tYU/Tht2n3AVy6I/AAAAAAAAF74/20lNDz_-FeI/s1600/Fiborial_Series_IPy.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="274" src="http://1.bp.blogspot.com/-XM4_l-j8tYU/Tht2n3AVy6I/AAAAAAAAF74/20lNDz_-FeI/s640/Fiborial_Series_IPy.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Mixing Instance and Static Members in the same Class&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Instance classes can contain both, instance and static members such as: fields, properties, constructors, methods, etc.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="python" name="code"&gt;from System import Console
    
# Instance Class
class Fiborial:
    # Instance Field  
    __instanceCount = 0
    # Static Field      
    __staticCount = 0    
    print "\nStatic Constructor", __staticCount
    # Instance Read-Only Property    
    # Within instance members, you can always use      
    # the "self" reference pointer to access your (instance) members.              
    def getInstanceCount(self):   
        return self.__instanceCount  
    InstanceCount = property(getInstanceCount, None, None)
    # Static Property
    # looks like it is not supported even if the code identify it as such    
    @staticmethod
    def getStaticCount():        
        return Fiborial.__staticCount        
    #StaticCount = property(getStaticCount, None, None)
    # The problem seems to be the use of: property(getStaticCount,..)
    # it requires an instance method and not a static one (Test.getStaticCount)    
    # Instance Constructor    
    def __init__(self):
        self.__instanceCount = 0    
        print "\nInstance Constructor", self.__instanceCount
    # No Static Constructor    
    #@staticmethod
    #def __init__():
    #    Fiborial.__staticCount = 0
    #    print "\nStatic Constructor", Fiborial.__staticCount
    # Instance Method
    def factorial(self, n):
        self.__instanceCount += 1   
        print "\nFactorial(" + str(n) + ")"
    # Static Method
    @staticmethod    
    def fibonacci(n):
        Fiborial.__staticCount += 1  
        print "\nFibonacci(" + str(n) + ")"

def main():
    # Calling Static Constructor and Methods    
    # No need to instantiate    
    Fiborial.fibonacci(5)  
      
    # Calling Instance Constructor and Methods    
    # Instance required    
    fib = Fiborial()    
    fib.factorial(5)  

    Fiborial.fibonacci(15)  
    fib.factorial(5)  
      
    # Calling Instance Constructor and Methods    
    # for a second object    
    fib2 = Fiborial()  
    fib2.factorial(5)  
      
    print ""  
    # Calling Static Property
    # using the static method referenced by the property
    #print "Static Count =", Fiborial.StaticCount
    print "Static Count =", Fiborial.getStaticCount()
    # Calling Instance Property of object 1 and 2    
    print "Instance 1 Count =", fib.InstanceCount
    print "Instance 2 Count =", fib2.InstanceCount
      
    Console.Read()  
  
if __name__ == '__main__':
    main()
&lt;/pre&gt;&lt;br /&gt;
And the Output is:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-NBK3O44FDgM/TiMOK6bvXNI/AAAAAAAAF-k/LqiPbjt45Bg/s1600/FiborialExtras2IPy.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="320" src="http://1.bp.blogspot.com/-NBK3O44FDgM/TiMOK6bvXNI/AAAAAAAAF-k/LqiPbjt45Bg/s320/FiborialExtras2IPy.png" width="302" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://2.bp.blogspot.com/_0_HCzHGe4_k/TJYz5ZgkFGI/AAAAAAAAFwk/Y8rwLu2Bags/s1600/output_ipy_ext.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;br /&gt;
&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Factorial using int, float, System.Numerics.BigInteger&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
So, it looks like integers in python can hold big integers, so using (Iron)Python int/long or System.Numerics.BigInteger is the same so not much to say here.&lt;br /&gt;
&lt;br /&gt;
NOTE: as with the previous scripts you need to manually add a reference to the System.Numerics.dll assembly to your project &amp;nbsp; or SearchPath + clr.AddReference &amp;nbsp;so you can add it to your code.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="python" name="code"&gt;import clr
clr.AddReference('System.Numerics.dll')
from System.Numerics import BigInteger
from System import Console
from System.Diagnostics import Stopwatch
  
# Int/Long Factorial  
def factorial_int(n):  
    if n == 1:
        return int(1)
    else:  
        return int(n * factorial_int(n - 1))
      
# double/float Factorial
def factorial_float(n):
    if n == 1:
        return float(1.0)
    else:  
        return float(n * factorial_int(n - 1))

# BigInteger Factorial     
def factorial_bigint(n):
    if n == 1:
        return BigInteger.One            
    else:            
        return BigInteger.Multiply(BigInteger(n), factorial_bigint(n-1))
  
timer = Stopwatch()  
facIntResult = 0
facDblResult = 0.0  
facBigResult = BigInteger.Zero
i = 0  
      
print "\nFactorial using Int/Long"
# Benchmark Factorial using Int64    

for i in range(5,55,5):  
    timer.Start()
    facIntResult = factorial_int(i)
    timer.Stop()          
    print " (" + str(i) + ") =", timer.Elapsed, " :", facIntResult  
      
print "\nFactorial using Float/Double"  
# Benchmark Factorial using Double  
for i in range(5,55,5):
    timer.Start()  
    facDblResult = factorial_float(i)  
    timer.Stop()          
    print " (" + str(i) + ") =", timer.Elapsed, " :", facDblResult
      
print "\nFactorial using BigInteger"  
# Benchmark Factorial using BigInteger  
for i in range(5,55,5):  
    timer.Start()
    facBigResult = factorial_bigint(i)  
    timer.Stop()
    print " (" + str(i) + ") =", timer.Elapsed, " :", facBigResult    

Console.Read()
&lt;/pre&gt;&lt;br /&gt;
And the Output is:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-AVvFlDHlo4U/Tht52dZ7khI/AAAAAAAAF78/uZkSvNryWIc/s1600/FiborialExtrasIPy3.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="516" src="http://3.bp.blogspot.com/-AVvFlDHlo4U/Tht52dZ7khI/AAAAAAAAF78/uZkSvNryWIc/s640/FiborialExtrasIPy3.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/694679611587040520-275433060648050337?l=carlosqt.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/yGOztUZC6P1etQNU4oGFxhzOMig/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/yGOztUZC6P1etQNU4oGFxhzOMig/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/yGOztUZC6P1etQNU4oGFxhzOMig/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/yGOztUZC6P1etQNU4oGFxhzOMig/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/CarlosQuintanillasBlog/~4/Zu_I07lCxWc" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://carlosqt.blogspot.com/feeds/275433060648050337/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://carlosqt.blogspot.com/2011/07/factorial-and-fibonacci-in-ironpython.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/694679611587040520/posts/default/275433060648050337?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/694679611587040520/posts/default/275433060648050337?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/CarlosQuintanillasBlog/~3/Zu_I07lCxWc/factorial-and-fibonacci-in-ironpython.html" title="Factorial and Fibonacci in IronPython" /><author><name>Carlos QT</name><uri>http://www.blogger.com/profile/15415604076909500411</uri><email>carlosqt@gmail.com</email><gd:extendedProperty name="OpenSocialUserId" value="14144067369073378952" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/-tnqFKsQMzR0/ThX8SkT41vI/AAAAAAAAF7g/rGR8Fwnh9a8/s72-c/FiborialIPy.png" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://carlosqt.blogspot.com/2011/07/factorial-and-fibonacci-in-ironpython.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CU8GSHw5eip7ImA9WhZUEE8.&quot;"><id>tag:blogger.com,1999:blog-694679611587040520.post-2121608085704135337</id><published>2011-06-02T07:10:00.000-07:00</published><updated>2011-06-02T07:10:29.222-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-06-02T07:10:29.222-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Cobra" /><category scheme="http://www.blogger.com/atom/ns#" term="CLR" /><title>Factorial and Fibonacci in Cobra</title><content type="html">&lt;a class="twitter-share-button" data-count="horizontal" data-via="carlosqt" href="http://twitter.com/share"&gt;Tweet&lt;/a&gt;&lt;script src="http://platform.twitter.com/widgets.js" type="text/javascript"&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;br /&gt;
Here below a little program in Cobra that implements 2 classes (in fact, they are 3). There is the main class, called Fiborial (Fibo(nnacci)+(Facto)rial) that implements the &lt;i&gt;Fibonacci&lt;/i&gt; and the &lt;i&gt;Factorial&lt;/i&gt; algorithms in two ways, one &lt;i&gt;Recursive&lt;/i&gt; (using recursion) and the other &lt;i&gt;Imperative&lt;/i&gt; (using loops and states). The second class is just an instance class that does the same thing, but its there just to show the difference between static and instance classes, and finally the third one (which will not appear in other languages) is the Program class which has the static execution method "Main".&lt;br /&gt;
&lt;br /&gt;
You can also find 3 more little examples at the bottom. One prints out the Factorial's Series and Fibonacci's Series, the second one just shows a class that mixes both: static and instance members, and finally the third one that uses different return types (including System.Numerics.BigInteger) for the Factorial method to compare the timing and result.&lt;br /&gt;
&lt;br /&gt;
As with the previous posts, you can copy and paste the code below in your favorite IDE/Editor and start playing and learning with it. This little "working" program will teach you some more basics of the Programming Language.&lt;br /&gt;
&lt;br /&gt;
There are some "comments" on the code added just to tell you what are or how are some features called. In case you want to review the theory, you can read my previous post, where I give a definition of each of the concepts mentioned on the code. You can find it here: &lt;a href="http://carlosqt.blogspot.com/2011/01/new-series-factorial-and-fibonacci.html"&gt;http://carlosqt.blogspot.com/2011/01/new-series-factorial-and-fibonacci.html&lt;/a&gt;&amp;nbsp;&lt;a href="http://carlosqt.blogspot.com/2010/08/new-series-languages-basics-by-example.html"&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;The Fiborial Program&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="csharp" name="code"&gt;# Factorial and Fibonacci in Cobra  
use System.Collections.Generic  
use System.Diagnostics  
use System.Numerics  

namespace FiborialCobra
  
    # Static Class
    class StaticFiborial is public
        shared
            # Static Field  
            var __className as String  
            # Static Constructor  
            cue init
                __className = 'Static Constructor'
                print '[__className]'
            # Static Method - Factorial Recursive    
            def factorialR(n as int) as BigInteger is public
                if n == 1 
                    return BigInteger.one
                else                        
                    return BigInteger.multiply(BigInteger(n), .factorialR(n - 1))
            # Static Method - Factorial Imperative    
            def factorialI(n as int) as BigInteger is public                
                res as BigInteger = BigInteger.one
                for i as int in n:0:-1
                    res = BigInteger.multiply(res, BigInteger(i))
                return res
            # Static Method - Fibonacci Recursive    
            def fibonacciR(n as int) as int64 is public
                if n &amp;lt; 2  
                    return 1
                else    
                    return .fibonacciR(n - 1) + .fibonacciR(n - 2)  
            # Static Method - Fibonacci Imperative  
            def fibonacciI(n as int) as int64 is public  
                pre as int64 = 1  
                cur as int64 = 1  
                tmp as int64 = 0  
                for i as int in 2:n+1
                    tmp = cur + pre
                    pre = cur  
                    cur = tmp  
                    i=i # ignore compiler warning
                return cur
            # Static Method - Benchmarking Algorithms  
            def benchmarkAlgorithm(algorithm as int, values as List&amp;lt;of int&amp;gt;) is public  
                timer as Stopwatch = Stopwatch()  
                i as int = 0
                testValue as int = 0  
                facTimeResult as BigInteger = BigInteger.zero                
                fibTimeResult as int64 = 0
                facTimeResult = facTimeResult
                fibTimeResult = fibTimeResult
                
                # "if-elif-else" Flow Control Statement
                if algorithm == 1  
                    print '\nFactorial Imperative:'
                    # "For in range" Loop Statement   
                    for i as int in values.count                  
                        testValue = values[i]
                        # Taking Time    
                        timer.start  
                        facTimeResult = .factorialI(testValue)  
                        timer.stop
                        # Getting Time    
                        print ' ([testValue]) = [timer.elapsed]'
                else if algorithm == 2  
                    print '\nFactorial Recursive:'
                    # "While" Loop Statement  
                    while i &amp;lt; values.count
                        testValue = values[i]  
                        # Taking Time    
                        timer.start
                        facTimeResult = .factorialR(testValue)
                        timer.stop
                        # Getting Time    
                        print ' ([testValue]) = [timer.elapsed]'
                        i += 1  
                else if algorithm == 3
                    print "\nFibonacci Imperative:"   
                    # "Do-While" Loop Statement  
                    post while i &amp;lt; values.count
                        testValue = values[i]  
                        # Taking Time  
                        timer.start
                        fibTimeResult = .fibonacciI(testValue)  
                        timer.stop  
                        # Getting Time  
                        print ' ([testValue]) = [timer.elapsed]'
                        i += 1  
                else if algorithm == 4  
                    print "\nFibonacci Recursive:"  
                    # "For in List" Loop Statement   
                    for i as int in values.count
                        testValue = values[i]
                        # Taking Time  
                        timer.start 
                        fibTimeResult = .fibonacciR(testValue)  
                        timer.stop
                        # Getting Time  
                        print ' ([testValue]) = [timer.elapsed]'
                else  
                    print 'DONG!'

    # Instance Class  
    class InstanceFiborial is public
        # Instances Field  
        var __className as String  
        # Instance Constructor  
        cue init  
            base.init
            __className = "Instance Constructor"  
            print __className  
        # Instance Method - Factorial Recursive  
        def factorialR(n as int) as BigInteger is public 
            # Calling Static Method  
            return StaticFiborial.factorialR(n)  
        # Instance Method - Factorial Imperative  
        def factorialI(n as int) as BigInteger is public 
            # Calling Static Method  
            return StaticFiborial.factorialI(n)  
        # Instance Method - Fibonacci Recursive    
        def fibonacciR(n as int) as int64 is public
            # Calling Static Method  
            return StaticFiborial.fibonacciR(n)  
        # Instance Method - Fibonacci Imperative  
        def fibonacciI(n as int) as int64 is public  
            # Calling Static Method  
            return StaticFiborial.fibonacciI(n)  
                    
    # Console Program  
    class Program is public  
        def main is shared 
            print '\nStatic Class'  
            # Calling Static Class and Methods  
            # No instantiation needed. Calling method directly from the class  
            print 'FacImp(5) = [StaticFiborial.factorialI(5)]'  
            print 'FacRec(5) = [StaticFiborial.factorialR(5)]'  
            print 'FibImp(11)= [StaticFiborial.fibonacciI(11)]'  
            print 'FibRec(11)= [StaticFiborial.fibonacciR(11)]'  
          
            print '\nInstance Class'  
            # Calling Instance Class and Methods  
            # Need to instantiate before using. Call method from instantiated obj  
            ff as InstanceFiborial = InstanceFiborial()
            print 'FacImp(5) = [ff.factorialI(5)]'  
            print 'FacRec(5) = [ff.factorialR(5)]'  
            print 'FibImp(11)= [ff.fibonacciI(11)]'  
            print 'FibRec(11)= [ff.fibonacciR(11)]'  
          
            # Create a List of integer values to test  
            # From 5 to 50 by 5  
            values as List&amp;lt;of int&amp;gt; = List&amp;lt;of int&amp;gt;()  
            for i as int in 5:55:5
                values.add(i)

            # Benchmarking Fibonacci  
            # 1 = Factorial Imperative  
            StaticFiborial.benchmarkAlgorithm(1, values)  
            # 2 = Factorial Recursive  
            StaticFiborial.benchmarkAlgorithm(2, values)  
            # Benchmarking Factorial  
            # 3 = Fibonacci Imperative  
            StaticFiborial.benchmarkAlgorithm(3, values)  
            # 4 = Fibonacci Recursive  
            StaticFiborial.benchmarkAlgorithm(4, values)
          
            # Stop and Exit  
            Console.read
&lt;/pre&gt;&lt;br /&gt;
And the Output is: &lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-Lj5qDjfbtfg/TeeZH2K6ZcI/AAAAAAAAF6s/OxsUisdbE4M/s1600/fiborial_cobra.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="640" src="http://1.bp.blogspot.com/-Lj5qDjfbtfg/TeeZH2K6ZcI/AAAAAAAAF6s/OxsUisdbE4M/s640/fiborial_cobra.PNG" width="268" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;a href="http://2.bp.blogspot.com/_0_HCzHGe4_k/TM8Wwm7ILyI/AAAAAAAAFyQ/AziXveRyTGo/s1600/output_delphi.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;br /&gt;
&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Humm, looks like Fibonnaci's algorithm implemented using recursion is definitively more complex than the others 3 right? I will grab these results for this and each of the upcoming posts to prepare a comparison of time execution between all the programming languages, then we will be able to talk about the algorithm's complexity as well.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Printing the Factorial and Fibonacci Series&lt;/b&gt;&lt;br /&gt;
&lt;pre class="csharp" name="code"&gt;use System.Text  
use System.Numerics  

namespace FiborialSeries   
    # Instance Class    
    class Fiborial is public
        shared
            # Using a StringBuilder as a list of string elements    
            def getFactorialSeries(n as int) as String is public
                # Create the String that will hold the list    
                series as StringBuilder = StringBuilder()   
                # We begin by concatenating the number you want to calculate    
                # in the following format: '!# ='    
                series.append('!')  
                series.append(n)  
                series.append(' = ')  
                # We iterate backwards through the elements of the series    
                for i as int in n:0:-1  
                    # and append it to the list    
                    series.append(i)  
                    if i &amp;gt; 1   
                        series.append(' * ')    
                    else  
                        series.append(' = ')  
                # Get the result from the Factorial Method    
                # and append it to the end of the list    
                series.append(.factorial(n))  
                # return the list as a string    
                return series.toString 
          
            # Using a StringBuilder as a list of string elements    
            def getFibonnaciSeries(n as int) as String is public
                # Create the String that will hold the list
                series as StringBuilder = StringBuilder()   
                # We begin by concatenating the first 3 values which    
                # are always constant    
                series.append('0, 1, 1')    
                # Then we calculate the Fibonacci of each element    
                # and add append it to the list    
                for i as int in 2:n+1
                    if i &amp;lt; n  
                        series.append(', ')   
                    else
                        series.append(' = ')    
                    series.append(.fibonacci(i))  
                # return the list as a string    
                return series.toString 
                  
            def factorial(n as int) as BigInteger is public
                if n == 1
                    return BigInteger.one
                else
                    return BigInteger.multiply(BigInteger(n), .factorial(n - 1))
              
            def fibonacci(n as int) as int64 is public
                if n &amp;lt; 2
                    return 1    
                else    
                    return .fibonacci(n - 1) + .fibonacci(n - 2)  
      
    # Console Program  
    class Program is public  
        def main is shared 
            # Printing Factorial Series    
            print ''  
            print Fiborial.getFactorialSeries(5)  
            print Fiborial.getFactorialSeries(7)  
            print Fiborial.getFactorialSeries(9)  
            print Fiborial.getFactorialSeries(11)  
            print Fiborial.getFactorialSeries(40)  
            # Printing Fibonacci Series    
            print ''  
            print Fiborial.getFibonnaciSeries(5)  
            print Fiborial.getFibonnaciSeries(7)  
            print Fiborial.getFibonnaciSeries(9)  
            print Fiborial.getFibonnaciSeries(11)  
            print Fiborial.getFibonnaciSeries(40)  
              
            Console.read
&lt;/pre&gt;&lt;br /&gt;
And the Output is:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-kbLSRzBwIDE/TeeZN1_AbxI/AAAAAAAAF6w/AMhipV69jm0/s1600/fiborial_cobra_extras_series.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="282" src="http://2.bp.blogspot.com/-kbLSRzBwIDE/TeeZN1_AbxI/AAAAAAAAF6w/AMhipV69jm0/s640/fiborial_cobra_extras_series.PNG" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Mixing Instance and Static Members in the same Class&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Instance classes can contain both, instance and static members such as: fields, properties, constructors, methods, etc.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="csharp" name="code"&gt;namespace FiborialExtrasCobra2  
      
    # Instance Classes can have both: static and instance members.
          
    # Instance Class    
    class Fiborial is public  
        # Instance Field  
        var __instanceCount as int
        # Static Field  
        var __staticCount as int is shared 
        # Instance Read-Only Property            
        pro instanceCount as int is public  
            get  
                return __instanceCount          
        # Static Read-Only Property    
        # Remeber that Properties are Methods to the CLR, so, 
        # you can also define static properties for static fields.             
        pro staticCount as int is shared, public
            get    
                return __staticCount    
        # Instance Constructor    
        cue init
            base.init
            __instanceCount = 0
            print '\nInstance Constructor [__instanceCount]'  
        # Static Constructor    
        cue init is shared        
            __staticCount = 0    
            print '\nStatic Constructor [__staticCount]'
        # Instance Method  
        def factorial(n as int) is public
            __instanceCount += 1   
            print '\nFactorial([n])'   
        # Static Method    
        def fibonacci(n as int) is shared, public
            __staticCount += 1  
            print '\nFibonacci([n])'   
      
    # Console Program  
    class Program is public
        def main is shared     
            # Calling Static Constructor and Methods    
            # No need to instantiate    
            Fiborial.fibonacci(5)  
              
            # Calling Instance Constructor and Methods    
            # Instance required    
            fib as Fiborial = Fiborial()    
            fib.factorial(5)  
              
            Fiborial.fibonacci(15)  
            fib.factorial(5)  
              
            # Calling Instance Constructor and Methods    
            # for a second object    
            fib2 as Fiborial = Fiborial()  
            fib2.factorial(5)  
              
            print ''  
            # Calling Static Property    
            print 'Static Count = [Fiborial.staticCount]'  
            # Calling Instance Property of object 1 and 2    
            print 'Instance 1 Count = [fib.instanceCount]'  
            print 'Instance 2 Count = [fib2.instanceCount]'  
            Console.read
&lt;/pre&gt;&lt;br /&gt;
And the Output is:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-LcVR31CzHi0/TeeZPqzTLfI/AAAAAAAAF60/aCUZ_b2cqVI/s1600/fiborial_cobra_extras2.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="350" src="http://3.bp.blogspot.com/-LcVR31CzHi0/TeeZPqzTLfI/AAAAAAAAF60/aCUZ_b2cqVI/s400/fiborial_cobra_extras2.PNG" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;a href="http://4.bp.blogspot.com/_0_HCzHGe4_k/TM8x5bVLv0I/AAAAAAAAFyU/ZHtgJE97Fdk/s1600/delphi_properties.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;br /&gt;
&lt;/a&gt;&lt;a href="http://2.bp.blogspot.com/_0_HCzHGe4_k/TJYz5ZgkFGI/AAAAAAAAFwk/Y8rwLu2Bags/s1600/output_ipy_ext.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;br /&gt;
&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Factorial using System.Int64, System.Double/Float, System.Numerics.BigInteger&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
The Factorial of numbers over 20 are massive!&lt;br /&gt;
For instance: !40 = 815915283247897734345611269596115894272000000000!&lt;br /&gt;
Because of this, the previous version of this program was giving the "wrong" result &lt;br /&gt;
!40 = -70609262346240000 when using "long" (System.Int64) type, but it was not until I did the Fiborial version in VB.NET that I realized about this faulty code, because instead of giving me a wrong value, VB.NET, JScript.NET, Boo execution thrown an Overflow Exception when using the "Long/long" (System.Int64) type.&lt;br /&gt;
&lt;br /&gt;
My first idea was to use ulong and ULong, but both failed for "big" numbers. I then used Double (double floating point) type and got no more exception/wrong result. The result of the factorial was now correct !40 = 1.1962222086548E+56, but still I wanted to show the Integer value of it, so I did some research and found that there is a new System.Numerics.BigInteger class in the .NET Framework 4.0. Adding the reference to the project and using this new class as the return type of the Factorial methods, I was able to get the result I was expecting.&lt;br /&gt;
!40 = 815915283247897734345611269596115894272000000000&lt;br /&gt;
&lt;br /&gt;
What I also found was that using different types change the time the algorithm takes to finish:&lt;br /&gt;
System.Int64 &amp;lt; System.Double &amp;lt; System.Numerics.BigInteger  &lt;br /&gt;
Almost by double!&lt;br /&gt;
&lt;br /&gt;
To illustrate what I just "tried" to say, lets have a look at the following code and the output we get.  &lt;br /&gt;
&lt;br /&gt;
&lt;pre class="csharp" name="code"&gt;use System.Diagnostics  
use System.Numerics  

namespace FiborialExtrasBoo3  

    class FiborialExtrasProgram 
        shared            

            def main
                timer as Stopwatch = Stopwatch()  
                facIntResult as int64 = 0  
                facDblResult as float = 0  
                facBigResult as BigInteger = BigInteger.zero
                i as int = 0
                  
                print '\nFactorial using Int64'  
                # Benchmark Factorial using Int64                    
                for i as int in 5:55:5  
                    timer.start
                    facIntResult = .factorialInt64(i)  
                    timer.stop         
                    print ' ([i]) = [timer.elapsed] : [facIntResult]'  
                  
                print '\nFactorial using Float'  
                # Benchmark Factorial using float  
                for i as int in 5:55:5  
                    timer.start
                    facDblResult = .factorialFloat(i)  
                    timer.stop         
                    print ' ([i]) = [timer.elapsed] : [facDblResult]'  
                  
                print '\nFactorial using BigInteger'  
                # Benchmark Factorial using BigInteger  
                for i as int in 5:55:5  
                    timer.start
                    facBigResult = .factorialBigInteger(i)  
                    timer.stop         
                    print ' ([i]) = [timer.elapsed] : [facBigResult]'  
                  
                Console.read
                
            # Long Factorial  
            def factorialInt64(n as int) as int64
                if n == 1  
                    return 1  
                else  
                    return n * .factorialInt64(n - 1)  
                  
            # float/Number Factorial     
            def factorialFloat(n as int) as float
                if n == 1  
                    return 1  
                else  
                    return n * .factorialFloat(n - 1)  
               
            # BigInteger Factorial     
            def factorialBigInteger(n as int) as BigInteger   
                if n == 1  
                    return BigInteger.one  
                else  
                    return BigInteger.multiply(BigInteger(n), .factorialBigInteger(n - 1))
&lt;/pre&gt;&lt;br /&gt;
NOTE: you need to manually add a reference to the System.Numerics.dll assembly to your project so you can add it to your code.&lt;br /&gt;
&lt;br /&gt;
And the Output is:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-8TTodOsnGuQ/TeeZRQ-VxJI/AAAAAAAAF64/-KBFEytAc-s/s1600/fiborial_cobra_extras_big_int.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="490" src="http://2.bp.blogspot.com/-8TTodOsnGuQ/TeeZRQ-VxJI/AAAAAAAAF64/-KBFEytAc-s/s640/fiborial_cobra_extras_big_int.PNG" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/694679611587040520-2121608085704135337?l=carlosqt.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/-0KBRSoNHxkvbGz4m5O92fEEjpg/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/-0KBRSoNHxkvbGz4m5O92fEEjpg/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/-0KBRSoNHxkvbGz4m5O92fEEjpg/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/-0KBRSoNHxkvbGz4m5O92fEEjpg/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/CarlosQuintanillasBlog/~4/VW3gHanyLa8" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://carlosqt.blogspot.com/feeds/2121608085704135337/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://carlosqt.blogspot.com/2011/06/factorial-and-fibonacci-in-cobra.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/694679611587040520/posts/default/2121608085704135337?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/694679611587040520/posts/default/2121608085704135337?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/CarlosQuintanillasBlog/~3/VW3gHanyLa8/factorial-and-fibonacci-in-cobra.html" title="Factorial and Fibonacci in Cobra" /><author><name>Carlos QT</name><uri>http://www.blogger.com/profile/15415604076909500411</uri><email>carlosqt@gmail.com</email><gd:extendedProperty name="OpenSocialUserId" value="14144067369073378952" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/-Lj5qDjfbtfg/TeeZH2K6ZcI/AAAAAAAAF6s/OxsUisdbE4M/s72-c/fiborial_cobra.PNG" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://carlosqt.blogspot.com/2011/06/factorial-and-fibonacci-in-cobra.html</feedburner:origLink></entry><entry gd:etag="W/&quot;Dk8FQX46eyp7ImA9WhZVFEk.&quot;"><id>tag:blogger.com,1999:blog-694679611587040520.post-7336081667902266861</id><published>2011-05-15T15:56:00.001-07:00</published><updated>2011-05-26T14:20:10.013-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-05-26T14:20:10.013-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Java" /><category scheme="http://www.blogger.com/atom/ns#" term="JVM" /><title>Stopwatch class for Java</title><content type="html">&lt;a class="twitter-share-button" data-count="horizontal" data-via="carlosqt" href="http://twitter.com/share"&gt;Tweet&lt;/a&gt;&lt;script src="http://platform.twitter.com/widgets.js" type="text/javascript"&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;br /&gt;
In order to continue with my next "Factorial and Fibonacci" posts in some Java/JVM languages; I was looking for an official Java version of the .NET Timer class "Stopwatch" (System.Diagnostics.Stopwatch), so I can measure and display the elapsed time results in the same way I had been doing it in my previous posts. &lt;br /&gt;
&lt;br /&gt;
Let's show some C# code of what I meant before continuing.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="csharp" name="code"&gt;using System;
using System.Numerics;
using System.Diagnostics;

namespace CSStopwatchApp
{
    class StopwatchApp
    {
        static void Main(string[] args)
        {
            Stopwatch timer = new Stopwatch();
            timer.Start();
            Fibonacci(50);
            timer.Stop();

            Console.WriteLine("Elapsed time in ticks: {0}", 
                timer.Elapsed.Ticks);
            Console.WriteLine("Elapsed time in milliseconds: {0}", 
                timer.Elapsed.Milliseconds);
            Console.WriteLine("Elapsed time in seconds: {0}", 
                timer.Elapsed.Seconds);
            Console.WriteLine("Elapsed time in minutes: {0}", 
                timer.Elapsed.Minutes);
            Console.WriteLine("Elapsed time in hours: {0}", 
                timer.Elapsed.Hours);
            Console.WriteLine("Elapsed time with format: {0}", 
                timer.Elapsed);
        }
                
        private static BigInteger Fibonacci(int n)
        {
            if (n &amp;lt; 2)
                return 1;
            else
                return Fibonacci(n - 1) + Fibonacci(n - 2);
        }
    }
}
&lt;/pre&gt;&lt;br /&gt;
And the result:&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-OpaXn-_3hqE/Tcsjx0Dc0DI/AAAAAAAAF54/CXmaGtLBx6M/s1600/StopwatchFib50_csharp.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="198" src="http://1.bp.blogspot.com/-OpaXn-_3hqE/Tcsjx0Dc0DI/AAAAAAAAF54/CXmaGtLBx6M/s640/StopwatchFib50_csharp.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
However, looks like there isn't one, instead, there are 2 methods used to measure time in Java: System.nanoTime() and System.currentTimeMillis() being the first one more precise when timing code execution.&lt;br /&gt;
&lt;br /&gt;
&lt;hr /&gt;&lt;b&gt;currentTimeMillis&lt;/b&gt;&lt;br /&gt;
&lt;pre class="java" name="code"&gt;public static long currentTimeMillis()
&lt;/pre&gt;Returns the current time in milliseconds. Note that while the unit of time of the return value is a millisecond, the granularity of the value depends on the underlying operating system and may be larger. For example, many operating systems measure time in units of tens of milliseconds. &lt;br /&gt;
&lt;br /&gt;
For example, to measure how long some code takes to execute: &lt;br /&gt;
&lt;pre class="java" name="code"&gt;long startTime = System.currentTimeMillis();
   // ... the code being measured ...
   long estimatedTime = System.currentTimeMillis() - startTime;
&lt;/pre&gt;&lt;br /&gt;
Returns:&lt;br /&gt;
the difference, measured in milliseconds, between the current time and midnight, January 1, 1970 UTC.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;nanoTime&lt;/b&gt;&lt;br /&gt;
&lt;pre class="java" name="code"&gt;public static long nanoTime()
&lt;/pre&gt;Returns the current value of the most precise available system timer, in nanoseconds. &lt;br /&gt;
&lt;br /&gt;
This method can only be used to measure elapsed time and is not related to any other notion of system or wall-clock time. The value returned represents nanoseconds since some fixed but arbitrary time (perhaps in the future, so values may be negative). This method provides nanosecond precision, but not necessarily nanosecond accuracy. No guarantees are made about how frequently values change. Differences in successive calls that span greater than approximately 292 years (263 nanoseconds) will not accurately compute elapsed time due to numerical overflow. &lt;br /&gt;
&lt;br /&gt;
For example, to measure how long some code takes to execute: &lt;br /&gt;
&lt;pre class="java" name="code"&gt;long startTime = System.nanoTime();
   // ... the code being measured ...
   long estimatedTime = System.nanoTime() - startTime;
 &lt;/pre&gt;&lt;br /&gt;
Returns:&lt;br /&gt;
The current value of the system timer, in nanoseconds.&lt;br /&gt;
&lt;hr /&gt;&lt;br /&gt;
So, I decided to do my own version of the Stopwatch class, not before doing some google to see if someone did it already ;) you know, code reuse FTW!&lt;br /&gt;
&lt;br /&gt;
Quickly I found a basic version using System.currentTimeMillis() written by Corey Goldberg and provided with a GPL license here: &lt;a href="http://www.goldb.org/stopwatchjava.html"&gt;http://www.goldb.org/stopwatchjava.html&lt;/a&gt; (thanks man!), so I took it and extended it to use System.nanoTime() instead, and implemented some other missing methods and the most important (for me) the Elapsed time formatted as "hh:mm:ss.sss" using the SimpleDateFormat class, which looks like only considers 3 milliseconds... so I added the rest (the nanoseconds part) to have: 00:00:00.0000000 (hh:mm:ss.sssssss), just like the .NET version output it. Here it is:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Stopwatch class in Java&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="java" name="code"&gt;/*
 *  Copyright (c) 2011, Carlos Quintanilla
 *  Special thanks to Corey Goldberg (for his StopWatch.java | Java Timer Class)
 *  here http://www.goldb.org/stopwatchjava.html
 * 
 *  Stopwatch.java is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 */

package stopwatchapp;

import java.text.SimpleDateFormat;
import java.util.Calendar;  

/**
 * @author Carlos Quintanilla
 */

public class Stopwatch {
    // constants
    private final long nsPerTick = 100;
    private final long nsPerMs = 1000000;
    private final long nsPerSs = 1000000000;
    private final long nsPerMm = 60000000000L;
    private final long nsPerHh = 3600000000000L;

    private long startTime = 0;
    private long stopTime = 0;
    private boolean running = false;
    
    /**
     * Starts measuring elapsed time
     * for an interval.
     */
    public void start() {
        this.startTime = System.nanoTime();       
        this.running = true;
    }
    
    /**
     * Stops measuring elapsed time
     * for an interval.
     */
    public void stop() {
        this.stopTime = System.nanoTime();
        this.running = false;
    }
    
    /**
     * Stops time interval measurement 
     * and resets the elapsed time to zero.
     */ 
    public void reset() {
        this.startTime = 0;
        this.stopTime = 0;
        this.running = false;
    }
    
    /**
     * Gets the total elapsed time measured 
     * by the current instance, in nanoseconds.
     * 1 Tick = 100 nanoseconds 
     */
    public long getElapsedTicks() {
        long elapsed;
        if (running) {
             elapsed = (System.nanoTime() - startTime);
        }
        else {
            elapsed = (stopTime - startTime);
        }
        return elapsed / nsPerTick;
    }
    
    /**
     * Gets the total elapsed time measured 
     * by the current instance, in milliseconds.
     * 10000 Ticks = 1 millisecond (1000000 nanoseconds)
     */
    public long getElapsedMilliseconds() {
        long elapsed;
        if (running) {
             elapsed = (System.nanoTime() - startTime);
        }
        else {
            elapsed = (stopTime - startTime);
        }
        return elapsed / nsPerMs;
    }
    
    /**
     * Gets the total elapsed time measured 
     * by the current instance, in seconds.
     * 10000000 Ticks = 1 second (1000 milliseconds)
     */
    public long getElapsedSeconds() {
        long elapsed;
        if (running) {
             elapsed = (System.nanoTime() - startTime);
        }
        else {
            elapsed = (stopTime - startTime);
        }        
        return elapsed / nsPerSs;
    }
    
    /**
     * Gets the total elapsed time measured 
     * by the current instance, in minutes.
     * 600000000 Ticks = 1 minute (60 seconds)
     */
    public long getElapsedMinutes() {
        long elapsed;
        if (running) {
             elapsed = (System.nanoTime() - startTime);
        }
        else {
            elapsed = (stopTime - startTime);
        }        
        return elapsed / nsPerMm;
    }
    
    /**
     * Gets the total elapsed time measured 
     * by the current instance, in hours.
     * 36000000000 Ticks = 1 hour (60 minutes)
     */
    public long getElapsedHours() {
        long elapsed;
        if (running) {
             elapsed = (System.nanoTime() - startTime);
        }
        else {
            elapsed = (stopTime - startTime);
        }        
        return elapsed / nsPerHh;
    }
    
    /**
     * Gets the total elapsed time with format 
     * 00:00:00.0000000 = 00:mm:ss.SSS + 9999 Ticks
     */ 
    public String getElapsed() {
        String timeFormatted = "";
        timeFormatted = this.formatTime(this.getElapsedTicks());        
        return timeFormatted;
    }
    
    /**
     * Gets the total elapsed time with format 
     * 00:00:00.0000000 = 00:mm:ss.SSS + #### Ticks
     * @param elapsedTicks elapsed ticks between start and stop nano time
     */ 
    private String formatTime(final long elapsedTicks) {        
        String formattedTime = "";
        // should be hh:mm:ss.SSS, but 00 starts with 01 
        SimpleDateFormat formatter = new SimpleDateFormat("00:mm:ss.SSS");
        Calendar calendar = Calendar.getInstance();        
        
        if (elapsedTicks &amp;lt;= 9999) {
            calendar.setTimeInMillis(0);
            formattedTime = formatter.format(calendar.getTime()) 
                    + String.valueOf(String.format("%04d", elapsedTicks));
        }
        else {
            calendar.setTimeInMillis(elapsedTicks * nsPerTick / nsPerMs);            
            String formattedTicks = String.format("%07d", elapsedTicks);
            formattedTicks = formattedTicks.substring(formattedTicks.length() - 4);
            formattedTime = formatter.format(calendar.getTime()) + formattedTicks;
        }
        return formattedTime;
    }
}
&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
If we add that class in any Java project, we can now do what the C# code at the beginning of this post does! Let's see the Java version of the code:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="java" name="code"&gt;package stopwatchapp;
import java.math.BigInteger;

public class StopwatchApp {

    public static void main(String[] args) {
        
        Stopwatch timer = new Stopwatch();
        timer.start();
        Fibonacci(50);
        timer.stop();
        
        System.out.println("Elapsed time in ticks: " 
            + timer.getElapsedTicks());
        System.out.println("Elapsed time in milliseconds: " 
            + timer.getElapsedMilliseconds());
        System.out.println("Elapsed time in seconds: " 
            + timer.getElapsedSeconds());
        System.out.println("Elapsed time in minutes: " 
            + timer.getElapsedMinutes());
        System.out.println("Elapsed time in hours: " 
            + timer.getElapsedHours());
        System.out.println("Elapsed time with format: " 
            + timer.getElapsed());
    }
    
    private static BigInteger Fibonacci(int n)
    {
        if (n &amp;lt; 2)
            return BigInteger.ONE;
        else
            return Fibonacci(n - 1).add(Fibonacci(n - 2));
    }
}
&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
And the Output is: &lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-DyS62UU_nMU/Tcsn0ib4pmI/AAAAAAAAF6A/LHp8CZdmTQs/s1600/StopwatchFib50_java.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="238" src="http://4.bp.blogspot.com/-DyS62UU_nMU/Tcsn0ib4pmI/AAAAAAAAF6A/LHp8CZdmTQs/s640/StopwatchFib50_java.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
That's it! now I'm ready to work on the next posts using this java timer class. Hope it is helpful to you too since I found lot's of forums asking for it and the answer was always use: System.nanoTime() and System.currentTimeMillis() &lt;br /&gt;
&lt;br /&gt;
By the way, if you want to run the example, change Fibonacci(50) to a lower value such as Fibonacci(35 or 40) to not wait for the result some minutes.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/694679611587040520-7336081667902266861?l=carlosqt.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/BKclPEKxMvAjOLCFfPIbJS5VbEc/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/BKclPEKxMvAjOLCFfPIbJS5VbEc/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/BKclPEKxMvAjOLCFfPIbJS5VbEc/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/BKclPEKxMvAjOLCFfPIbJS5VbEc/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/CarlosQuintanillasBlog/~4/AnXKYivMiIE" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://carlosqt.blogspot.com/feeds/7336081667902266861/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://carlosqt.blogspot.com/2011/05/stopwatch-class-for-java.html#comment-form" title="2 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/694679611587040520/posts/default/7336081667902266861?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/694679611587040520/posts/default/7336081667902266861?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/CarlosQuintanillasBlog/~3/AnXKYivMiIE/stopwatch-class-for-java.html" title="Stopwatch class for Java" /><author><name>Carlos QT</name><uri>http://www.blogger.com/profile/15415604076909500411</uri><email>carlosqt@gmail.com</email><gd:extendedProperty name="OpenSocialUserId" value="14144067369073378952" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/-OpaXn-_3hqE/Tcsjx0Dc0DI/AAAAAAAAF54/CXmaGtLBx6M/s72-c/StopwatchFib50_csharp.png" height="72" width="72" /><thr:total>2</thr:total><feedburner:origLink>http://carlosqt.blogspot.com/2011/05/stopwatch-class-for-java.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D0QBQHo5eyp7ImA9WhZVFEk.&quot;"><id>tag:blogger.com,1999:blog-694679611587040520.post-1304605657994355004</id><published>2011-05-15T15:56:00.000-07:00</published><updated>2011-05-26T14:29:11.423-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-05-26T14:29:11.423-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Java" /><category scheme="http://www.blogger.com/atom/ns#" term="JVM" /><title>Factorial and Fibonacci in Java</title><content type="html">&lt;a class="twitter-share-button" data-count="horizontal" data-via="carlosqt" href="http://twitter.com/share"&gt;Tweet&lt;/a&gt;&lt;script src="http://platform.twitter.com/widgets.js" type="text/javascript"&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Here below a little program in Java that implements 2 classes (in fact, they are 3 + an extra utility Stopwatch class from my previous post &lt;a href="http://carlosqt.blogspot.com/2011/05/stopwatch-class-for-java.html"&gt;http://carlosqt.blogspot.com/2011/05/stopwatch-class-for-java.html&lt;/a&gt;). There is the main class, called Fiborial (Fibo(nnacci)+(Facto)rial) that implements the &lt;i&gt;Fibonacci&lt;/i&gt; and the &lt;i&gt;Factorial&lt;/i&gt; algorithms in two ways, one &lt;i&gt;Recursive&lt;/i&gt; (using recursion) and the other &lt;i&gt;Imperative&lt;/i&gt; (using loops and states). The second class is just an instance class that does the same thing, but its there just to show the difference between static and instance classes, and finally the third one (which will not appear in other languages) is the Program class which has the static execution method "main".&lt;br /&gt;
&lt;br /&gt;
You can also find 3 more little examples at the bottom. One prints out the Factorial's Series and Fibonacci's Series, the second one just shows a class that mixes both: static and instance members, and finally the third one that uses different return types (including java.math.BigInteger) for the Factorial method to compare the timing and result.&lt;br /&gt;
&lt;br /&gt;
As with the previous posts, you can copy and paste the code below in your favorite IDE/Editor and start playing and learning with it. This little "working" program will teach you some more basics of the Programming Language.&lt;br /&gt;
&lt;br /&gt;
There are some "comments" on the code added just to tell you what are or how are some features called. In case you want to review the theory, you can read my previous post, where I give a definition of each of the concepts mentioned on the code. You can find it here: &lt;a href="http://carlosqt.blogspot.com/2011/01/new-series-factorial-and-fibonacci.html"&gt;http://carlosqt.blogspot.com/2011/01/new-series-factorial-and-fibonacci.html&lt;/a&gt;&amp;nbsp;&lt;a href="http://carlosqt.blogspot.com/2010/08/new-series-languages-basics-by-example.html"&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;The Fiborial Program&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="java" name="code"&gt;// Factorial and Fibonacci in Java
package fiborial;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;

// Instance Class         
// static is not a class modifier in Java
public class StaticFiborial
{  
    // Static Field  
    private static String className;  
    // Static Constructor/Initializer
    static
    {  
        className = "Static Constructor";  
        System.out.println(className);        
    }  
    // Static Method - Factorial Recursive  
    public static BigInteger factorialR(int n)  
    {  
        if (n == 1)  
            return BigInteger.ONE;
        else  
            return BigInteger.valueOf(n).multiply(factorialR(n - 1));
    }  
    // Static Method - Factorial Imperative  
    public static BigInteger factorialI(int n)  
    {  
        BigInteger res = BigInteger.ONE;  
        for (int i = n; i &amp;gt;= 1; i--)  
        {                  
            res.multiply(BigInteger.valueOf(i));  
        }  
        return res;
    }  
    // Static Method - Fibonacci Recursive  
    public static long fibonacciR(int n)  
    {  
        if (n &amp;lt; 2)  
            return 1;  
        else  
            return fibonacciR(n - 1) + fibonacciR(n - 2);  
    }  
    // Static Method - Fibonacci Imperative  
    public static long fibonacciI(int n)  
    {              
        long pre, cur, tmp = 0;  
        pre = cur = 1;              
        for (int i = 2; i &amp;lt;= n; i++)  
        {  
            tmp = cur + pre;  
            pre = cur;  
            cur = tmp;  
        }  
        return cur;  
    }      
    // Static Method - Benchmarking Algorithms  
    // Static Method - Benchmarking Algorithms  
    public static void benchmarkAlgorithm(int algorithm, List&amp;lt;Integer&amp;gt; values)  
    {              
        Stopwatch timer = new Stopwatch();  
        int i, testValue;  
        BigInteger facTimeResult = BigInteger.valueOf(0);  
        long fibTimeResult = 0;  
        i = testValue = 0;              
          
        // "Switch" Flow Constrol Statement  
        switch (algorithm)  
        {  
            case 1:  
                System.out.println("\nFactorial Imperative:");  
                // "For" Loop Statement  
                for (i = 0; i &amp;lt; values.size(); i++)  
                {                          
                    testValue = ((Integer)values.get(i)).intValue();  
                    // Taking Time  
                    timer.start();  
                    facTimeResult = factorialI(testValue);  
                    timer.stop();                          
                    // Getting Time  
                    System.out.println(" (" + testValue + ") = " 
                        + timer.getElapsed());  
                }                      
                break;  
            case 2:  
                System.out.println("\nFactorial Recursive:");  
                // "While" Loop Statement  
                while (i &amp;lt; values.size())  
                {                          
                    testValue = ((Integer)values.get(i)).intValue();  
                    // Taking Time  
                    timer.start();  
                    facTimeResult = factorialR(testValue);  
                    timer.stop();  
                    // Getting Time  
                    System.out.println(" (" + testValue + ") = " 
                        + timer.getElapsed());  
                    i++;  
                }  
                break;  
            case 3:  
                System.out.println("\nFibonacci Imperative:");  
                // "Do-While" Loop Statement  
                do {  
                    testValue = ((Integer)values.get(i)).intValue();  
                    // Taking Time  
                    timer.start();  
                    fibTimeResult = fibonacciI(testValue);  
                    timer.stop();  
                    // Getting Time  
                    System.out.println(" (" + testValue + ") = " 
                        + timer.getElapsed());  
                    i++;  
                } while (i &amp;lt; values.size());  
                break;  
            case 4:  
                System.out.println("\nFibonacci Recursive:");  
                // "For Each" Loop Statement  
                for (Integer item : values)  
                {  
                    testValue = item;  
                    // Taking Time  
                    timer.start();  
                    fibTimeResult = fibonacciR(testValue);  
                    timer.stop();  
                    // Getting Time  
                    System.out.println(" (" + testValue + ") = " 
                        + timer.getElapsed());  
                }  
                break;  
            default:  
                System.out.println("DONG!");  
                break;  
        }                  
    }  
}
&lt;/pre&gt;&lt;br /&gt;
&lt;pre class="java" name="code"&gt;package fiborial;
import java.math.BigInteger;
// Instance Class  
public class InstanceFiborial  
{  
    // Instance Field  
    private String className;  
    // Instance Constructor  
    public InstanceFiborial()  
    {  
        this.className = "Instance Constructor";  
        System.out.println(this.className);
    }  
    // Instance Method - Factorial Recursive  
    public BigInteger factorialR(int n)  
    {  
        // Calling Static Method  
        return StaticFiborial.factorialR(n);  
    }  
    // Instance Method - Factorial Imperative  
    public BigInteger factorialI(int n)  
    {  
        // Calling Static Method  
        return StaticFiborial.factorialI(n);  
    }  
    // Instance Method - Fibonacci Recursive  
    public long fibonacciR(int n)  
    {  
        // Calling Static Method  
        return StaticFiborial.fibonacciR(n);  
    }  
    // Instance Method - Factorial Imperative  
    public long fibonacciI(int n)  
    {  
        // Calling Static Method  
        return StaticFiborial.fibonacciI(n);  
    }  
}
&lt;/pre&gt;&lt;br /&gt;
&lt;pre class="java" name="code"&gt;package fiborial;
import java.util.Scanner; 
import java.util.ArrayList;
import java.util.List;

public class StaticFiborialProgram 
{
    public static void main(String[] args)
    {
        System.out.println("\nStatic Class");  
        // Calling Static Class and Methods  
        // No instantiation needed. Calling method directly from the class  
        System.out.println("FacImp(5) = " + StaticFiborial.factorialI(5));  
        System.out.println("FacRec(5) = " + StaticFiborial.factorialR(5));  
        System.out.println("FibImp(11)= " + StaticFiborial.fibonacciI(11));  
        System.out.println("FibRec(11)= " + StaticFiborial.fibonacciR(11));  

        System.out.println("\nInstance Class");  
        // Calling Instance Class and Methods   
        // Need to instantiate before using. Calling method from instantiated object  
        InstanceFiborial ff = new InstanceFiborial();  
        System.out.println("FacImp(5) = " + ff.factorialI(5));  
        System.out.println("FacRec(5) = " + ff.factorialR(5));  
        System.out.println("FibImp(11)= " + ff.fibonacciI(11));  
        System.out.println("FibRec(11)= " + ff.fibonacciR(11));  

        // Create a (generic) list of integer values to test  
        // From 5 to 50 by 5  
        List&amp;lt;Integer&amp;gt; values = new ArrayList&amp;lt;Integer&amp;gt;();  
        for(int i = 5; i &amp;lt;= 50; i += 5)  
            values.add(i);  

        // Benchmarking Fibonacci                       
        // 1 = Factorial Imperative              
        StaticFiborial.benchmarkAlgorithm(1, values);  
        // 2 = Factorial Recursive  
        StaticFiborial.benchmarkAlgorithm(2, values);   

        // Benchmarking Factorial              
        // 3 = Fibonacci Imperative  
        StaticFiborial.benchmarkAlgorithm(3, values);  
        // 4 = Fibonacci Recursive  
        StaticFiborial.benchmarkAlgorithm(4, values);   

        // Stop and exit  
        System.out.println("Press any key to exit...");  
        Scanner in = new Scanner(System.in);  
        String line = in.nextLine();  
        in.close();  
    }
}
&lt;/pre&gt;&lt;br /&gt;
And the Output is:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-FO4Hmg9LrI0/Td7FoSIi_XI/AAAAAAAAF6g/FVAiP0h8CSc/s1600/fiborial_java.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="640" src="http://3.bp.blogspot.com/-FO4Hmg9LrI0/Td7FoSIi_XI/AAAAAAAAF6g/FVAiP0h8CSc/s640/fiborial_java.PNG" width="321" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;a href="http://2.bp.blogspot.com/_0_HCzHGe4_k/TM8Wwm7ILyI/AAAAAAAAFyQ/AziXveRyTGo/s1600/output_delphi.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;br /&gt;
&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Printing the Factorial and Fibonacci Series&lt;/b&gt;&lt;br /&gt;
&lt;pre class="java" name="code"&gt;package fiborialseries;
import java.math.BigInteger;
import java.lang.StringBuffer;

class Fiborial
{
    // Using a StringBuffer as a list of string elements
    public static String getFactorialSeries(int n)
    {
        // Create the String that will hold the list
        StringBuffer series = new StringBuffer();
        // We begin by concatenating the number you want to calculate
        // in the following format: "!# ="
        series.append("!");
        series.append(n);
        series.append(" = ");
        // We iterate backwards through the elements of the series
        for (int i = n; i &amp;lt;= n &amp;amp;&amp;amp; i &amp;gt; 0; i--)
        {
            // and append it to the list
            series.append(i);
            if (i &amp;gt; 1)
                series.append(" * ");
            else 
                series.append(" = "); 
        }
        // Get the result from the Factorial Method
        // and append it to the end of the list
        series.append(factorial(n));
        // return the list as a string
        return series.toString();
    }

    // Using a StringBuffer as a list of string elements
    public static String getFibonnaciSeries(int n)
    {
        // Create the String that will hold the list
        StringBuffer series = new StringBuffer();
        // We begin by concatenating the first 3 values which
        // are always constant
        series.append("0, 1, 1");
        // Then we calculate the Fibonacci of each element
        // and add append it to the list
        for (int i = 2; i &amp;lt;= n; i++)
        {
            if (i &amp;lt; n)
                series.append(", ");
            else
                series.append(" = ");
            
            series.append(fibonacci(i));
        }
        // return the list as a string
        return series.toString();
    }

    public static BigInteger factorial(int n)
    {
        if (n == 1)  
            return BigInteger.ONE;
        else  
            return BigInteger.valueOf(n).multiply(factorial(n - 1));
    }        

    public static long fibonacci(int n)
    {
        if (n &amp;lt; 2)  
            return 1;  
        else  
            return fibonacci(n - 1) + fibonacci(n - 2);  
    }   
}
&lt;/pre&gt;&lt;br /&gt;
&lt;pre class="java" name="code"&gt;package fiborialseries;

class FiborialExtrasProgram
{    
    public static void main(String[] args) 
    {            
        // Printing Factorial Series
        System.out.println("");
        System.out.println(Fiborial.getFactorialSeries(5));
        System.out.println(Fiborial.getFactorialSeries(7));
        System.out.println(Fiborial.getFactorialSeries(9));
        System.out.println(Fiborial.getFactorialSeries(11));
        System.out.println(Fiborial.getFactorialSeries(40));
        // Printing Fibonacci Series
        System.out.println("");
        System.out.println(Fiborial.getFibonnaciSeries(5));
        System.out.println(Fiborial.getFibonnaciSeries(7));
        System.out.println(Fiborial.getFibonnaciSeries(9));
        System.out.println(Fiborial.getFibonnaciSeries(11));
        System.out.println(Fiborial.getFibonnaciSeries(40));
    }
}
&lt;/pre&gt;&lt;br /&gt;
And the Output is:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/--JLNr9ezjsE/TdBVbVgbX5I/AAAAAAAAF6M/3eWTdjzsp3s/s1600/fiborial_java_extras_series.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="312" src="http://3.bp.blogspot.com/--JLNr9ezjsE/TdBVbVgbX5I/AAAAAAAAF6M/3eWTdjzsp3s/s640/fiborial_java_extras_series.PNG" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Mixing Instance and Static Members in the same Class&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Instance classes can contain both, instance and static members such as: fields, getters/setters, constructors/initializers, methods, etc.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="java" name="code"&gt;package fiborialextrasjava2;

// Instance Class  
class Fiborial  
{  
    // Instance Field  
    private int instanceCount;  
    // Static Field  
    private static int staticCount;          
    // Instance Read-Only Getter  
    // Within instance members, you can always use    
    // the "this" reference pointer to access your (instance) members.  
    public int getInstanceCount()
    {  
        return this.instanceCount;   
    }  
    // Static Read-Only Getter      
    // As with Static Methods, you cannot reference your class members  
    // with the "this" reference pointer since static members are not  
    // instantiated.          
    public static int getStaticCount()
    {  
        return staticCount;  
    }  
    // Instance Constructor  
    public Fiborial()  
    {  
        this.instanceCount = 0;  
        System.out.println("\nInstance Constructor " + this.instanceCount); 
    }  
    // Static Constructor  
    static
    {  
        staticCount = 0;  
        System.out.println("\nStatic Constructor " + staticCount);  
    }  

    // Instance Method  
    public void factorial(int n)  
    {  
        this.instanceCount += 1;  
        System.out.println("\nFactorial(" + n + ")");  
    }  

    // Static Method  
    public static void fibonacci(int n)  
    {  
        staticCount += 1;  
        System.out.println("\nFibonacci(" + n + ")");  
    }                  
}
&lt;/pre&gt;&lt;br /&gt;
&lt;pre class="java" name="code"&gt;package fiborialextrasjava2;

class FiborialExtras2Program
{    
    public static void main(String[] args) 
    {            
        // Calling Static Constructor and Methods  
        // No need to instantiate  
        Fiborial.fibonacci(5);              

        // Calling Instance Constructor and Methods  
        // Instance required  
        Fiborial fib = new Fiborial();  
        fib.factorial(5);              

        Fiborial.fibonacci(15);              
        fib.factorial(5);  

        // Calling Instance Constructor and Methods  
        // for a second object  
        Fiborial fib2 = new Fiborial();  
        fib2.factorial(5);  
          
        System.out.println("");
        // Calling Static Property  
        System.out.println("Static Count = " + Fiborial.getStaticCount());  
        // Calling Instance Property of object 1 and 2  
        System.out.println("Instance 1 Count = " + fib.getInstanceCount());  
        System.out.println("Instance 2 Count = " + fib2.getInstanceCount());          
    }
}
&lt;/pre&gt;&lt;br /&gt;
And the Output is:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-ikkKX1Qg4ak/TdBY4mWs84I/AAAAAAAAF6U/bee3t-6xTWs/s1600/fiborial_java_extras2.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="430" src="http://3.bp.blogspot.com/-ikkKX1Qg4ak/TdBY4mWs84I/AAAAAAAAF6U/bee3t-6xTWs/s640/fiborial_java_extras2.PNG" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://2.bp.blogspot.com/_0_HCzHGe4_k/TJYz5ZgkFGI/AAAAAAAAFwk/Y8rwLu2Bags/s1600/output_ipy_ext.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt; &lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Factorial using java.lang.Long, java.lang.Double, java.math.BigInteger&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
The Factorial of numbers over 20 are massive!&lt;br /&gt;
For instance: !40 = 815915283247897734345611269596115894272000000000!&lt;br /&gt;
Because of this, the previous version of this program was giving the "wrong" result &lt;br /&gt;
!40 = -70609262346240000 when using "long" type, but it was not until I did the Fiborial version in VB.NET that I realized about this faulty code, because instead of giving me a wrong value, VB.NET, JScript.NET, Boo execution thrown an Overflow Exception when using the "Long/long" (System.Int64) type. It looks like in Java it also applies, so I'm copying the same I said for the previous posts:&lt;br /&gt;
&lt;br /&gt;
Used Double (double floating point) type and got no more exception/wrong result. The result of the factorial was now correct !40 = 1.1962222086548E+56, but still I wanted to show the Integer value of it, so I did some research and found that there is a new System.Numerics.BigInteger class in the .NET Framework 4.0 which in Java is java.math.BigInteger. Using BigInteger class to calculate the Factorial gave me the results I was expecting.&lt;br /&gt;
!40 = 815915283247897734345611269596115894272000000000&lt;br /&gt;
&lt;br /&gt;
What I also found was that using different types change the time the algorithm takes to finish:&lt;br /&gt;
Almost by double!&lt;br /&gt;
&lt;br /&gt;
To illustrate what I just "tried" to say, lets have a look at the following code and the output we get.  &lt;br /&gt;
&lt;br /&gt;
&lt;pre class="java" name="code"&gt;package fiborialextrasjava3;
import java.math.BigInteger;

class FiborialExtrasProgram
{    
    public static void main(String[] args) 
    {            
        Stopwatch timer = new Stopwatch();  
        long facIntResult = 0;  
        double facDblResult = 0;  
        BigInteger facBigResult = BigInteger.valueOf(0);  

        System.out.println("\nFactorial using Int64");
        // Benchmark Factorial using Int64  
        for (int i = 5; i &amp;lt;= 50; i += 5)  
        {  
            timer.start();  
            facIntResult = factorialInt64(i);  
            timer.stop();  
            System.out.println(" (" + i + ") = " 
                + timer.getElapsed() + " : " + facIntResult);
        }  
        System.out.println("\nFactorial using Double");  
        // Benchmark Factorial using Double  
        for (int i = 5; i &amp;lt;= 50; i += 5)  
        {  
            timer.start();  
            facDblResult = factorialDouble(i);  
            timer.stop();              
            System.out.println(" (" + i + ") = " 
                + timer.getElapsed() + " : " + facDblResult);
        }  
        System.out.println("\nFactorial using BigInteger");  
        // Benchmark Factorial using BigInteger  
        for (int i = 5; i &amp;lt;= 50; i += 5)  
        {  
            timer.start();  
            facBigResult = factorialBigInteger(i);  
            timer.stop();  
            System.out.println(" (" + i + ") = " 
                + timer.getElapsed() + " : " + facBigResult);
        }          
    }
    
    // Long Factorial  
    public static long factorialInt64(int n)  
    {  
        if (n == 1)  
            return 1;
        else  
            return n * factorialInt64(n - 1);
    }
    
    // Double Factorial
    public static double factorialDouble(int n)  
    {  
        if (n == 1)  
            return 1;
        else  
            return n * factorialDouble(n - 1);
    }
    
    // BigInteger Factorial 
    public static BigInteger factorialBigInteger(int n)  
    {  
        if (n == 1)  
            return BigInteger.ONE;
        else  
            return BigInteger.valueOf(n).multiply(factorialBigInteger(n - 1));
    }
}
&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
And the Output is:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-aA5uKpZYg5E/TdBWQXCVWeI/AAAAAAAAF6Q/VbKJSlx2Ja8/s1600/fiborial_java_extras_big_int.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="546" src="http://4.bp.blogspot.com/-aA5uKpZYg5E/TdBWQXCVWeI/AAAAAAAAF6Q/VbKJSlx2Ja8/s640/fiborial_java_extras_big_int.PNG" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/694679611587040520-1304605657994355004?l=carlosqt.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/rZCN_fO1en9i1V1qvWMx8p6iytM/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/rZCN_fO1en9i1V1qvWMx8p6iytM/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/rZCN_fO1en9i1V1qvWMx8p6iytM/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/rZCN_fO1en9i1V1qvWMx8p6iytM/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/CarlosQuintanillasBlog/~4/Y8Xa38-IP0s" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://carlosqt.blogspot.com/feeds/1304605657994355004/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://carlosqt.blogspot.com/2011/05/factorial-and-fibonacci-in-java.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/694679611587040520/posts/default/1304605657994355004?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/694679611587040520/posts/default/1304605657994355004?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/CarlosQuintanillasBlog/~3/Y8Xa38-IP0s/factorial-and-fibonacci-in-java.html" title="Factorial and Fibonacci in Java" /><author><name>Carlos QT</name><uri>http://www.blogger.com/profile/15415604076909500411</uri><email>carlosqt@gmail.com</email><gd:extendedProperty name="OpenSocialUserId" value="14144067369073378952" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/-FO4Hmg9LrI0/Td7FoSIi_XI/AAAAAAAAF6g/FVAiP0h8CSc/s72-c/fiborial_java.PNG" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://carlosqt.blogspot.com/2011/05/factorial-and-fibonacci-in-java.html</feedburner:origLink></entry><entry gd:etag="W/&quot;A0UFRXk4eCp7ImA9WhZUEE8.&quot;"><id>tag:blogger.com,1999:blog-694679611587040520.post-7296712681658845745</id><published>2011-04-03T13:27:00.000-07:00</published><updated>2011-06-02T08:40:14.730-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-06-02T08:40:14.730-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="PHP" /><category scheme="http://www.blogger.com/atom/ns#" term="Phalanger" /><category scheme="http://www.blogger.com/atom/ns#" term="CLR" /><title>Factorial and Fibonacci in Phalanger</title><content type="html">&lt;a class="twitter-share-button" data-count="horizontal" data-via="carlosqt" href="http://twitter.com/share"&gt;Tweet&lt;/a&gt;&lt;script src="http://platform.twitter.com/widgets.js" type="text/javascript"&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;br /&gt;
Updated: using BigInteger Multiply method instead of unsupported custom * Operator.&lt;br /&gt;
&lt;br /&gt;
Here below a little program in Phalanger that implements 2 classes (in fact, they are 3). There is the main class, called Fiborial (Fibo(nnacci)+(Facto)rial) that implements the &lt;i&gt;Fibonacci&lt;/i&gt; and the &lt;i&gt;Factorial&lt;/i&gt; algorithms in two ways, one &lt;i&gt;Recursive&lt;/i&gt; (using recursion) and the other &lt;i&gt;Imperative&lt;/i&gt; (using loops and states). The second class is just an instance class that does the same thing, but its there just to show the difference between static and instance classes, and finally the third one (which will not appear in other languages) is the Program class which has the static execution method "Main".&lt;br /&gt;
&lt;br /&gt;
You can also find 3 more little examples at the bottom. One prints out the Factorial's Series and Fibonacci's Series, the second one just shows a class that mixes both: static and instance members, and finally the third one that uses different return types (including System.Numerics.BigInteger) for the Factorial method to compare the timing and result.&lt;br /&gt;
&lt;br /&gt;
As with the previous posts, you can copy and paste the code below in your favorite IDE/Editor and start playing and learning with it. This little "working" program will teach you some more basics of the Programming Language.&lt;br /&gt;
&lt;br /&gt;
There are some "comments" on the code added just to tell you what are or how are some features called. In case you want to review the theory, you can read my previous post, where I give a definition of each of the concepts mentioned on the code. You can find it here: &lt;a href="http://carlosqt.blogspot.com/2011/01/new-series-factorial-and-fibonacci.html"&gt;http://carlosqt.blogspot.com/2011/01/new-series-factorial-and-fibonacci.html&lt;/a&gt;&amp;nbsp;&lt;a href="http://carlosqt.blogspot.com/2010/08/new-series-languages-basics-by-example.html"&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;The Fiborial Program&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="php" name="code"&gt;&amp;lt;?php    
# Factorial and Fibonacci in Phalanger    
import namespace System;    
import namespace System:::Collections:::Generic;  
import namespace System:::Diagnostics;  
import namespace System:::Numerics;  
  
namespace FiborialPhp   
{    
    [Export]   
    # Instance Class         
    # static is not a class modifier in PHP  
    class StaticFiborial  
    {    
        # Static Field   
        private static $className;  
        # no available static __constructor support  
        # Static Initializer Method instead, but need to be explicitly invoked  
        public static function StaticFiborialConstructor()  
        {  
            $className = "Static Constructor";  
            echo $className . "\n";  
        }          
        # Static Method - Factorial Recursive  
        public static function FactorialR(int $n)  
        {    
            if($n == 1)   
                return new BigInteger(1);
            else                  
                return BigInteger::Multiply(new BigInteger($n), self::FactorialR($n-1));
        }          
        # Static Method - Factorial Imperative      
        public static function FactorialI(int $n)   
        {                  
            $res = new BigInteger(1);            
            for ($i = $n; $i &amp;gt;= 1; $i--)
                $res = BigInteger::Multiply($res, new BigInteger($i));                
            return $res;  
        }     
        # Static Method - Fibonacci Recursive      
        public static function FibonacciR(int $n)   
        {      
            if ($n &amp;lt; 2)  
                return 1;      
            else      
                return self::FibonacciR($n - 1) + self::FibonacciR($n - 2);      
        }  
        # Static Method - Fibonacci Imperative      
        public static function FibonacciI(int $n)   
        {  
            $pre = 0; $cur = 0; $tmp = 0;  
            $pre = 1; $cur = 1;  
            for ($i = 2; $i &amp;lt;= $n; $i++)   
            {  
                $tmp = $cur + $pre;      
                $pre = $cur;      
                $cur = $tmp;      
            }      
            return $cur;  
        }  
        # Static Method - Benchmarking Algorithms      
        public static function BenchmarkAlgorithm(int $algorithm, i'List'&amp;lt;:int:&amp;gt; $values)   
        {  
            $timer = new Stopwatch();  
            $i = 0;   
            $testValue = 0;              
            $facTimeResult = new BigInteger(0);
            $fibTimeResult = 0;      
              
            # "Switch" Flow Constrol Statement      
            switch ($algorithm)      
            {      
                case 1:      
                    echo "\nFactorial Imperative:\n";  
                    # "For" Loop Statement      
                    for ($i = 0; $i &amp;lt; $values-&amp;gt;Count; $i++)    
                    {                                                  
                        $testValue = $values-&amp;gt;get_Item($i);  
                        # Taking Time      
                        $timer-&amp;gt;Start();      
                        $facTimeResult = self::FactorialI($testValue);      
                        $timer-&amp;gt;Stop();                              
                        # Getting Time                            
                        echo " ($testValue) = {$timer-&amp;gt;Elapsed-&amp;gt;ToString()}\n";  
                    }                          
                    break;      
                case 2:      
                    echo "\nFactorial Recursive:\n";  
                    # "While" Loop Statement      
                    while ($i &amp;lt; $values-&amp;gt;Count)      
                    {                              
                        $testValue = $values-&amp;gt;get_Item($i);                          
                        # Taking Time      
                        $timer-&amp;gt;Start();      
                        $facTimeResult = self::FactorialR($testValue);      
                        $timer-&amp;gt;Stop();      
                        # Getting Time      
                        echo " ($testValue) = {$timer-&amp;gt;Elapsed-&amp;gt;ToString()}\n";  
                        $i++;  
                    }  
                    break;      
                case 3:      
                    echo "\nFibonacci Imperative:\n";  
                    # "Do-While" Loop Statement      
                    do   
                    {      
                        $testValue = $values-&amp;gt;get_Item($i);  
                        # Taking Time      
                        $timer-&amp;gt;Start();      
                        $fibTimeResult = self::FibonacciI($testValue);      
                        $timer-&amp;gt;Stop();      
                        # Getting Time      
                        echo " ($testValue) = {$timer-&amp;gt;Elapsed-&amp;gt;ToString()}\n";  
                        $i++;      
                    } while ($i &amp;lt; $values-&amp;gt;Count);                          
                    break;      
                case 4:      
                    echo "\nFibonacci Recursive:\n";  
                    # "ForEach" Loop Statement      
                    foreach ($values as $item)      
                    {      
                        $testValue = (int)$item;      
                        # Taking Time      
                        $timer-&amp;gt;Start();      
                        $fibTimeResult = self::FibonacciR($testValue);  
                        $timer-&amp;gt;Stop();      
                        # Getting Time      
                        echo " ($testValue) = {$timer-&amp;gt;Elapsed-&amp;gt;ToString()}\n";  
                    }      
                    break;      
                default:      
                    echo "DONG!\n";  
                    break;  
            }                      
        }      
    }  
  
    [Export]   
    # Instance Class  
    class InstanceFiborial  
    {    
        # Instance  Field   
        private $className;  
        # Instance Constructor                          
        function __construct()    
        {    
            $this-&amp;gt;className = "Instance Constructor";  
            echo $this-&amp;gt;className . "\n";  
        }  
        # Instance Method - Factorial Recursive  
        public function FactorialR(int $n)  
        {    
            # Calling Static Method  
            return FiborialPhp:::StaticFiborial::FactorialR($n);  
        }  
        # Instance Method - Factorial Imperative      
        public function FactorialI(int $n)   
        {      
            # Calling Static Method  
            return FiborialPhp:::StaticFiborial::FactorialI($n);  
        }     
        # Instance Method - Fibonacci Recursive      
        public function FibonacciR(int $n)   
        {      
            # Calling Static Method  
            return FiborialPhp:::StaticFiborial::FibonacciR($n);  
        }  
        # Instance Method - Fibonacci Imperative      
        public function FibonacciI(int $n)   
        {  
            # Calling Static Method  
            return FiborialPhp:::StaticFiborial::FibonacciI($n);  
        }  
    }  
  
    # Console Program    
    class Program    
    {    
        public static function Main()    
        {    
            # Static Initializer/Constructor for StaticFiborial Class   
            # explicitly called somewhere in your code ^_^  
            FiborialPhp:::StaticFiborial::StaticFiborialConstructor();  
              
            echo "\nStatic Class\n";  
            # Calling Static Class and Methods    
            # No instantiation needed. Calling method directly from the class    
            echo "FacImp(5) = " . FiborialPhp:::StaticFiborial::FactorialI(5)-&amp;gt;ToString() . "\n";  
            echo "FacRec(5) = " . FiborialPhp:::StaticFiborial::FactorialR(5)-&amp;gt;ToString() . "\n";  
            echo "FibImp(11)= " . FiborialPhp:::StaticFiborial::FibonacciI(11)-&amp;gt;ToString() . "\n";  
            echo "FibRec(11)= " . FiborialPhp:::StaticFiborial::FibonacciR(11)-&amp;gt;ToString() . "\n";  
    
            echo "\nInstance Class\n";    
            # Calling Instance Class and Methods    
            # Need to instantiate before using. Calling method from instantiated object    
            $ff = new FiborialPhp:::InstanceFiborial();  
            echo "FacImp(5) = {$ff-&amp;gt;FactorialI(5)-&amp;gt;ToString()}\n";  
            echo "FacRec(5) = {$ff-&amp;gt;FactorialR(5)-&amp;gt;ToString()}\n";  
            echo "FibImp(11)= {$ff-&amp;gt;FibonacciI(11)-&amp;gt;ToString()}\n";  
            echo "FibRec(11)= {$ff-&amp;gt;FibonacciR(11)-&amp;gt;ToString()}\n";  
    
            # PHP/CLR provides syntax of quoted identifiers.   
            # the List class can be referred to by i'List' quoted identifier.  
            # to avoid ambiguity with PHP List keyword  
            # From 5 to 50 by 5  
            $values = new i'List'&amp;lt;:int:&amp;gt;;  
            for($i = 5; $i &amp;lt;= 50; $i += 5)  
                $values-&amp;gt;Add($i);  
  
            # Benchmarking Fibonacci    
            # 1 = Factorial Imperative    
            FiborialPhp:::StaticFiborial::BenchmarkAlgorithm(1, $values);  
            # 2 = Factorial Recursive    
            FiborialPhp:::StaticFiborial::BenchmarkAlgorithm(2, $values);  
            # Benchmarking Factorial    
            # 3 = Fibonacci Imperative    
            FiborialPhp:::StaticFiborial::BenchmarkAlgorithm(3, $values);  
            # 4 = Fibonacci Recursive    
            FiborialPhp:::StaticFiborial::BenchmarkAlgorithm(4, $values);  
  
            # Stop and exit    
            echo "Press any key to exit...";    
            fgets(STDIN);    
            return 0;    
        }    
    }  
}  
?&amp;gt;
&lt;/pre&gt;&lt;br /&gt;
And the Output is: &lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-X61JPUcuhPI/TZjVj7xUISI/AAAAAAAAF5Q/CHB3_U7MHew/s1600/fiborial_php.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="640" src="http://3.bp.blogspot.com/-X61JPUcuhPI/TZjVj7xUISI/AAAAAAAAF5Q/CHB3_U7MHew/s640/fiborial_php.PNG" width="294" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;a href="http://2.bp.blogspot.com/_0_HCzHGe4_k/TM8Wwm7ILyI/AAAAAAAAFyQ/AziXveRyTGo/s1600/output_delphi.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;br /&gt;
&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Humm, looks like Fibonnaci's algorithm implemented using recursion is definitively more complex than the others 3 right? I will grab these results for this and each of the upcoming posts to prepare a comparison of time execution between all the programming languages, then we will be able to talk about the algorithm's complexity as well.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Printing the Factorial and Fibonacci Series&lt;/b&gt;&lt;br /&gt;
&lt;pre class="php" name="code"&gt;&amp;lt;?php    
import namespace System;    
import namespace System:::Text;  
import namespace System:::Numerics;  
  
namespace FiborialSeries  
{    
    [Export]       
    class Fiborial  
    {    
        # Using a StringBuilder as a list of string elements              
        static function GetFactorialSeries(int $n)   
        {  
            # Create the String that will hold the list      
            $series = new StringBuilder();      
            # We begin by concatenating the number you want to calculate      
            # in the following format: "!# ="      
            $series-&amp;gt;Append("!");      
            $series-&amp;gt;Append($n);      
            $series-&amp;gt;Append(" = ");      
            # We iterate backwards through the elements of the series      
            for ($i = $n; $i &amp;lt;= $n &amp;amp;&amp;amp; $i &amp;gt; 0; $i--)   
            {      
                # and append it to the list      
                $series-&amp;gt;Append($i);  
                if ($i &amp;gt; 1)      
                    $series-&amp;gt;Append(" * ");      
                else       
                    $series-&amp;gt;Append(" = ");       
            }      
            # Get the result from the Factorial Method      
            # and append it to the end of the list                                      
            # $series-&amp;gt;Append(self::Factorial($n)-&amp;gt;ToString());  
            # BUT! that throws an exception with big numbers (&amp;gt; fact(30))  
            # Overflow ex "Value was either too large or too small for a Decimal."
            # because I think it is a bug i used an ugly workaround which is
            # using the "." in the return.
            return $series-&amp;gt;ToString() . self::Factorial($n)-&amp;gt;ToString();
        }      
      
        # Using a StringBuilder as a list of string elements      
        static function GetFibonnaciSeries(int $n)      
        {      
            # Create the String that will hold the list      
            $series = new StringBuilder();  
            # We begin by concatenating the first 3 values which      
            # are always constant      
            $series-&amp;gt;Append("0, 1, 1");      
            # Then we calculate the Fibonacci of each element      
            # and add append it to the list      
            for ($i = 2; $i &amp;lt;= $n; $i++)      
            {      
                if ($i &amp;lt; $n)      
                    $series-&amp;gt;Append(", ");      
                else      
                    $series-&amp;gt;Append(" = ");      
          
                $series-&amp;gt;Append(self::Fibonacci($i));  
            }      
            # return the list as a string      
            return $series-&amp;gt;ToString();      
        }      
  
        static function Factorial(int $n)  
        {    
            if($n == 1)   
                return new BigInteger(1);
            else                  
                return BigInteger::Multiply(new BigInteger($n), self::Factorial($n - 1));
        }  
          
        static function Fibonacci(int $n)   
        {      
            if ($n &amp;lt; 2)  
                return 1;  
            else      
                return self::Fibonacci($n - 1) + self::Fibonacci($n - 2);      
        }      
    }  
  
    class Program    
    {    
        public static function Main()    
        {    
            # Printing Factorial Series      
            echo "\n";  
            echo FiborialSeries:::Fiborial::GetFactorialSeries(5) . "\n";  
            echo FiborialSeries:::Fiborial::GetFactorialSeries(7) . "\n";  
            echo FiborialSeries:::Fiborial::GetFactorialSeries(9) . "\n";  
            echo FiborialSeries:::Fiborial::GetFactorialSeries(11) . "\n";  
            echo FiborialSeries:::Fiborial::GetFactorialSeries(40) . "\n";    
            # Printing Fibonacci Series
            echo "\n";  
            echo FiborialSeries:::Fiborial::GetFibonnaciSeries(5) . "\n";  
            echo FiborialSeries:::Fiborial::GetFibonnaciSeries(7) . "\n";  
            echo FiborialSeries:::Fiborial::GetFibonnaciSeries(9) . "\n";  
            echo FiborialSeries:::Fiborial::GetFibonnaciSeries(11) . "\n";  
            echo FiborialSeries:::Fiborial::GetFibonnaciSeries(40) . "\n";  
               
            fgets(STDIN);    
            return 0;    
        }    
    }  
}  
?&amp;gt;
&lt;/pre&gt;&lt;br /&gt;
And the Output is:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-AEEfUDpyqgI/TZjVs6d8leI/AAAAAAAAF5U/Uu1kQYSvJlc/s1600/fiborial_php_extras_series.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="256" src="http://4.bp.blogspot.com/-AEEfUDpyqgI/TZjVs6d8leI/AAAAAAAAF5U/Uu1kQYSvJlc/s640/fiborial_php_extras_series.PNG" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Mixing Instance and Static Members in the same Class&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Instance classes can contain both, instance and static members such as: fields, properties, constructors, methods, etc. &lt;br /&gt;
&lt;br /&gt;
&lt;pre class="php" name="code"&gt;&amp;lt;?php  
import namespace System;  

namespace FiborialExtras2
{  
    # Instance Class
    [Export]     
    class Fiborial
    {  
        # Instance Field
        private $instanceCount;
        # Static Field
        private static $staticCount;        
        # Instance Read-Only Property/Getter
        # Within instance members, you can always use  
        # the "this" reference pointer to access your (instance) members.
        public function getInstanceCount()
        {
            return $this-&amp;gt;instanceCount;
        }
        # Static Read-Only Property/Getter
        # As with Static Methods, you cannot reference your class members
        # with the "this" reference pointer since static members are not
        # instantiated.        
        public static function getStaticCount()
        {
            return $staticCount;
        }
        # Instance Constructor          
        public function __construct()  
        {  
            $this-&amp;gt;instanceCount = 0;
            echo "\nInstance Constructor {$this-&amp;gt;instanceCount}\n";
        }  
        # Static Constructor
        public static function FiborialStaticConstructor()
        {
            $staticCount = 0;
            echo "\nStatic Constructor {$staticCount}\n";
        }    
        # Instance Method
        public function Factorial(int $n)
        {  
            $this-&amp;gt;instanceCount += 1;
            echo "\nFactorial({$n})\n";
        }
        # Static Method
        public static function Fibonacci(int $n) 
        {    
            $staticCount += 1;
            echo "\nFibonacci({$n})\n";
        }    
    }

    class Program  
    {  
        public static function Main()  
        {  
            # Calling Static Constructor/Initializer and Methods
            # No need to instantiate
            FiborialExtras2:::Fiborial::FiborialStaticConstructor();
            FiborialExtras2:::Fiborial::Fibonacci(5);            

            // Calling Instance Constructor and Methods
            // Instance required
            $fib = new FiborialExtras2:::Fiborial();
            $fib-&amp;gt;Factorial(5);

            FiborialExtras2:::Fiborial::Fibonacci(15);            
            $fib-&amp;gt;Factorial(5);

            // Calling Instance Constructor and Methods
            // for a second object
            $fib2 = new FiborialExtras2:::Fiborial();
            $fib2-&amp;gt;Factorial(5);
            
            echo "\n";
            // Calling Static Property
            echo "Static Count = " . FiborialExtras2:::Fiborial::getStaticCount() . "\n";
            // Calling Instance Property of object 1 and 2
            echo "Instance 1 Count = {$fib-&amp;gt;getInstanceCount()}\n";
            echo "Instance 2 Count = {$fib2-&amp;gt;getInstanceCount()}\n";

            fgets(STDIN);  
            return 0;  
        }  
    }
}
?&amp;gt;
&lt;/pre&gt;&lt;br /&gt;
And the Output is:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-FHWCh_GtAGM/TZjV1x7COKI/AAAAAAAAF5Y/_sN4bvGIa3I/s1600/fiborial_php_extras2.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="400" src="http://3.bp.blogspot.com/-FHWCh_GtAGM/TZjV1x7COKI/AAAAAAAAF5Y/_sN4bvGIa3I/s400/fiborial_php_extras2.PNG" width="377" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://2.bp.blogspot.com/_0_HCzHGe4_k/TJYz5ZgkFGI/AAAAAAAAFwk/Y8rwLu2Bags/s1600/output_ipy_ext.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;br /&gt;
&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Factorial using System.Int64, System.Double, System.Numerics.BigInteger&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
The Factorial of numbers over 20 are massive!&lt;br /&gt;
For instance: !40 = 815915283247897734345611269596115894272000000000!&lt;br /&gt;
Because of this, the previous version of this program was giving the "wrong" result &lt;br /&gt;
!40 = -70609262346240000 when using "long" (System.Int64) type, but it was not until I did the Fiborial version in VB.NET that I realized about this faulty code, because instead of giving me a wrong value, VB.NET, JScript.NET, Boo execution thrown an Overflow Exception when using the "Long/long" (System.Int64) type.&lt;br /&gt;
&lt;br /&gt;
My first idea was to use ulong and ULong, but both failed for "big" numbers. I then used Double (double floating point) type and got no more exception/wrong result. The result of the factorial was now correct !40 = 1.1962222086548E+56, but still I wanted to show the Integer value of it, so I did some research and found that there is a new System.Numerics.BigInteger class in the .NET Framework 4.0. Adding the reference to the project and using this new class as the return type of the Factorial methods, I was able to get the result I was expecting.&lt;br /&gt;
!40 = 815915283247897734345611269596115894272000000000&lt;br /&gt;
&lt;br /&gt;
What I also found was that using different types change the time the algorithm takes to finish:&lt;br /&gt;
System.Int64 &amp;lt; System.Double &amp;lt; System.Numerics.BigInteger  &lt;br /&gt;
Almost by double!&lt;br /&gt;
&lt;br /&gt;
To illustrate what I just "tried" to say, lets have a look at the following code and the output we get.  &lt;br /&gt;
&lt;br /&gt;
&lt;pre class="php" name="code"&gt;&amp;lt;?php    
import namespace System;    
import namespace System:::Numerics;    
import namespace System:::Diagnostics;    
  
function FactorialInt64(int $n)   
{      
    if ($n == 1)      
        return 1;      
    else      
        return $n * FactorialInt64($n - 1);      
}      
  
function FactorialDouble(int $n)   
{      
    if ($n == 1)      
        return (double)1;      
    else      
        return (double)($n * FactorialDouble($n - 1));  
}  
  
function FactorialBigInteger(int $n)   
{      
    if($n == 1)   
        return new BigInteger(1);
    else                  
        return BigInteger::Multiply(new BigInteger($n), FactorialBigInteger($n - 1));
}  
  
class Program  
{  
    public static function Main()    
    {    
            $timer = new Stopwatch();  
            $facIntResult = 0;      
            $facDblResult = (double)0;      
            $facBigResult = new BigInteger(0);   
  
            echo "\nFactorial using Int64\n";      
            // Benchmark Factorial using Int64      
            for ($i = 5; $i &amp;lt;= 50; $i += 5)      
            {      
                $timer-&amp;gt;Start();      
                $facIntResult = FactorialInt64($i);      
                $timer-&amp;gt;Stop();      
                echo " ({$i}) = {$timer-&amp;gt;Elapsed-&amp;gt;ToString()} : {$facIntResult}\n";  
            }                  
            echo "\nFactorial using Double\n";      
            // Benchmark Factorial using Double  
            for ($i = 5; $i &amp;lt;= 50; $i += 5)      
            {      
                $timer-&amp;gt;Start();      
                $facDblResult = FactorialDouble($i);      
                $timer-&amp;gt;Stop();      
                echo " ({$i}) = {$timer-&amp;gt;Elapsed-&amp;gt;ToString()} : {$facDblResult}\n";  
            }      
            echo "\nFactorial using BigInteger\n";  
            // Benchmark Factorial using BigInteger                  
            for ($i = 5; $i &amp;lt;= 50; $i += 5)  
            {      
                  
                $timer-&amp;gt;Start();      
                $facBigResult = FactorialBigInteger($i);      
                $timer-&amp;gt;Stop();      
                echo " ({$i}) = {$timer-&amp;gt;Elapsed-&amp;gt;ToString()} : {$facBigResult-&amp;gt;ToString()}\n";  
            }    
                        
            fgets(STDIN);    
            return 0;    
    }    
}  
?&amp;gt;
&lt;/pre&gt;&lt;br /&gt;
NOTE: you need to manually add a reference to the System.Numerics.dll assembly to your project so you can add it to your code.&lt;br /&gt;
&lt;br /&gt;
And the Output is:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-VI1M_xqbHQs/TeeuEFEl1XI/AAAAAAAAF68/rHQl2Dl9Qms/s1600/fiborial_php_extras_big_int2.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="482" src="http://2.bp.blogspot.com/-VI1M_xqbHQs/TeeuEFEl1XI/AAAAAAAAF68/rHQl2Dl9Qms/s640/fiborial_php_extras_big_int2.PNG" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;a href="http://1.bp.blogspot.com/-GdIEa1Uatg8/TY9wCJl6TbI/AAAAAAAAF5M/AUQ55fdqdSE/s1600/fiborial_n_extras_big_int.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&amp;nbsp;&lt;/a&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/694679611587040520-7296712681658845745?l=carlosqt.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/bfT_0Z6YJ78QKOD5_-aKZstceLA/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/bfT_0Z6YJ78QKOD5_-aKZstceLA/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/bfT_0Z6YJ78QKOD5_-aKZstceLA/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/bfT_0Z6YJ78QKOD5_-aKZstceLA/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/CarlosQuintanillasBlog/~4/fwEwO-BgbR8" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://carlosqt.blogspot.com/feeds/7296712681658845745/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://carlosqt.blogspot.com/2011/04/factorial-and-fibonacci-in-phalanger.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/694679611587040520/posts/default/7296712681658845745?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/694679611587040520/posts/default/7296712681658845745?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/CarlosQuintanillasBlog/~3/fwEwO-BgbR8/factorial-and-fibonacci-in-phalanger.html" title="Factorial and Fibonacci in Phalanger" /><author><name>Carlos QT</name><uri>http://www.blogger.com/profile/15415604076909500411</uri><email>carlosqt@gmail.com</email><gd:extendedProperty name="OpenSocialUserId" value="14144067369073378952" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/-X61JPUcuhPI/TZjVj7xUISI/AAAAAAAAF5Q/CHB3_U7MHew/s72-c/fiborial_php.PNG" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://carlosqt.blogspot.com/2011/04/factorial-and-fibonacci-in-phalanger.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DEcNQHc_eip7ImA9WhZSEkk.&quot;"><id>tag:blogger.com,1999:blog-694679611587040520.post-7518171880813965006</id><published>2011-03-27T10:14:00.000-07:00</published><updated>2011-03-27T10:14:51.942-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-03-27T10:14:51.942-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Nemerle" /><category scheme="http://www.blogger.com/atom/ns#" term="CLR" /><title>Factorial and Fibonacci in Nemerle</title><content type="html">&lt;a class="twitter-share-button" data-count="horizontal" data-via="carlosqt" href="http://twitter.com/share"&gt;Tweet&lt;/a&gt;&lt;script src="http://platform.twitter.com/widgets.js" type="text/javascript"&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;br /&gt;
Here below a little program in Nemerle that implements 2 classes (in fact, they are 3). There is the main class, called Fiborial (Fibo(nnacci)+(Facto)rial) that implements the &lt;i&gt;Fibonacci&lt;/i&gt; and the &lt;i&gt;Factorial&lt;/i&gt; algorithms in two ways, one &lt;i&gt;Recursive&lt;/i&gt; (using recursion) and the other &lt;i&gt;Imperative&lt;/i&gt; (using loops and states). The second class is just an instance class that does the same thing, but its there just to show the difference between static and instance classes, and finally the third one (which will not appear in other languages) is the Program class which has the static execution method "Main".&lt;br /&gt;
&lt;br /&gt;
You can also find 3 more little examples at the bottom. One prints out the Factorial's Series and Fibonacci's Series, the second one just shows a class that mixes both: static and instance members, and finally the third one that uses different return types (including System.Numerics.BigInteger) for the Factorial method to compare the timing and result.&lt;br /&gt;
&lt;br /&gt;
As with the previous posts, you can copy and paste the code below in your favorite IDE/Editor and start playing and learning with it. This little "working" program will teach you some more basics of the Programming Language.&lt;br /&gt;
&lt;br /&gt;
There are some "comments" on the code added just to tell you what are or how are some features called. In case you want to review the theory, you can read my previous post, where I give a definition of each of the concepts mentioned on the code. You can find it here: &lt;a href="http://carlosqt.blogspot.com/2011/01/new-series-factorial-and-fibonacci.html"&gt;http://carlosqt.blogspot.com/2011/01/new-series-factorial-and-fibonacci.html&lt;/a&gt;&amp;nbsp;&lt;a href="http://carlosqt.blogspot.com/2010/08/new-series-languages-basics-by-example.html"&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;The Fiborial Program&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="csharp" name="code"&gt;// Factorial and Fibonacci in Nemerle
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Numerics;
using Nemerle.IO;

namespace FiborialN
{
    // Module = Static Class
    // all members become static by default
    // no need to explicitly use static on members (i did anyway)
    module StaticFiborial
    {
        // Static Field
        static mutable className : string; 
        // Static Constructor
        static this()
        {
            className = "Static Constructor";
            printf("%s", className);
        }
        // Static Method - Factorial Recursive
        public static FactorialR(n : int) : BigInteger
        {            
            if (n == 1)
                 BigInteger(1);
            else 
                 BigInteger(n) * FactorialR(n - 1);
        }
        // Static Method - Factorial Imperative
        public static FactorialI(n : int) : BigInteger
        {
            mutable res : BigInteger = BigInteger(1);
            for (mutable i : int = n; i &amp;gt;= 1; i--)
                res *= i;
            res;
        }
        // Static Method - Fibonacci Recursive
        public static FibonacciR(n : int) : long
        {
            def oneLong : long = 1;
            if (n &amp;lt; 2)
                oneLong;
            else
                FibonacciR(n - 1) + FibonacciR(n - 2);
        }
        // Static Method - Fibonacci Imperative
        public static FibonacciI(n : int) : long
        {            
            mutable pre : long = 1;
            mutable cur : long = 1;
            mutable tmp : long = 0;
            
            for (mutable i : int = 2; i &amp;lt;= n; i++)
            {
                tmp = cur + pre;
                pre = cur;
                cur = tmp;
            }
            cur;
        }
        // Static Method - Benchmarking Algorithms
        public static BenchmarkAlgorithm(algorithm : int, values : list[int]) : void
        {            
            def timer : Stopwatch = Stopwatch();
            mutable i : int = 0;
            mutable testValue : int = 0;
            mutable facTimeResult : BigInteger = BigInteger(0);
            mutable fibTimeResult : long = 0;
           
            // "Switch" Flow Constrol Statement
            match (algorithm)
            {
                | 1 =&amp;gt;
                    printf("\nFactorial Imperative:\n");
                    // "For" Loop Statement
                    for (i = 0; i &amp;lt; values.Length; i++)
                    {
                        testValue = values.Nth(i);
                        // Taking Time
                        timer.Start();
                        facTimeResult = FactorialI(testValue);
                        timer.Stop();                        
                        // Getting Time
                        printf(" (%d) = %s\n", testValue, timer.Elapsed.ToString());
                    }
                | 2 =&amp;gt;
                    printf("\nFactorial Recursive:\n");
                    // 'While' Loop Statement  
                    while (i &amp;lt; values.Length) 
                    {
                        testValue = values.Nth(i);  
                        // Taking Time  
                        timer.Start();  
                        facTimeResult = FactorialR(testValue);  
                        timer.Stop();  
                        // Getting Time  
                        printf(" (%d) = %s\n", testValue, timer.Elapsed.ToString());
                        i++;
                    }
                | 3 =&amp;gt;
                    printf("\nFibonacci Imperative:\n");
                    // 'Do-While' Loop Statement  
                    do {  
                        testValue = values.Nth(i);  
                        // Taking Time 
                        timer.Start();  
                        fibTimeResult = FibonacciI(testValue);  
                        timer.Stop();  
                        // Getting Time  
                        printf(" (%d) = %s\n", testValue, timer.Elapsed.ToString());
                        i++;  
                    } while (i &amp;lt; values.Length);  
                | 4 =&amp;gt;
                    printf("\nFibonacci Recursive:\n");
                    // 'For Each' Loop Statement  
                    foreach (item : int in values) {  
                        testValue = item;
                        // Taking Time  
                        timer.Start();  
                        fibTimeResult = FibonacciR(testValue);  
                        timer.Stop();  
                        // Getting Time  
                        printf(" (%d) = %s\n", testValue, timer.Elapsed.ToString());
                    }  
                | _ =&amp;gt; printf("DONG!");
            }                
        }
    }
    
    // Instance Class  
    public class InstanceFiborial 
    {  
        // Instance Field  
        mutable className : String;  
        // Instance Constructor  
        public this() 
        {  
            this.className = "Instance Constructor";  
            printf("%s", this.className);
        }  
        // Instance Method - Factorial Recursive  
        public FactorialR(n : int) : BigInteger 
        {  
            // Calling Static Method  
            StaticFiborial.FactorialR(n);  
        }  
        // Instance Method - Factorial Imperative  
        public FactorialI(n : int) : BigInteger 
        {  
            // Calling Static Method  
            StaticFiborial.FactorialI(n);  
        }  
        // Instance Method - Fibonacci Recursive  
        public FibonacciR(n : int) : long 
        {  
            // Calling Static Method  
            StaticFiborial.FibonacciR(n);  
        }  
        // Instance Method - Factorial Imperative  
        public FibonacciI(n : int) : long 
        {  
            // Calling Static Method  
            StaticFiborial.FibonacciI(n);  
        }  
    }  
    
    module Program
    {
        Main() : void
        {          
            printf("\nStatic Class\n");
            // Calling Static Class and Methods  
            // No instantiation needed. Calling method directly from the class 
            printf("FacImp(5) = %s\n", StaticFiborial.FactorialI(5).ToString());  
            printf("FacRec(5) = %s\n", StaticFiborial.FactorialR(5).ToString());  
            printf("FibImp(11)= %s\n", StaticFiborial.FibonacciI(11).ToString());  
            printf("FibRec(11)= %s\n", StaticFiborial.FibonacciR(11).ToString());  

            printf("\nInstance Class\n");  
            // Calling Instance Class and Methods   
            // Need to instantiate before using. Calling method from instantiated object  
            def ff : InstanceFiborial = InstanceFiborial();  
            printf("FacImp(5) = %s\n", ff.FactorialI(5).ToString());  
            printf("FacRec(5) = %s\n", ff.FactorialR(5).ToString());  
            printf("FibImp(11)= %s\n", ff.FibonacciI(11).ToString());  
            printf("FibRec(11)= %s\n", ff.FibonacciR(11).ToString()); 

            // Create a (nemerle) list of integer values to test
            // From 5 to 50 by 5
            mutable values : list[int] = [];
            foreach (i in $[5,10..50])
                values ::= i;
                    
            // Benchmarking Fibonacci                       
            // 1 = Factorial Imperative              
            StaticFiborial.BenchmarkAlgorithm(1, values.Reverse());
            // 2 = Factorial Recursive  
            StaticFiborial.BenchmarkAlgorithm(2, values.Reverse());

            // Benchmarking Factorial              
            // 3 = Fibonacci Imperative  
            StaticFiborial.BenchmarkAlgorithm(3, values.Reverse());
            // 4 = Fibonacci Recursive  
            StaticFiborial.BenchmarkAlgorithm(4, values.Reverse());        

            // Stop and Exit 
            _ = Console.ReadLine();
        }
    }
}
&lt;/pre&gt;&lt;br /&gt;
And the Output is: &lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-RsydOKZ3ajM/TY9vABXaJ2I/AAAAAAAAF5A/Sei1PrF70JE/s1600/fiborial_n.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="640" src="http://3.bp.blogspot.com/-RsydOKZ3ajM/TY9vABXaJ2I/AAAAAAAAF5A/Sei1PrF70JE/s640/fiborial_n.PNG" width="478" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;a href="http://2.bp.blogspot.com/_0_HCzHGe4_k/TM8Wwm7ILyI/AAAAAAAAFyQ/AziXveRyTGo/s1600/output_delphi.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;br /&gt;
&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Humm, looks like Fibonnaci's algorithm implemented using recursion is definitively more complex than the others 3 right? I will grab these results for this and each of the upcoming posts to prepare a comparison of time execution between all the programming languages, then we will be able to talk about the algorithm's complexity as well.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Printing the Factorial and Fibonacci Series&lt;/b&gt;&lt;br /&gt;
&lt;pre class="csharp" name="code"&gt;using System;  
using System.Text;  
using System.Numerics;
using Nemerle.IO;

namespace FiborialSeries
{
    static class Fiborial
    {
        // Using a StringBuilder as a list of string elements  
        public static GetFactorialSeries(n : int) : string
        {  
            // Create the String that will hold the list  
            def series : StringBuilder = StringBuilder();  
            // We begin by concatenating the number you want to calculate  
            // in the following format: "!# ="  
            _ = series.Append("!");
            _ = series.Append(n);  
            _ = series.Append(" = ");  
            // We iterate backwards through the elements of the series  
            for (mutable i : int = n; i &amp;lt;= n &amp;amp;&amp;amp; i &amp;gt; 0; i--)  
            {  
                // and append it to the list  
                _ = series.Append(i);  
                if (i &amp;gt; 1)  
                    _ = series.Append(" * ");  
                else   
                    _ = series.Append(" = ");   
            }  
            // Get the result from the Factorial Method  
            // and append it to the end of the list  
            _ = series.Append(Factorial(n));  
            // return the list as a string  
            series.ToString();  
        }
        // Using a StringBuilder as a list of string elements  
        public static GetFibonnaciSeries(n : int) : string 
        {  
            // Create the String that will hold the list  
            def series : StringBuilder = StringBuilder();  
            // We begin by concatenating the first 3 values which  
            // are always constant  
            _ = series.Append("0, 1, 1");  
            // Then we calculate the Fibonacci of each element  
            // and add append it to the list  
            for (mutable i : int = 2; i &amp;lt;= n; i++)  
            {  
                if (i &amp;lt; n)  
                    _ = series.Append(", ");  
                else  
                    _ = series.Append(" = ");  
                  
                _ = series.Append(Fibonacci(i));  
            }  
            // return the list as a string  
            series.ToString();  
        }  
        // Static Method - Factorial Recursive
        public static Factorial(n : int) : BigInteger
        {            
            if (n == 1)
                 BigInteger(1);
            else 
                 BigInteger(n) * Factorial(n - 1);
        }        
        // Static Method - Fibonacci Recursive
        public static Fibonacci(n : int) : long
        {
            def oneLong : long = 1;
            if (n &amp;lt; 2)
                oneLong;
            else
                Fibonacci(n - 1) + Fibonacci(n - 2);
        }        
    }
        
    module Program
    {
        Main() : void
        {          
            printf("\nStatic Class\n");
            // Printing Factorial Series  
            printf("\n");
            printf("%s\n", Fiborial.GetFactorialSeries(5));
            printf("%s\n", Fiborial.GetFactorialSeries(7));  
            printf("%s\n", Fiborial.GetFactorialSeries(9));  
            printf("%s\n", Fiborial.GetFactorialSeries(11));  
            printf("%s\n", Fiborial.GetFactorialSeries(40));  
            // Printing Fibonacci Series  
            printf("\n");
            printf("%s\n", Fiborial.GetFibonnaciSeries(5));  
            printf("%s\n", Fiborial.GetFibonnaciSeries(7));  
            printf("%s\n", Fiborial.GetFibonnaciSeries(9));  
            printf("%s\n", Fiborial.GetFibonnaciSeries(11));  
            printf("%s\n", Fiborial.GetFibonnaciSeries(40));              
        }
    }
}
&lt;/pre&gt;&lt;br /&gt;
And the Output is:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-gefgraJE6Ew/TY9vVa9TQCI/AAAAAAAAF5E/JTNThf_e5zQ/s1600/fiborial_n_extras_series.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="345" src="http://1.bp.blogspot.com/-gefgraJE6Ew/TY9vVa9TQCI/AAAAAAAAF5E/JTNThf_e5zQ/s640/fiborial_n_extras_series.PNG" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Mixing Instance and Static Members in the same Class&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
We can also define instance classes that have both, instance and static members such as: fields, properties, constructors, methods, etc. However, we cannot do that if the class is marked as static because of the features mentioned in the previous post:&lt;br /&gt;
The main features of a static class are:&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;They only contain static members.&lt;/li&gt;
&lt;li&gt;They cannot be instantiated.&lt;/li&gt;
&lt;li&gt;They are sealed.&lt;/li&gt;
&lt;li&gt;They cannot contain Instance Constructors&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;pre class="csharp" name="code"&gt;using System;  
namespace FiborialExtrasN2
{
    // Instance Class
    class Fiborial  
    {  
        // Instance Field  
        mutable instanceCount : int;  
        // Static Field  
        static mutable staticCount : int;          
        // Instance Read-Only Property  
        // Within instance members, you can always use    
        // the "this" reference pointer to access your (instance) members.  
        public InstanceCount : int
        {  
            get { this.instanceCount; }  
        }  
        // Static Read-Only Property  
        // Remeber that Properties are Methods to the CLR, so, you can also  
        // define static properties for static fields.   
        // As with Static Methods, you cannot reference your class members  
        // with the "this" reference pointer since static members are not  
        // instantiated.          
        public static StaticCount : int
        {  
            get { staticCount; }  
        }  
        // Instance Constructor  
        public this()  
        {  
            this.instanceCount = 0;  
            Console.WriteLine("\nInstance Constructor {0}", this.instanceCount);  
        }  
        // Static Constructor  
        static this()  
        {  
            staticCount = 0;  
            Console.WriteLine("\nStatic Constructor {0}", staticCount);  
        }  
  
        // Instance Method  
        public Factorial(n : int) : void
        {  
            this.instanceCount += 1;  
            Console.WriteLine("\nFactorial({0})", n);  
        }  
  
        // Static Method  
        public static Fibonacci(n : int) : void
        {  
            staticCount += 1;  
            Console.WriteLine("\nFibonacci({0})", n);  
        }                   
    }
        
    module Program
    {
        Main() : void
        {          
            // Calling Static Constructor and Methods  
            // No need to instantiate  
            Fiborial.Fibonacci(5);              
  
            // Calling Instance Constructor and Methods  
            // Instance required  
            def fib : Fiborial = Fiborial();  
            fib.Factorial(5);              
  
            Fiborial.Fibonacci(15);              
            fib.Factorial(5);  
  
            // Calling Instance Constructor and Methods  
            // for a second object  
            def fib2 : Fiborial = Fiborial();  
            fib2.Factorial(5);  
              
            Console.WriteLine();  
            // Calling Static Property  
            Console.WriteLine("Static Count = {0}", Fiborial.StaticCount);  
            // Calling Instance Property of object 1 and 2  
            Console.WriteLine("Instance 1 Count = {0}", fib.InstanceCount);  
            Console.WriteLine("Instance 2 Count = {0}", fib2.InstanceCount); 
        }
    }
}
&lt;/pre&gt;&lt;br /&gt;
And the Output is:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-OpwI1augWPk/TY9vqUwmDuI/AAAAAAAAF5I/MEQCMmYKHt0/s1600/fiborial_n_extras2.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="391" src="http://1.bp.blogspot.com/-OpwI1augWPk/TY9vqUwmDuI/AAAAAAAAF5I/MEQCMmYKHt0/s400/fiborial_n_extras2.PNG" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://2.bp.blogspot.com/_0_HCzHGe4_k/TJYz5ZgkFGI/AAAAAAAAFwk/Y8rwLu2Bags/s1600/output_ipy_ext.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;br /&gt;
&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Factorial using System.Int64, System.Double, System.Numerics.BigInteger&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
The Factorial of numbers over 20 are massive!&lt;br /&gt;
For instance: !40 = 815915283247897734345611269596115894272000000000!&lt;br /&gt;
Because of this, the previous version of this program was giving the "wrong" result &lt;br /&gt;
!40 = -70609262346240000 when using "long" (System.Int64) type, but it was not until I did the Fiborial version in VB.NET that I realized about this faulty code, because instead of giving me a wrong value, VB.NET, JScript.NET, Boo execution thrown an Overflow Exception when using the "Long/long" (System.Int64) type.&lt;br /&gt;
&lt;br /&gt;
My first idea was to use ulong and ULong, but both failed for "big" numbers. I then used Double (double floating point) type and got no more exception/wrong result. The result of the factorial was now correct !40 = 1.1962222086548E+56, but still I wanted to show the Integer value of it, so I did some research and found that there is a new System.Numerics.BigInteger class in the .NET Framework 4.0. Adding the reference to the project and using this new class as the return type of the Factorial methods, I was able to get the result I was expecting.&lt;br /&gt;
!40 = 815915283247897734345611269596115894272000000000&lt;br /&gt;
&lt;br /&gt;
What I also found was that using different types change the time the algorithm takes to finish:&lt;br /&gt;
System.Int64 &amp;lt; System.Double &amp;lt; System.Numerics.BigInteger  &lt;br /&gt;
Almost by double!&lt;br /&gt;
&lt;br /&gt;
To illustrate what I just "tried" to say, lets have a look at the following code and the output we get.  &lt;br /&gt;
&lt;br /&gt;
&lt;pre class="csharp" name="code"&gt;#pragma indent
using System;  
using System.Numerics;  
using System.Diagnostics;  
using System.Console;

namespace FiborialExtrasCs3

    module Program
        // Long Factorial
        public static FactorialInt64(n : int) : long
            def oneLong : long = 1;
            if (n == 1)
                 oneLong;
            else 
                 n * FactorialInt64(n - 1);

        // Double Factorial
        public static FactorialDouble(n : int) : double
            def oneDouble : double = 1;
            if (n == 1)
                oneDouble;
            else 
                 n * FactorialDouble(n - 1);

        // BigInteger Factorial
        public static FactorialBigInteger(n : int) : BigInteger
            if (n == 1)
                 BigInteger(1);
            else 
                 BigInteger(n) * FactorialBigInteger(n - 1);
    
        Main() : void
            def timer : Stopwatch = Stopwatch();  
            mutable facIntResult : long = 0;  
            mutable facDblResult : double = 0;  
            mutable facBigResult : BigInteger = BigInteger(0);
                        
            WriteLine("\nFactorial using Int64");
            // Benchmark Factorial using Int64
            // Overflow Exception!!!
            try
                foreach (i in $[5,10..50])
                    timer.Start();  
                    facIntResult = FactorialInt64(i);  
                    timer.Stop();
                    WriteLine(" ({0}) = {1} : {2}", i, timer.Elapsed, facIntResult);  
            catch
                | ex is OverflowException =&amp;gt;
                    // yummy ^_^  
                    WriteLine("Oops! {0}", ex.Message);
            
            WriteLine("\nFactorial using Double");  
            // Benchmark Factorial using Double  
            foreach (i in $[5,10..50])
                timer.Start();  
                facDblResult = FactorialDouble(i);
                timer.Stop();
                WriteLine(" ({0}) = {1} : {2}", i, timer.Elapsed, facDblResult);  
            
            WriteLine("\nFactorial using BigInteger");  
            // Benchmark Factorial using BigInteger
            foreach (i in $[5,10..50])
                timer.Start();
                facBigResult = FactorialBigInteger(i);
                timer.Stop();
                WriteLine(" ({0}) = {1} : {2}", i, timer.Elapsed, facBigResult);
&lt;/pre&gt;&lt;br /&gt;
NOTE: you need to manually add a reference to the System.Numerics.dll assembly to your project so you can add it to your code.&lt;br /&gt;
&lt;br /&gt;
And the Output is:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-GdIEa1Uatg8/TY9wCJl6TbI/AAAAAAAAF5M/AUQ55fdqdSE/s1600/fiborial_n_extras_big_int.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="478" src="http://1.bp.blogspot.com/-GdIEa1Uatg8/TY9wCJl6TbI/AAAAAAAAF5M/AUQ55fdqdSE/s640/fiborial_n_extras_big_int.PNG" width="640" /&gt;&amp;nbsp;&lt;/a&gt;&lt;a href="http://1.bp.blogspot.com/-GdIEa1Uatg8/TY9wCJl6TbI/AAAAAAAAF5M/AUQ55fdqdSE/s1600/fiborial_n_extras_big_int.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&amp;nbsp;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/694679611587040520-7518171880813965006?l=carlosqt.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/NQdrYdUdwIKSE1H5Dpw9-LUd_pQ/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/NQdrYdUdwIKSE1H5Dpw9-LUd_pQ/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/NQdrYdUdwIKSE1H5Dpw9-LUd_pQ/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/NQdrYdUdwIKSE1H5Dpw9-LUd_pQ/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/CarlosQuintanillasBlog/~4/nXw_hqupRZQ" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://carlosqt.blogspot.com/feeds/7518171880813965006/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://carlosqt.blogspot.com/2011/03/factorial-and-fibonacci-in-nemerle.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/694679611587040520/posts/default/7518171880813965006?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/694679611587040520/posts/default/7518171880813965006?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/CarlosQuintanillasBlog/~3/nXw_hqupRZQ/factorial-and-fibonacci-in-nemerle.html" title="Factorial and Fibonacci in Nemerle" /><author><name>Carlos QT</name><uri>http://www.blogger.com/profile/15415604076909500411</uri><email>carlosqt@gmail.com</email><gd:extendedProperty name="OpenSocialUserId" value="14144067369073378952" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/-RsydOKZ3ajM/TY9vABXaJ2I/AAAAAAAAF5A/Sei1PrF70JE/s72-c/fiborial_n.PNG" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://carlosqt.blogspot.com/2011/03/factorial-and-fibonacci-in-nemerle.html</feedburner:origLink></entry><entry gd:etag="W/&quot;C0YDRX08eSp7ImA9WhZUEE8.&quot;"><id>tag:blogger.com,1999:blog-694679611587040520.post-1272869620253962054</id><published>2011-03-08T15:01:00.000-08:00</published><updated>2011-06-02T06:26:14.371-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-06-02T06:26:14.371-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Boo" /><category scheme="http://www.blogger.com/atom/ns#" term="CLR" /><title>Factorial and Fibonacci in Boo</title><content type="html">&lt;a class="twitter-share-button" data-count="horizontal" data-via="carlosqt" href="http://twitter.com/share"&gt;Tweet&lt;/a&gt;&lt;script src="http://platform.twitter.com/widgets.js" type="text/javascript"&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;br /&gt;
Here below a little program in Boo that implements 2 classes (in fact, they are 3). There is the main class, called Fiborial (Fibo(nnacci)+(Facto)rial) that implements the &lt;i&gt;Fibonacci&lt;/i&gt; and the &lt;i&gt;Factorial&lt;/i&gt; algorithms in two ways, one &lt;i&gt;Recursive&lt;/i&gt; (using recursion) and the other &lt;i&gt;Imperative&lt;/i&gt; (using loops and states). The second class is just an instance class that does the same thing, but its there just to show the difference between static and instance classes, and finally the third one (which will not appear in other languages) is the Program class which has the static execution method "Main".&lt;br /&gt;
&lt;br /&gt;
You can also find 3 more little examples at the bottom. One prints out the Factorial's Series and Fibonacci's Series, the second one just shows a class that mixes both: static and instance members, and finally the third one that uses different return types (including System.Numerics.BigInteger) for the Factorial method to compare the timing and result.&lt;br /&gt;
&lt;br /&gt;
As with the previous posts, you can copy and paste the code below in your favorite IDE/Editor and start playing and learning with it. This little "working" program will teach you some more basics of the Programming Language.&lt;br /&gt;
&lt;br /&gt;
There are some "comments" on the code added just to tell you what are or how are some features called. In case you want to review the theory, you can read my previous post, where I give a definition of each of the concepts mentioned on the code. You can find it here: &lt;a href="http://carlosqt.blogspot.com/2011/01/new-series-factorial-and-fibonacci.html"&gt;http://carlosqt.blogspot.com/2011/01/new-series-factorial-and-fibonacci.html&lt;/a&gt;&amp;nbsp;&lt;a href="http://carlosqt.blogspot.com/2010/08/new-series-languages-basics-by-example.html"&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;The Fiborial Program&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="csharp" name="code"&gt;// Factorial and Fibonacci in Boo
namespace FiborialBoo
import System
import System.Collections.Generic
import System.Diagnostics
import System.Numerics

// Static Class  
public static class StaticFiborial:
    // Static Field
    private className as string
    // Static Constructor
    def constructor():
        className = "Static Constructor"
        print className
    // Static Method - Factorial Recursive  
    public def FactorialR(n as int) as BigInteger:
        if n == 1:
            return 1  
        else:  
            return n * FactorialR(n - 1)
    // Static Method - Factorial Imperative  
    public def FactorialI(n as int) as BigInteger:
        res as BigInteger = 1
        for i as int in range(n, 1):
            res *= i
        return res
    // Static Method - Fibonacci Recursive  
    public def FibonacciR(n as int) as long:
        if n &amp;lt; 2:
            return 1  
        else:  
            return FibonacciR(n - 1) + FibonacciR(n - 2)
    // Static Method - Fibonacci Imperative
    public def FibonacciI(n as int) as long:
        pre as long = 1
        cur as long = 1
        tmp as long = 0
        for i as int in range(2, n+1):
            tmp = cur + pre
            pre = cur
            cur = tmp
        return cur
    // Static Method - Benchmarking Algorithms
    public def BenchmarkAlgorithm(algorithm as int, values as List[of int]) as void:
        timer as Stopwatch = Stopwatch()
        i as int = 0
        testValue as int = 0
        facTimeResult as BigInteger = 0
        fibTimeResult as long = 0  
        
        // "if-elif-else" Flow Control Statement  
        if algorithm == 1:
            print "\nFactorial Imperative:"
            // "For in range" Loop Statement 
            for i in range(values.Count):                
                testValue = values[i]
                // Taking Time  
                timer.Start()
                facTimeResult = FactorialI(testValue)
                timer.Stop()                          
                // Getting Time  
                print " (${testValue}) = ${timer.Elapsed}"
        elif algorithm == 2:
            print "\nFactorial Recursive:"
            // "While" Loop Statement
            while i &amp;lt; len(values):
                testValue = values[i]
                // Taking Time  
                timer.Start()
                facTimeResult = FactorialR(testValue)
                timer.Stop()                          
                // Getting Time  
                print " (${testValue}) = ${timer.Elapsed}"
                i += 1
        elif algorithm == 3:
            print "\nFibonacci Imperative:" 
            // "For in List" Loop Statement             
            for item as int in values:
                testValue = item
                // Taking Time
                timer.Start()
                fibTimeResult = FibonacciI(testValue)
                timer.Stop()
                // Getting Time
                print " (${testValue}) = ${timer.Elapsed}"                
        elif algorithm == 4:
            print "\nFibonacci Recursive:"
            // "For in List" Loop Statement 
            for item as int in values:
                testValue = item
                // Taking Time
                timer.Start()
                fibTimeResult = FibonacciR(testValue)
                timer.Stop()
                // Getting Time
                print " (${testValue}) = ${timer.Elapsed}"
        else:
            print "DONG!"

// Instance Class
public class InstanceFiborial:
    // Instances Field
    private className as string
    // Instance Constructor
    def constructor():
        self.className = "Instance Constructor"
        print self.className
    // Instance Method - Factorial Recursive
    public def FactorialR(n as int) as BigInteger:
        // Calling Static Method
        return StaticFiborial.FactorialR(n)
    // Instance Method - Factorial Imperative
    public def FactorialI(n as int) as BigInteger:
        // Calling Static Method
        return StaticFiborial.FactorialI(n)
    // Instance Method - Fibonacci Recursive  
    public def FibonacciR(n as int) as long:
        // Calling Static Method
        return StaticFiborial.FibonacciR(n)
    // Instance Method - Fibonacci Imperative
    public def FibonacciI(n as int) as long:
        // Calling Static Method
        return StaticFiborial.FibonacciI(n)

public def Main(argv as (string)):
    print "\nStatic Class"
    // Calling Static Class and Methods
    // No instantiation needed. Calling method directly from the class
    print "FacImp(5) = ${StaticFiborial.FactorialI(5)}"
    print "FacRec(5) = ${StaticFiborial.FactorialR(5)}"
    print "FibImp(11)= ${StaticFiborial.FibonacciI(11)}"
    print "FibRec(11)= ${StaticFiborial.FibonacciR(11)}"

    print "\nInstance Class"
    // Calling Instance Class and Methods
    // Need to instantiate before using. Calling method from instantiated object
    ff as InstanceFiborial = InstanceFiborial()
    print "FacImp(5) = ${ff.FactorialI(5)}"
    print "FacRec(5) = ${ff.FactorialR(5)}"
    print "FibImp(11)= ${ff.FibonacciI(11)}"
    print "FibRec(11)= ${ff.FibonacciR(11)}"

    // Create a (Boo) list of values to test  
    // From 5 to 50 by 5
    values as List[of int] = List[of int]()
    for i as int in range(5,55,5):
        values.Add(i)
    
    // Benchmarking Fibonacci
    // 1 = Factorial Imperative
    StaticFiborial.BenchmarkAlgorithm(1, values)
    // 2 = Factorial Recursive
    StaticFiborial.BenchmarkAlgorithm(2, values)
    // Benchmarking Factorial
    // 3 = Fibonacci Imperative
    StaticFiborial.BenchmarkAlgorithm(3, values)
    // 4 = Fibonacci Recursive
    StaticFiborial.BenchmarkAlgorithm(4, values)

    // Stop and Exit
    Console.ReadKey(true)
&lt;/pre&gt;&lt;br /&gt;
And the Output is: &lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="https://lh3.googleusercontent.com/-topi029LuME/TXZATCMgC0I/AAAAAAAAF4w/vXwNV-CdehE/s1600/fiborial_boo.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="640" src="https://lh3.googleusercontent.com/-topi029LuME/TXZATCMgC0I/AAAAAAAAF4w/vXwNV-CdehE/s640/fiborial_boo.PNG" width="318" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;a href="http://2.bp.blogspot.com/_0_HCzHGe4_k/TM8Wwm7ILyI/AAAAAAAAFyQ/AziXveRyTGo/s1600/output_delphi.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;br /&gt;
&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Humm, looks like Fibonnaci's algorithm implemented using recursion is definitively more complex than the others 3 right? I will grab these results for this and each of the upcoming posts to prepare a comparison of time execution between all the programming languages, then we will be able to talk about the algorithm's complexity as well.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Printing the Factorial and Fibonacci Series&lt;/b&gt;&lt;br /&gt;
&lt;pre class="csharp" name="code"&gt;namespace FiborialSeries
import System
import System.Text
import System.Numerics

// Static Class  
public static class Fiborial:
    // Using a StringBuilder as a list of string elements  
    public def GetFactorialSeries(n as int) as string:  
        // Create the String that will hold the list  
        series as StringBuilder = StringBuilder() 
        // We begin by concatenating the number you want to calculate  
        // in the following format: "!# ="  
        series.Append("!")
        series.Append(n)
        series.Append(" = ")
        // We iterate backwards through the elements of the series  
        for i as int in range(n, 1):
            // and append it to the list  
            series.Append(i)
            if i &amp;gt; 1: 
                series.Append(" * ")  
            else:   
                series.Append(" = ")
        // Get the result from the Factorial Method  
        // and append it to the end of the list  
        series.Append(Factorial(n))
        // return the list as a string  
        return series.ToString()

    // Using a StringBuilder as a list of string elements  
    public def GetFibonnaciSeries(n as int) as string:
        // Create the String that will hold the list  
        series as StringBuilder = StringBuilder() 
        // We begin by concatenating the first 3 values which  
        // are always constant  
        series.Append("0, 1, 1")  
        // Then we calculate the Fibonacci of each element  
        // and add append it to the list  
        for i as int in range(2, n+1):
            if i &amp;lt; n:
                series.Append(", ") 
            else:
                series.Append(" = ")  
            series.Append(Fibonacci(i))
        // return the list as a string  
        return series.ToString()
        
    public def Factorial(n as int) as BigInteger:
        if n == 1:
            return 1  
        else:  
            return n * Factorial(n - 1)    
    
    public def Fibonacci(n as int) as long:
        if n &amp;lt; 2:
            return 1  
        else:  
            return Fibonacci(n - 1) + Fibonacci(n - 2)

public def Main(argv as (string)):
    // Printing Factorial Series  
    print ""
    print Fiborial.GetFactorialSeries(5)
    print Fiborial.GetFactorialSeries(7)
    print Fiborial.GetFactorialSeries(9)
    print Fiborial.GetFactorialSeries(11)
    print Fiborial.GetFactorialSeries(40)
    // Printing Fibonacci Series  
    print ""
    print Fiborial.GetFibonnaciSeries(5)
    print Fiborial.GetFibonnaciSeries(7)
    print Fiborial.GetFibonnaciSeries(9)
    print Fiborial.GetFibonnaciSeries(11)
    print Fiborial.GetFibonnaciSeries(40)
    
    Console.ReadKey(true)
&lt;/pre&gt;&lt;br /&gt;
And the Output is:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="https://lh6.googleusercontent.com/-ixwQupNlG24/TXa0XedqOAI/AAAAAAAAF40/7sletmsSRhw/s1600/fiborial_boo_extras_series.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="270" src="https://lh6.googleusercontent.com/-ixwQupNlG24/TXa0XedqOAI/AAAAAAAAF40/7sletmsSRhw/s640/fiborial_boo_extras_series.PNG" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Mixing Instance and Static Members in the same Class&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
We can also define instance classes that have both, instance and static members such as: fields, properties, constructors, methods, etc. However, we cannot do that if the class is marked as static because of the features mentioned in the previous post:&lt;br /&gt;
The main features of a static class are:&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;They only contain static members.&lt;/li&gt;
&lt;li&gt;They cannot be instantiated.&lt;/li&gt;
&lt;li&gt;They are sealed.&lt;/li&gt;
&lt;li&gt;They cannot contain Instance Constructors&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;pre class="csharp" name="code"&gt;namespace FiborialExtrasBoo2
import System

// Instance Classes can have both: static and instance members.   
// However, Static Classes only allow static members to be defined.  
// If you declare our next example class as static  
// (static class Fiborial) you will get the following compile error  
// Error: cannot declare instance members in a static class  
    
// Instance Class  
public class Fiborial:
    // Instance Field
    private instanceCount as int
    // Static Field
    private static staticCount as int
    // Instance Read-Only Property  
    // Within instance members, you can always use    
    // the "self" reference pointer to access your (instance) members.            
    public InstanceCount as int:
        get:
            return self.instanceCount  
    // Static Read-Only Property  
    // Remeber that Properties are Methods to the CLR, so, you can also  
    // define static properties for static fields.   
    // As with Static Methods, you cannot reference your class members  
    // with the "self" reference pointer since static members are not  
    // instantiated.          
    public static StaticCount as int:
        get:  
            return staticCount  
    // Instance Constructor  
    public def constructor():
        self.instanceCount = 0  
        print "\nInstance Constructor ${self.instanceCount}"
    // Static Constructor  
    private static def constructor():
        staticCount = 0  
        print "\nStatic Constructor ${staticCount}"
    // Instance Method
    public def Factorial(n as int) as void: 
        self.instanceCount += 1 
        print "\nFactorial(${n})" 
    // Static Method  
    public static def Fibonacci(n as int) as void: 
        staticCount += 1
        print "\nFibonacci(${n})" 

public def Main(argv as (string)):
    // Calling Static Constructor and Methods  
    // No need to instantiate  
    Fiborial.Fibonacci(5)
    
    // Calling Instance Constructor and Methods  
    // Instance required  
    fib as Fiborial = Fiborial()  
    fib.Factorial(5)
    
    Fiborial.Fibonacci(15)
    fib.Factorial(5)
    
    // Calling Instance Constructor and Methods  
    // for a second object  
    fib2 as Fiborial = Fiborial()
    fib2.Factorial(5)
    
    print ""
    // Calling Static Property  
    print "Static Count = ${Fiborial.StaticCount}"
    // Calling Instance Property of object 1 and 2  
    print "Instance 1 Count = ${fib.InstanceCount}"
    print "Instance 2 Count = ${fib2.InstanceCount}"
    Console.ReadKey(true)
&lt;/pre&gt;&lt;br /&gt;
And the Output is:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="https://lh3.googleusercontent.com/-egH7NhJApKk/TXa0g5o1oMI/AAAAAAAAF44/Q0aq8RNVF6Y/s1600/fiborial_boo_extras2.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="318" src="https://lh3.googleusercontent.com/-egH7NhJApKk/TXa0g5o1oMI/AAAAAAAAF44/Q0aq8RNVF6Y/s400/fiborial_boo_extras2.PNG" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;a href="http://4.bp.blogspot.com/_0_HCzHGe4_k/TM8x5bVLv0I/AAAAAAAAFyU/ZHtgJE97Fdk/s1600/delphi_properties.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;br /&gt;
&lt;/a&gt;&lt;br /&gt;
&lt;a href="http://2.bp.blogspot.com/_0_HCzHGe4_k/TJYz5ZgkFGI/AAAAAAAAFwk/Y8rwLu2Bags/s1600/output_ipy_ext.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;br /&gt;
&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Factorial using System.Int64, System.Double, System.Numerics.BigInteger&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
The Factorial of numbers over 20 are massive!&lt;br /&gt;
For instance: !40 = 815915283247897734345611269596115894272000000000!&lt;br /&gt;
Because of this, the previous version of this program was giving the "wrong" result &lt;br /&gt;
!40 = -70609262346240000 when using "long" (System.Int64) type, but it was not until I did the Fiborial version in VB.NET that I realized about this faulty code, because instead of giving me a wrong value, VB.NET, JScript.NET, Boo execution thrown an Overflow Exception when using the "Long/long" (System.Int64) type.&lt;br /&gt;
&lt;br /&gt;
My first idea was to use ulong and ULong, but both failed for "big" numbers. I then used Double (double floating point) type and got no more exception/wrong result. The result of the factorial was now correct !40 = 1.1962222086548E+56, but still I wanted to show the Integer value of it, so I did some research and found that there is a new System.Numerics.BigInteger class in the .NET Framework 4.0. Adding the reference to the project and using this new class as the return type of the Factorial methods, I was able to get the result I was expecting.&lt;br /&gt;
!40 = 815915283247897734345611269596115894272000000000&lt;br /&gt;
&lt;br /&gt;
What I also found was that using different types change the time the algorithm takes to finish:&lt;br /&gt;
System.Int64 &amp;lt; System.Double &amp;lt; System.Numerics.BigInteger  &lt;br /&gt;
Almost by double!&lt;br /&gt;
&lt;br /&gt;
To illustrate what I just "tried" to say, lets have a look at the following code and the output we get.  &lt;br /&gt;
&lt;br /&gt;
&lt;pre class="python" name="code"&gt;namespace FiborialExtrasBoo3
import System
import System.Diagnostics
import System.Numerics

# Long Factorial
def FactorialInt64(n as int) as long:
    if n == 1:
        return 1
    else:
        return n * FactorialInt64(n - 1)
    
# Double/Number Factorial   
def FactorialDouble(n as int) as double:
    if n == 1:
        return 1
    else:
        return n * FactorialDouble(n - 1)
 
# BigInteger Factorial   
def FactorialBigInteger(n as int) as BigInteger:  
    if n == 1:
        return 1
    else:
        return n * FactorialBigInteger(n - 1)

public def Main(argv as (string)):
    timer as Stopwatch = Stopwatch()
    facIntResult as long = 0
    facDblResult as double = 0
    facBigResult as BigInteger = 0  
    i as int = 0
    
    print "\nFactorial using Int64"
    # Benchmark Factorial using Int64  
    # Overflow Exception!!!
    try:
        for i as int in range(5,55,5):
            timer.Start()
            facIntResult = FactorialInt64(i)
            timer.Stop()        
            print " (${i}) = ${timer.Elapsed} : ${facIntResult}"
    except ex as ArithmeticException:
        # yummy ^_^
        print "Oops! ${ex.Message} "
    
    print "\nFactorial using Double"
    # Benchmark Factorial using Double
    for i as int in range(5,55,5):
        timer.Start()
        facDblResult = FactorialDouble(i)
        timer.Stop()        
        print " (${i}) = ${timer.Elapsed} : ${facDblResult}"
    
    print "\nFactorial using BigInteger"
    # Benchmark Factorial using BigInteger
    for i as int in range(5,55,5):
        timer.Start()
        facBigResult = FactorialBigInteger(i)
        timer.Stop()        
        print " (${i}) = ${timer.Elapsed} : ${facBigResult}"
    
    Console.ReadKey(true)
&lt;/pre&gt;&lt;br /&gt;
NOTE: you need to manually add a reference to the System.Numerics.dll assembly to your project so you can add it to your code.&lt;br /&gt;
&lt;br /&gt;
And the Output is:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="https://lh3.googleusercontent.com/-Q2JFWHAdRx4/TXa0qO8wQdI/AAAAAAAAF48/FNHVRhB5-BU/s1600/fiborial_boo_extras_big_int.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="442" src="https://lh3.googleusercontent.com/-Q2JFWHAdRx4/TXa0qO8wQdI/AAAAAAAAF48/FNHVRhB5-BU/s640/fiborial_boo_extras_big_int.PNG" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/694679611587040520-1272869620253962054?l=carlosqt.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/_WW7ZoIxNkoKLdxD9yyTxTnn_RY/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/_WW7ZoIxNkoKLdxD9yyTxTnn_RY/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/_WW7ZoIxNkoKLdxD9yyTxTnn_RY/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/_WW7ZoIxNkoKLdxD9yyTxTnn_RY/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/CarlosQuintanillasBlog/~4/k6ZQL3HoP-U" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://carlosqt.blogspot.com/feeds/1272869620253962054/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://carlosqt.blogspot.com/2011/03/factorial-and-fibonacci-in-boo.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/694679611587040520/posts/default/1272869620253962054?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/694679611587040520/posts/default/1272869620253962054?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/CarlosQuintanillasBlog/~3/k6ZQL3HoP-U/factorial-and-fibonacci-in-boo.html" title="Factorial and Fibonacci in Boo" /><author><name>Carlos QT</name><uri>http://www.blogger.com/profile/15415604076909500411</uri><email>carlosqt@gmail.com</email><gd:extendedProperty name="OpenSocialUserId" value="14144067369073378952" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://lh3.googleusercontent.com/-topi029LuME/TXZATCMgC0I/AAAAAAAAF4w/vXwNV-CdehE/s72-c/fiborial_boo.PNG" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://carlosqt.blogspot.com/2011/03/factorial-and-fibonacci-in-boo.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DE8DSXk6eip7ImA9Wx9aFks.&quot;"><id>tag:blogger.com,1999:blog-694679611587040520.post-2628638876448139287</id><published>2011-03-06T11:02:00.000-08:00</published><updated>2011-03-09T02:34:38.712-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-03-09T02:34:38.712-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="F#" /><category scheme="http://www.blogger.com/atom/ns#" term="CLR" /><title>Factorial and Fibonacci in F#</title><content type="html">&lt;a class="twitter-share-button" data-count="horizontal" data-via="carlosqt" href="http://twitter.com/share"&gt;Tweet&lt;/a&gt;&lt;script src="http://platform.twitter.com/widgets.js" type="text/javascript"&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;br /&gt;
WARNING! I know that F# is intended to be use in a very Functional way, however, my goal is to show its Imperative and OO language features, so it can be compared with other 19 OO languages. Said that, if you know how to do something on the examples below in a more Functional style you can add it in a comment :)&lt;br /&gt;
&lt;br /&gt;
Here below a little program in F# that implements 2 classes (in fact, they are 3). There is the main class, called Fiborial (Fibo(nnacci)+(Facto)rial) that implements the &lt;i&gt;Fibonacci&lt;/i&gt; and the &lt;i&gt;Factorial&lt;/i&gt; algorithms in two ways, one &lt;i&gt;Recursive&lt;/i&gt; (using recursion) and the other &lt;i&gt;Imperative&lt;/i&gt; (using loops and states). The second class is just an instance class that does the same thing, but its there just to show the difference between static and instance classes, and finally the third one (which will not appear in other languages) is the Program class which has the static execution method "Main".&lt;br /&gt;
&lt;br /&gt;
You can also find 3 more little examples at the bottom. One prints out the Factorial's Series and Fibonacci's Series, the second one just shows a class that mixes both: static and instance members, and finally the third one that uses different return types (including System.Numerics.BigInteger) for the Factorial method to compare the timing and result.&lt;br /&gt;
&lt;br /&gt;
As with the previous posts, you can copy and paste the code below in your favorite IDE/Editor and start playing and learning with it. This little "working" program will teach you some more basics of the Programming Language.&lt;br /&gt;
&lt;br /&gt;
There are some "comments" on the code added just to tell you what are or how are some features called. In case you want to review the theory, you can read my previous post, where I give a definition of each of the concepts mentioned on the code. You can find it here: &lt;a href="http://carlosqt.blogspot.com/2011/01/new-series-factorial-and-fibonacci.html"&gt;http://carlosqt.blogspot.com/2011/01/new-series-factorial-and-fibonacci.html&lt;/a&gt;&amp;nbsp;&lt;a href="http://carlosqt.blogspot.com/2010/08/new-series-languages-basics-by-example.html"&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
In F# like in VB.NET there is a type called Module. An F# module is a grouping of F# code constructs such as types, values, function values, and code in do bindings. It is implemented as a common language runtime (CLR) class that has only static members. Normally I would only use the Module type as the first example, however, here I included both, an instance class with only Static Members and a second example using Module. The syntax for the members declaration varies so I wanted to include both even if we see a second example in the Mixing Instance and Static members program.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;The Fiborial Program (using Type = Instance Class)&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="csharp" name="code"&gt;// Factorial and Fibonacci in F#
namespace FiborialFs
open System  
open System.Collections.Generic
open System.Diagnostics
open System.Numerics

// Instance Class 
// with all static members 
type StaticFiborial() = class
    // Static Field
    static let mutable className:string = ""
    // Static Constructor/Initializer(s) 
    static do className &amp;lt;- "Static Constructor"    
    static do printfn "%s" className    
    // Static Method - Factorial Recursive
    // in F#: type bigint = BigInteger
    static member public FactorialR(n:int) : bigint =
        if n = 1 then 
            bigint(1)
        else 
            bigint(n) * StaticFiborial.FactorialR(n-1)
    // Static Method - Factorial Imperative
    static member public FactorialI(n:int) : bigint =
        let mutable res:bigint = bigint(1)
        for i = n downto 1 do 
            res &amp;lt;- res * bigint(i)
        res
    // Static Method - Fibonacci Recursive
    static member public FibonacciR(n:int) : int64 =
        if (n &amp;lt; 2) then
            int64(1)
        else  
            StaticFiborial.FibonacciR(n - 1) + StaticFiborial.FibonacciR(n - 2)
    // Static Method - Fibonacci Imperative
    static member public FibonacciI(n:int) : int64 =
        let mutable pre:int64 = int64(1)
        let mutable cur:int64 = int64(1)
        let mutable tmp:int64 = int64(0)
        for i = 2 to n do
            tmp &amp;lt;- cur + pre
            pre &amp;lt;- cur
            cur &amp;lt;- tmp
        cur
    // Static Method - Benchmarking Algorithms
    static member public BenchmarkAlgorithm(algorithm:int, values:list&amp;lt;int&amp;gt;) =
        let timer = new Stopwatch()
        let mutable i:int = 1
        let mutable testValue:int = 1
        let mutable facTimeResult:bigint = bigint(0)
        let mutable fibTimeResult:int64 = int64(0)

        // "if-elif-else" Flow Control Statement
        if algorithm = 1 then
            printfn "\nFactorial Imperative:" 
            // "For to" Loop Statement
            for i = 1 to values.Length - 1 do
                testValue &amp;lt;- values.Item(i)
                // Taking Time  
                timer.Start()
                facTimeResult &amp;lt;- StaticFiborial.FactorialI(testValue)
                timer.Stop()
                // Getting Time  
                printfn " (%s) = %s" (testValue.ToString()) (timer.Elapsed.ToString())

        elif algorithm = 2 then
            printfn "\nFactorial Recursive:" 
            // "While" Loop Statement
            while i &amp;lt; values.Length - 1 do  
                testValue &amp;lt;- values.Item(i)
                // Taking Time  
                timer.Start()
                facTimeResult &amp;lt;- StaticFiborial.FactorialR(testValue)
                timer.Stop()
                // Getting Time  
                printfn " (%s) = %s" (testValue.ToString()) (timer.Elapsed.ToString())
                i &amp;lt;- i + 1

        elif algorithm = 3 then
            printfn "\nFibonacci Imperative:"
            // "For in" Loop Statement
            for item in values do
                testValue &amp;lt;- item
                // Taking Time  
                timer.Start();  
                fibTimeResult &amp;lt;- StaticFiborial.FibonacciI(testValue)
                timer.Stop();  
                // Getting Time  
                printfn " (%s) = %s" (testValue.ToString()) (timer.Elapsed.ToString())

        elif algorithm = 4 then
            printfn "\nFibonacci Recursive:"
            // "For in" Loop Statement
            for item in values do
                testValue &amp;lt;- item
                // Taking Time  
                timer.Start();  
                fibTimeResult &amp;lt;- StaticFiborial.FibonacciR(testValue)
                timer.Stop();  
                // Getting Time  
                printfn " (%s) = %s" (testValue.ToString()) (timer.Elapsed.ToString())

        else 
            printfn "DONG!" 
end 

// Instance Class  
type InstanceFiborial() = class   
        // Instance Field
        let mutable className:string = ""
        // Instance Constructor/Initializer(s) 
        do className &amp;lt;- "Instance Constructor"
        do printfn "%s" className
        // Instance Method - Factorial Recursive  
        member public self.FactorialR(n:int) : bigint =
            // Calling Static Method  
            StaticFiborial.FactorialR(n)  
        // Instance Method - Factorial Imperative  
        member public self.FactorialI(n:int) : bigint =
            // Calling Static Method  
            StaticFiborial.FactorialI(n)  
        // Instance Method - Fibonacci Recursive  
        member public self.FibonacciR(n:int) : int64 =
            // Calling Static Method  
            StaticFiborial.FibonacciR(n)
        // Instance Method - Factorial Imperative  
        member public self.FibonacciI(n:int) : int64 =
            // Calling Static Method  
            StaticFiborial.FibonacciI(n);  
end

module Program = 
    //printfn "%s" (Fiborial.FactorialR(40).ToString())
    printfn "\nStatic Class"
    // Calling Instance Class with Static Methods  
    // No instantiation needed. Calling method directly from the class  
    printfn "FacImp(5) = {%s}" (StaticFiborial.FactorialI(5).ToString())  
    printfn "FacRec(5) = {%s}" (StaticFiborial.FactorialR(5).ToString())  
    printfn "FibImp(11)= {%s}" (StaticFiborial.FibonacciI(11).ToString())  
    printfn "FibRec(11)= {%s}" (StaticFiborial.FibonacciR(11).ToString())  
  
    printfn "\nInstance Class"
    // Calling Instance Class and Methods   
    // Need to instantiate before using. Calling method from instantiated object  
    let ff:InstanceFiborial = new InstanceFiborial()  
    Console.WriteLine("FacImp(5) = {0}", ff.FactorialI(5))  
    Console.WriteLine("FacRec(5) = {0}", ff.FactorialR(5))  
    Console.WriteLine("FibImp(11)= {0}", ff.FibonacciI(11))  
    Console.WriteLine("FibRec(11)= {0}", ff.FibonacciR(11))  
  
    // Create a (generic) list of integer values to test  
    // From 5 to 50 by 5  
    let values = [5..5..50]
    
    // Benchmarking Fibonacci
    // 1 = Factorial Imperative
    StaticFiborial.BenchmarkAlgorithm(1, values);  
    // 2 = Factorial Recursive  
    StaticFiborial.BenchmarkAlgorithm(2, values);   
  
    // Benchmarking Factorial
    // 3 = Fibonacci Imperative  
    StaticFiborial.BenchmarkAlgorithm(3, values);  
    // 4 = Fibonacci Recursive  
    StaticFiborial.BenchmarkAlgorithm(4, values);   
  
    // Stop and Exit  
    let i = Console.Read()
&lt;/pre&gt;&lt;br /&gt;
And the Output is: &lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="https://lh6.googleusercontent.com/-3EnwlUnPJAI/TXLCYsghO1I/AAAAAAAAF4c/SUbEfvlg8o8/s1600/fiborial_fs.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="640" src="https://lh6.googleusercontent.com/-3EnwlUnPJAI/TXLCYsghO1I/AAAAAAAAF4c/SUbEfvlg8o8/s640/fiborial_fs.PNG" width="336" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;a href="http://2.bp.blogspot.com/_0_HCzHGe4_k/TM8Wwm7ILyI/AAAAAAAAFyQ/AziXveRyTGo/s1600/output_delphi.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;br /&gt;
&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Humm, looks like Fibonnaci's algorithm implemented using recursion is definitively more complex than the others 3 right? I will grab these results for this and each of the upcoming posts to prepare a comparison of time execution between all the programming languages, then we will be able to talk about the algorithm's complexity as well.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;The Fiborial Program (using Module = Static Class)&lt;/b&gt;&lt;br /&gt;
&lt;pre class="csharp" name="code"&gt;// Factorial and Fibonacci in F#
namespace FiborialFs
open System  
open System.Collections.Generic
open System.Diagnostics
open System.Numerics

// Static Class 
module StaticFiborial = 
    // Static Field
    let mutable className:string = ""
    // Static Constructor/Initializer(s) 
    do className &amp;lt;- "Static Constructor"    
    do printfn "%s" className    
    // Static Method - Factorial Recursive
    // in F#: type bigint = BigInteger
    let rec FactorialR(n:int) : bigint =
        if n = 1 then 
            bigint(1)
        else 
            bigint(n) * FactorialR(n-1)
    // Static Method - Factorial Imperative
    let public FactorialI(n:int) : bigint =
        let mutable res:bigint = bigint(1)
        for i = n downto 1 do 
            res &amp;lt;- res * bigint(i)
        res
    // Static Method - Fibonacci Recursive
    let rec FibonacciR(n:int) : int64 =
        if (n &amp;lt; 2) then
            int64(1)
        else  
            FibonacciR(n - 1) + FibonacciR(n - 2)
    // Static Method - Fibonacci Imperative
    let public FibonacciI(n:int) : int64 =
        let mutable pre:int64 = int64(1)
        let mutable cur:int64 = int64(1)
        let mutable tmp:int64 = int64(0)
        for i = 2 to n do
            tmp &amp;lt;- cur + pre
            pre &amp;lt;- cur
            cur &amp;lt;- tmp
        cur
    // Static Method - Benchmarking Algorithms
    let public BenchmarkAlgorithm(algorithm:int, values:list&amp;lt;int&amp;gt;) =
        let timer = new Stopwatch()
        let mutable i:int = 1
        let mutable testValue:int = 1
        let mutable facTimeResult:bigint = bigint(0)
        let mutable fibTimeResult:int64 = int64(0)

        // "if-elif-else" Flow Control Statement
        if algorithm = 1 then
            printfn "\nFactorial Imperative:" 
            // "For to" Loop Statement
            for i = 1 to values.Length - 1 do
                testValue &amp;lt;- values.Item(i)
                // Taking Time  
                timer.Start()
                facTimeResult &amp;lt;- FactorialI(testValue)
                timer.Stop()
                // Getting Time  
                printfn " (%s) = %s" (testValue.ToString()) (timer.Elapsed.ToString())

        elif algorithm = 2 then
            printfn "\nFactorial Recursive:" 
            // "While" Loop Statement
            while i &amp;lt; values.Length - 1 do  
                testValue &amp;lt;- values.Item(i)
                // Taking Time  
                timer.Start()
                facTimeResult &amp;lt;- FactorialR(testValue)
                timer.Stop()
                // Getting Time  
                printfn " (%s) = %s" (testValue.ToString()) (timer.Elapsed.ToString())
                i &amp;lt;- i + 1

        elif algorithm = 3 then
            printfn "\nFibonacci Imperative:"
            // "For in" Loop Statement
            for item in values do
                testValue &amp;lt;- item
                // Taking Time  
                timer.Start();  
                fibTimeResult &amp;lt;- FibonacciI(testValue)
                timer.Stop();  
                // Getting Time  
                printfn " (%s) = %s" (testValue.ToString()) (timer.Elapsed.ToString())

        elif algorithm = 4 then
            printfn "\nFibonacci Recursive:"
            // "For in" Loop Statement
            for item in values do
                testValue &amp;lt;- item
                // Taking Time  
                timer.Start();  
                fibTimeResult &amp;lt;- FibonacciR(testValue)
                timer.Stop();  
                // Getting Time  
                printfn " (%s) = %s" (testValue.ToString()) (timer.Elapsed.ToString())

        else 
            printfn "DONG!" 

module Program = 
    //printfn "%s" (Fiborial.FactorialR(40).ToString())
    printfn "\nStatic Class"
    // Calling Instance Class with Static Methods  
    // No instantiation needed. Calling method directly from the class  
    printfn "FacImp(5) = {%s}" (StaticFiborial.FactorialI(5).ToString())  
    printfn "FacRec(5) = {%s}" (StaticFiborial.FactorialR(5).ToString())  
    printfn "FibImp(11)= {%s}" (StaticFiborial.FibonacciI(11).ToString())  
    printfn "FibRec(11)= {%s}" (StaticFiborial.FibonacciR(11).ToString())  

    // Create a (generic) list of integer values to test  
    // From 5 to 50 by 5  
    let values = [5..5..50]
    
    // Benchmarking Fibonacci
    // 1 = Factorial Imperative
    StaticFiborial.BenchmarkAlgorithm(1, values);  
    // 2 = Factorial Recursive  
    StaticFiborial.BenchmarkAlgorithm(2, values);   
  
    // Benchmarking Factorial
    // 3 = Fibonacci Imperative  
    StaticFiborial.BenchmarkAlgorithm(3, values);  
    // 4 = Fibonacci Recursive  
    StaticFiborial.BenchmarkAlgorithm(4, values);   
  
    // Stop and Exit  
    let i = Console.Read()
&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
And the Output is: &lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="https://lh5.googleusercontent.com/-Krk3t6hflRY/TXOx00rqewI/AAAAAAAAF4g/yzegH5_yHuE/s1600/fiborial_module_fs.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="640" src="https://lh5.googleusercontent.com/-Krk3t6hflRY/TXOx00rqewI/AAAAAAAAF4g/yzegH5_yHuE/s640/fiborial_module_fs.PNG" width="296" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;a href="http://2.bp.blogspot.com/_0_HCzHGe4_k/TM8Wwm7ILyI/AAAAAAAAFyQ/AziXveRyTGo/s1600/output_delphi.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;br /&gt;
&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Printing the Factorial and Fibonacci Series&lt;/b&gt;&lt;br /&gt;
&lt;pre class="csharp" name="code"&gt;// Factorial and Fibonacci in F#
namespace FiborialSeries
open System  
open System.Text
open System.Numerics

// Static Class 
module Fiborial = 
    // We first define the Factorial and Fibonacci methods
    // so we can use them after in the Series methods

    let rec Factorial(n:int) : bigint =
        if n = 1 then 
            bigint(1)
        else 
            bigint(n) * Factorial(n-1)

    let rec Fibonacci(n:int) : int64 =
        if (n &amp;lt; 2) then
            int64(1)
        else  
            Fibonacci(n - 1) + Fibonacci(n - 2)

    // Using a StringBuilder as a list of string elements  
    let public GetFactorialSeries(n:int): string =
        // Create the String that will hold the list  
        let mutable series:StringBuilder = StringBuilder()
        // We begin by concatenating the number you want to calculate  
        // in the following format: "!# ="  
        ignore (series.Append("!"))
        ignore (series.Append(n))
        ignore (series.Append(" = "))
        // We iterate backwards through the elements of the series 
        for i = n downto 1 do 
            // and append it to the list  
            ignore (series.Append(i))
            if i &amp;gt; 1 then
                ignore (series.Append(" * "))
            else
                ignore (series.Append(" = "))
        // Get the result from the Factorial Method  
        // and append it to the end of the list  
        ignore (series.Append(Factorial(n)))  
        // return the list as a string  
        series.ToString()

    // Using a StringBuilder as a list of string elements 
    let public GetFibonnaciSeries(n:int): string =
        // Create the String that will hold the list 
        let mutable series:StringBuilder = StringBuilder()
        // We begin by concatenating the first 3 values which  
        // are always constant  
        ignore (series.Append("0, 1, 1"))
        // Then we calculate the Fibonacci of each element  
        // and add append it to the list 
        for i = 2 to n do
            if i &amp;lt; n then
                ignore (series.Append(", "))
            else
                ignore (series.Append(" = "))
            ignore (series.Append(Fibonacci(i)))
        // return the list as string
        series.ToString()

module Program =
    // Printing Factorial Series  
    printfn ""  
    printfn "%s" (Fiborial.GetFactorialSeries(5))
    printfn "%s" (Fiborial.GetFactorialSeries(7))  
    printfn "%s" (Fiborial.GetFactorialSeries(9))
    printfn "%s" (Fiborial.GetFactorialSeries(11))  
    printfn "%s" (Fiborial.GetFactorialSeries(40))  
    // Printing Fibonacci Series  
    printfn ""  
    printfn "%s" (Fiborial.GetFibonnaciSeries(5))
    printfn "%s" (Fiborial.GetFibonnaciSeries(7))
    printfn "%s" (Fiborial.GetFibonnaciSeries(9))
    printfn "%s" (Fiborial.GetFibonnaciSeries(11))
    printfn "%s" (Fiborial.GetFibonnaciSeries(40))
&lt;/pre&gt;&lt;br /&gt;
And the Output is:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="https://lh6.googleusercontent.com/-KHuQlghPgYw/TXPAfwuD-TI/AAAAAAAAF4k/5_scduOvwno/s1600/fiborial_fs_extras_series.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="268" src="https://lh6.googleusercontent.com/-KHuQlghPgYw/TXPAfwuD-TI/AAAAAAAAF4k/5_scduOvwno/s640/fiborial_fs_extras_series.PNG" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Mixing Instance and Static Members in the same Class&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
We can also define instance classes that have both, instance and static members such as: fields, properties, constructors, methods, etc. However, we cannot do that if the type is a Module because Module = Static Class and remember the features mentioned in the previous post:&lt;br /&gt;
The main features of a static class are:&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;They only contain static members.&lt;/li&gt;
&lt;li&gt;They cannot be instantiated.&lt;/li&gt;
&lt;li&gt;They are sealed.&lt;/li&gt;
&lt;li&gt;They cannot contain Instance Constructors&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;pre class="csharp" name="code"&gt;namespace FiborialExtrasFs2
open System

// Instance Classes can have both: static and instance members.   
// However, Modules (Static Classes) only allow static members to be defined.  

// Instance Class  
type Fiborial() = class
    // Instance Field
    let mutable instanceCount:int = 0
    // Instance Constructor/Initializer(s) 
    do instanceCount &amp;lt;- 0
    do printfn "\nInstance Constructor %s" (instanceCount.ToString())
    // Static Field
    static let mutable staticCount:int = 0
    // Static Constructor/Initializer(s) 
    static do staticCount &amp;lt;- 0
    static do printfn "\nStatic Constructor %s" (Fiborial.StaticCount.ToString())
    //static do printfn "\nInstance Constructor {%s}" (staticCount.ToString())
    // Instance Read-Only Property
    member public this.InstanceCount 
        with get() = instanceCount
    // Static Read-Only Property  
    // Remeber that Properties are Methods to the CLR, so, you can also  
    // define static properties for static fields.   
    static member public StaticCount
        with get() = staticCount
    // Instance Method
    member public this.Factorial(n:int) =
        instanceCount &amp;lt;- instanceCount + 1
        printfn "\nFactorial(%s)" (instanceCount.ToString())
    // Static Method
    static member public Fibonacci(n:int) =
        staticCount &amp;lt;- staticCount + 1
        printfn "\nFibonacci(%s)" (Fiborial.StaticCount.ToString())
end

module Program =
    // Calling Static Constructor and Methods  
    // No need to instantiate  
    Fiborial.Fibonacci(5)
  
    // Calling Instance Constructor and Methods  
    // Instance required  
    let fib:Fiborial = new Fiborial()
    fib.Factorial(5)
  
    Fiborial.Fibonacci(15)
    fib.Factorial(5)
  
    // Calling Instance Constructor and Methods  
    // for a second object  
    let fib2:Fiborial = new Fiborial()
    fib2.Factorial(5);  
              
    printfn ""
    // Calling Static Property  
    printfn "Static Count = %s" (Fiborial.StaticCount.ToString())
    // Calling Instance Property of object 1 and 2  
    printfn "Instance 1 Count = %s" (fib.InstanceCount.ToString())
    printfn "Instance 2 Count = %s" (fib2.InstanceCount.ToString())
&lt;/pre&gt;&lt;br /&gt;
And the Output is:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="https://lh5.googleusercontent.com/-CUO2Vc-0P4U/TXPIyX0w6WI/AAAAAAAAF4o/mAEAw2vKYuA/s1600/fiborial_fs_extras2.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="320" src="https://lh5.googleusercontent.com/-CUO2Vc-0P4U/TXPIyX0w6WI/AAAAAAAAF4o/mAEAw2vKYuA/s320/fiborial_fs_extras2.PNG" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;a href="http://4.bp.blogspot.com/_0_HCzHGe4_k/TM8x5bVLv0I/AAAAAAAAFyU/ZHtgJE97Fdk/s1600/delphi_properties.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;br /&gt;
&lt;/a&gt;&lt;br /&gt;
&lt;a href="http://2.bp.blogspot.com/_0_HCzHGe4_k/TJYz5ZgkFGI/AAAAAAAAFwk/Y8rwLu2Bags/s1600/output_ipy_ext.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;br /&gt;
&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Factorial using System.Int64, System.Double, System.Numerics.BigInteger (bigint)&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
The Factorial of numbers over 20 are massive!&lt;br /&gt;
For instance: !40 = 815915283247897734345611269596115894272000000000!&lt;br /&gt;
Because of this, the previous version of this program was giving the "wrong" result &lt;br /&gt;
!40 = -70609262346240000 when using "long" (System.Int64) type, but it was not until I did the Fiborial version in VB.NET that I realized about this faulty code, because instead of giving me a wrong value, VB.NET execution thrown an Overflow Exception when using the "Long" (System.Int64) type.&lt;br /&gt;
&lt;br /&gt;
My first idea was to use ulong and ULong, but both failed for "big" numbers. I then used Double (double floating point) type and got no more exception/wrong result. The result of the factorial was now correct !40 = 1.1962222086548E+56, but still I wanted to show the Integer value of it, so I did some research and found that there is a new System.Numerics.BigInteger class in the .NET Framework 4.0. Adding the reference to the project and using this new class as the return type of the Factorial methods, I was able to get the result I was expecting.&lt;br /&gt;
!40 = 815915283247897734345611269596115894272000000000&lt;br /&gt;
&lt;br /&gt;
What I also found was that using different types change the time the algorithm takes to finish:&lt;br /&gt;
System.Int64 &amp;lt; System.Double &amp;lt; System.Numerics.BigInteger  &lt;br /&gt;
Almost by double!&lt;br /&gt;
&lt;br /&gt;
To illustrate what I just "tried" to say, lets have a look at the following code and the output we get.  &lt;br /&gt;
&lt;br /&gt;
&lt;pre class="csharp" name="code"&gt;open System
open System.Diagnostics
open System.Numerics

// Long Factorial
let rec FactorialInt64(n:int): int64 =
    match n with
    | 1 -&amp;gt; int64(1)
    | n -&amp;gt; int64(n) * FactorialInt64(n - 1)

// Double Factorial
let rec FactorialDouble(n:int): double =
    match n with
    | 1 -&amp;gt; double(1)
    | n -&amp;gt; double(n) * FactorialDouble(n - 1)

// BigInteger Factorial
let rec FactorialBigInteger(n:int): bigint =
    match n with
    | 1 -&amp;gt; bigint(1)
    | n -&amp;gt; bigint(n) * FactorialBigInteger(n - 1)

let timer:Stopwatch = new Stopwatch()
let mutable facIntResult:int64 = int64(0)
let mutable facDblResult:double = double(0)
let mutable facBigResult:bigint = bigint(0)
let mutable i:int = 0

let values:list&amp;lt;int&amp;gt; = [5..5..50]

printfn "\nFactorial using Int64"
// Benchmark Factorial using Int64
for i in values do
    timer.Start();  
    facIntResult &amp;lt;- FactorialInt64(i)
    timer.Stop(); 
    printfn "(%d) = %s : %s" i (timer.Elapsed.ToString()) (facIntResult.ToString())

printfn "\nFactorial using Double"
// Benchmark Factorial using Double
for i in values do
    timer.Start();  
    facDblResult &amp;lt;- FactorialDouble(i)
    timer.Stop(); 
    printfn "(%d) = %s : %s" i (timer.Elapsed.ToString()) (facDblResult.ToString())

printfn "\nFactorial using BigInteger"
// Benchmark Factorial using Double
for i in values do
    timer.Start();
    facBigResult &amp;lt;- FactorialBigInteger(i)
    timer.Stop(); 
    printfn "(%d) = %s : %s" i (timer.Elapsed.ToString()) (facBigResult.ToString())
&lt;/pre&gt;&lt;br /&gt;
NOTE: you DONT need to manually add a reference to the System.Numerics.dll assembly to your project because F# already adds it for you. In fact you don't need to use BigInteger, but bigint which is a type bigint = BigInteger.&lt;br /&gt;
&lt;br /&gt;
And the Output is:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="https://lh5.googleusercontent.com/-ahMSFdEX11E/TXPUriTvrTI/AAAAAAAAF4s/0eIscNR22rQ/s1600/fiborial_fs_extras_big_int.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="500" src="https://lh5.googleusercontent.com/-ahMSFdEX11E/TXPUriTvrTI/AAAAAAAAF4s/0eIscNR22rQ/s640/fiborial_fs_extras_big_int.PNG" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/694679611587040520-2628638876448139287?l=carlosqt.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/Wk68tWqsC4RoXGH5ziqvzDnxgCM/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Wk68tWqsC4RoXGH5ziqvzDnxgCM/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/Wk68tWqsC4RoXGH5ziqvzDnxgCM/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Wk68tWqsC4RoXGH5ziqvzDnxgCM/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/CarlosQuintanillasBlog/~4/2OhIcVgV2C4" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://carlosqt.blogspot.com/feeds/2628638876448139287/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://carlosqt.blogspot.com/2011/03/factorial-and-fibonacci-in-f.html#comment-form" title="3 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/694679611587040520/posts/default/2628638876448139287?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/694679611587040520/posts/default/2628638876448139287?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/CarlosQuintanillasBlog/~3/2OhIcVgV2C4/factorial-and-fibonacci-in-f.html" title="Factorial and Fibonacci in F#" /><author><name>Carlos QT</name><uri>http://www.blogger.com/profile/15415604076909500411</uri><email>carlosqt@gmail.com</email><gd:extendedProperty name="OpenSocialUserId" value="14144067369073378952" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://lh6.googleusercontent.com/-3EnwlUnPJAI/TXLCYsghO1I/AAAAAAAAF4c/SUbEfvlg8o8/s72-c/fiborial_fs.PNG" height="72" width="72" /><thr:total>3</thr:total><feedburner:origLink>http://carlosqt.blogspot.com/2011/03/factorial-and-fibonacci-in-f.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CkUCQHk-eCp7ImA9Wx9aEks.&quot;"><id>tag:blogger.com,1999:blog-694679611587040520.post-2559540527098625786</id><published>2011-03-04T09:37:00.000-08:00</published><updated>2011-03-04T09:37:41.750-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-03-04T09:37:41.750-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="JScript.NET" /><category scheme="http://www.blogger.com/atom/ns#" term="CLR" /><title>Factorial and Fibonacci in JScript.NET</title><content type="html">&lt;a class="twitter-share-button" data-count="horizontal" data-via="carlosqt" href="http://twitter.com/share"&gt;Tweet&lt;/a&gt;&lt;script src="http://platform.twitter.com/widgets.js" type="text/javascript"&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;br /&gt;
Here below a little program in JScript.NET that implements 2 classes (in fact, they are 3). There is the main class, called Fiborial (Fibo(nnacci)+(Facto)rial) that implements the &lt;i&gt;Fibonacci&lt;/i&gt; and the &lt;i&gt;Factorial&lt;/i&gt; algorithms in two ways, one &lt;i&gt;Recursive&lt;/i&gt; (using recursion) and the other &lt;i&gt;Imperative&lt;/i&gt; (using loops and states). The second class is just an instance class that does the same thing, but its there just to show the difference between static and instance classes, and finally the third one (which will not appear in other languages) is the Program class which has the static execution method "Main".&lt;br /&gt;
&lt;br /&gt;
You can also find 3 more little examples at the bottom. One prints out the Factorial's Series and Fibonacci's Series, the second one just shows a class that mixes both: static and instance members, and finally the third one that uses different return types (including System.Numerics.BigInteger) for the Factorial method to compare the timing and result.&lt;br /&gt;
&lt;br /&gt;
As with the previous posts, you can copy and paste the code below in your favorite IDE/Editor and start playing and learning with it. This little "working" program will teach you some more basics of the Programming Language.&lt;br /&gt;
&lt;br /&gt;
There are some "comments" on the code added just to tell you what are or how are some features called. In case you want to review the theory, you can read my previous post, where I give a definition of each of the concepts mentioned on the code. You can find it here: &lt;a href="http://carlosqt.blogspot.com/2011/01/new-series-factorial-and-fibonacci.html"&gt;http://carlosqt.blogspot.com/2011/01/new-series-factorial-and-fibonacci.html&lt;/a&gt;&amp;nbsp;&lt;a href="http://carlosqt.blogspot.com/2010/08/new-series-languages-basics-by-example.html"&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;The Fiborial Program&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="javascript" name="code"&gt;// Factorial and Fibonacci in JScript.NET
import System;  
// JScript does not support the use of generics
// import System.Collections.Generic;
import System.Collections;
import System.Diagnostics;
import System.Numerics;
 
package FiborialJs {     
    // Instance Class     
    // static is not a class modifier in JScript
    public class StaticFiborial {
        // Static Field
        static var className : String;
        // Static Initializer (Static Constructor)
        static StaticFiborial {
            className = 'Static Constructor';
            Console.WriteLine(className);            
        }
        // Static Method - Factorial Recursive
        static function FactorialR(n : int) : BigInteger {
            if (n == 1)
                // cannot use return 1 because literal 1 is
                // not a BigNumber and cannot convert! 
                return new BigInteger(1);
            else
                return n * FactorialR(n - 1);
        }
        // Static Method - Factorial Imperative
        static function FactorialI(n : int) : BigInteger {
            // cannot use var res : BigInteger = 1; because 
            // literal 1 is not a BigNumber and cannot convert! 
            var res : BigInteger = new BigInteger(1);
            for (var i : int = n; i &amp;gt;= 1; i--) {
                res *= i;
            }
            return res;
        }
        // Static Method - Fibonacci Recursive
        static function FibonacciR(n : int) : long {
            if (n &amp;lt; 2)
                return 1;
            else
                return FibonacciR(n - 1) + FibonacciR(n - 2);
        }
        // Static Method - Fibonacci Imperative
        static function FibonacciI(n : int) : long {
            var pre : long, cur : long, tmp : long = 0;
            pre = cur = 1;            
            for (var i : int = 2; i &amp;lt;= n; i++) {
                tmp = cur + pre;
                pre = cur;
                cur = tmp;
            }
            return cur;
        }
        // Static Method - Benchmarking Algorithms
        static function BenchmarkAlgorithm(algorithm : int, values : ArrayList) {
            var timer : Stopwatch = new Stopwatch;
            var i : int = 0, testValue : int = 0;
            var facTimeResult : BigInteger = new BigInteger(0);
            var fibTimeResult : long = 0;
            
            // 'Switch' Flow Constrol Statement
            switch (algorithm)
            {
                case 1:
                    Console.WriteLine('\nFactorial Imperative:');
                    // 'For' Loop Statement
                    for (i = 0; i &amp;lt; values.Count; i++) {                        
                        testValue = values[i];
                        // Taking Time
                        timer.Start();
                        facTimeResult = FactorialI(testValue);
                        timer.Stop();                        
                        // Getting Time
                        Console.WriteLine(' ({0}) = {1}', testValue, timer.Elapsed);
                    }                    
                    break;
                case 2:
                    Console.WriteLine('\nFactorial Recursive:');
                    // 'While' Loop Statement
                    while (i &amp;lt; values.Count) {                        
                        testValue = values[i];
                        // Taking Time
                        timer.Start();
                        facTimeResult = FactorialR(testValue);
                        timer.Stop();
                        // Getting Time
                        Console.WriteLine(' ({0}) = {1}', testValue, timer.Elapsed);
                        i++;
                    }
                    break;
                case 3:
                    Console.WriteLine('\nFibonacci Imperative:');
                    // 'Do-While' Loop Statement
                    do {
                        testValue = values[i];
                        // Taking Time
                        timer.Start();
                        fibTimeResult = FibonacciI(testValue);
                        timer.Stop();
                        // Getting Time
                        Console.WriteLine(' ({0}) = {1}', testValue, timer.Elapsed);
                        i++;
                    } while (i &amp;lt; values.Count);
                    break;
                case 4:
                    Console.WriteLine('\nFibonacci Recursive:');
                    // 'For In' Loop Statement
                    for (var item : int in values) {
                        testValue = item;
                        // Taking Time
                        timer.Start();
                        fibTimeResult = FibonacciR(testValue);
                        timer.Stop();
                        // Getting Time
                        Console.WriteLine(' ({0}) = {1}', testValue, timer.Elapsed);
                    }
                    break;
                default:
                    Console.WriteLine('DONG!');
                    break;
            }            
        }        
    }

    // Instance Class
    public class InstanceFiborial {
        // Instance Field
        var className : String;
        // Instance Constructor
        function InstanceFiborial() {
            this.className = 'Instance Constructor';
            Console.WriteLine(this.className);
        }
        // Instance Method - Factorial Recursive
        function FactorialR(n : int) : BigInteger {
            // Calling Static Method
            return StaticFiborial.FactorialR(n);
        }
        // Instance Method - Factorial Imperative
        function FactorialI(n : int) : BigInteger {
            // Calling Static Method
            return StaticFiborial.FactorialI(n);
        }
        // Instance Method - Fibonacci Recursive
        function FibonacciR(n : int) : long {
            // Calling Static Method
            return StaticFiborial.FibonacciR(n);
        }
        // Instance Method - Factorial Imperative
        function FibonacciI(n : int) : long {
            // Calling Static Method
            return StaticFiborial.FibonacciI(n);
        }
    };
};

import FiborialJs;

function Main() {
    Console.WriteLine('\nInstance Class with Static Methods only');
    // Calling Static Methods from an Instance Class
    // No instantiation needed. Calling method directly from the class
    Console.WriteLine('FacImp(5) = {0}', StaticFiborial.FactorialI(5));
    Console.WriteLine('FacRec(5) = {0}', StaticFiborial.FactorialR(5));
    Console.WriteLine('FibImp(11)= {0}', StaticFiborial.FibonacciI(11));
    Console.WriteLine('FibRec(11)= {0}', StaticFiborial.FibonacciR(11));

    Console.WriteLine('\nInstance Class');
    // Calling Instance Class and Methods 
    // Need to instantiate before using. Calling method from instantiated object
    var ff : InstanceFiborial = new InstanceFiborial;
    Console.WriteLine('FacImp(5) = {0}', ff.FactorialI(5));
    Console.WriteLine('FacRec(5) = {0}', ff.FactorialR(5));
    Console.WriteLine('FibImp(11)= {0}', ff.FibonacciI(11));
    Console.WriteLine('FibRec(11)= {0}', ff.FibonacciR(11));

    // Create na arraylist of integer values to test
    // From 5 to 50 by 5
    //var values : List&amp;lt;int&amp;gt; = new List&amp;lt;int&amp;gt;;
    var values : ArrayList = new ArrayList;
    for(var i : int = 5; i &amp;lt;= 50; i += 5)
        values.Add(i);

    // Benchmarking Fibonacci                     
    // 1 = Factorial Imperative            
    StaticFiborial.BenchmarkAlgorithm(1, values);
    // 2 = Factorial Recursive
    StaticFiborial.BenchmarkAlgorithm(2, values); 

    // Benchmarking Factorial            
    // 3 = Fibonacci Imperative
    StaticFiborial.BenchmarkAlgorithm(3, values);
    // 4 = Fibonacci Recursive
    StaticFiborial.BenchmarkAlgorithm(4, values); 

    // Stop and Exit
    Console.Read();
};

Main();
&lt;/pre&gt;&lt;br /&gt;
And the Output is: &lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="https://lh4.googleusercontent.com/-c4tTqVi2Ms8/TXEczGaiiUI/AAAAAAAAF4M/29FjAdIc7xs/s1600/fiborial_js.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="640" src="https://lh4.googleusercontent.com/-c4tTqVi2Ms8/TXEczGaiiUI/AAAAAAAAF4M/29FjAdIc7xs/s640/fiborial_js.PNG" width="346" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;a href="http://2.bp.blogspot.com/_0_HCzHGe4_k/TM8Wwm7ILyI/AAAAAAAAFyQ/AziXveRyTGo/s1600/output_delphi.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;br /&gt;
&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Humm, looks like Fibonnaci's algorithm implemented using recursion is definitively more complex than the others 3 right? I will grab these results for this and each of the upcoming posts to prepare a comparison of time execution between all the programming languages, then we will be able to talk about the algorithm's complexity as well.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Printing the Factorial and Fibonacci Series&lt;/b&gt;&lt;br /&gt;
&lt;pre class="javascript" name="code"&gt;import System;  
import System.Text;
import System.Numerics;

package FiborialSeries {
    class Fiborial {
        // Using a StringBuilder as a list of string elements
        public static function GetFactorialSeries(n : int) : String {
            // Create the String that will hold the list
            var series : StringBuilder = new StringBuilder;
            // We begin by concatenating the number you want to calculate
            // in the following format: '!# ='
            series.Append('!');
            series.Append(n);
            series.Append(' = ');
            // We iterate backwards through the elements of the series
            for (var i : int = n; i &amp;lt;= n &amp;amp;&amp;amp; i &amp;gt; 0; i--) {
                // and append it to the list
                series.Append(i);
                if (i &amp;gt; 1)
                    series.Append(' * ');
                else 
                    series.Append(' = '); 
            }
            // Get the result from the Factorial Method
            // and append it to the end of the list
            series.Append(Factorial(n));
            // return the list as a string
            return series.ToString();
        }

        // Using a StringBuilder as a list of string elements
        public static function GetFibonnaciSeries(n : int) : String {
            // Create the String that will hold the list
            var series : StringBuilder = new StringBuilder;
            // We begin by concatenating the first 3 values which
            // are always constant
            series.Append('0, 1, 1');
            // Then we calculate the Fibonacci of each element
            // and add append it to the list
            for (var i : int = 2; i &amp;lt;= n; i++) {
                if (i &amp;lt; n)
                    series.Append(', ');
                else
                    series.Append(' = ');
                
                series.Append(Fibonacci(i));
            }
            // return the list as a string
            return series.ToString();
        }

        public static function Factorial(n : int) : BigInteger {
            if (n == 1)                
                return new BigInteger(1);
            else
                return n * Factorial(n - 1);
        }

        public static function Fibonacci(n : int) : long {
            if (n &amp;lt; 2)
                return 1;
            else
                return Fibonacci(n - 1) + Fibonacci(n - 2);
        }
    }
}

import FiborialSeries;

// Printing Factorial Series
Console.WriteLine();
Console.WriteLine(Fiborial.GetFactorialSeries(5));
Console.WriteLine(Fiborial.GetFactorialSeries(7));
Console.WriteLine(Fiborial.GetFactorialSeries(9));
Console.WriteLine(Fiborial.GetFactorialSeries(11));
Console.WriteLine(Fiborial.GetFactorialSeries(40));
// Printing Fibonacci Series
Console.WriteLine();
Console.WriteLine(Fiborial.GetFibonnaciSeries(5));
Console.WriteLine(Fiborial.GetFibonnaciSeries(7));
Console.WriteLine(Fiborial.GetFibonnaciSeries(9));
Console.WriteLine(Fiborial.GetFibonnaciSeries(11));
Console.WriteLine(Fiborial.GetFibonnaciSeries(40));
&lt;/pre&gt;&lt;br /&gt;
And the Output is:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="https://lh6.googleusercontent.com/-VgKMFmNNDd4/TXEfMLmELMI/AAAAAAAAF4Q/D1ahIgdpeP8/s1600/fiborial_js_extras_series.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="348" src="https://lh6.googleusercontent.com/-VgKMFmNNDd4/TXEfMLmELMI/AAAAAAAAF4Q/D1ahIgdpeP8/s640/fiborial_js_extras_series.PNG" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Mixing Instance and Static Members in the same Class&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
We can also define instance classes that have both, instance and static members such as: fields, properties, constructors/initializers, methods, etc. However, we cannot do that if the class is marked as static because JScript.NET does not support it. The following text explains why:&lt;br /&gt;
&lt;br /&gt;
"The static modifier signifies that a member belongs to the class itself rather than to instances of the class. Only one copy of a static member exists in a given application even if many instances of the class are created. You can only access static members with a reference to the class rather than a reference to an instance. However, within a class member declaration, static members can be accessed with the this object.&lt;br /&gt;
&lt;br /&gt;
Members of classes can be marked with the static modifier. Classes, interfaces, and members of interfaces cannot take the static modifier.&lt;br /&gt;
&lt;br /&gt;
You may not combine the static modifier with any of the inheritance modifiers (abstract and final) or version-safe modifiers (hide and override).&lt;br /&gt;
&lt;br /&gt;
Do not confuse the static modifier with the static statement. The static modifier denotes a member that belongs to the class itself rather than any instance of the class." Taken from: &lt;a href="http://msdn.microsoft.com/en-us/library/f4ewhdb8.aspx"&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
on the other hand:&lt;br /&gt;
&lt;br /&gt;
"A static initializer is used to initialize a class object (not object instances) before its first use. This initialization occurs only once, and it can be used to initialize fields in the class that have the static modifier.&lt;br /&gt;
&lt;br /&gt;
A class may contain several static initializer blocks interspersed with static field declarations. To initialize the class, all the static blocks and static field initializers are executed in the order in which they appear in the class body. This initialization is performed before the first reference to a static field.&lt;br /&gt;
&lt;br /&gt;
Do not confuse the static modifier with the static statement. The static modifier denotes a member that belongs to the class itself, not any instance of the class." Taken from: &lt;a href="http://msdn.microsoft.com/en-us/library/7k208hb5.aspx"&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="javascript" name="code"&gt;import System;

package FiborialExtrasJs2 {
    // Instance Classes can have both: static and instance members. 
    // However, Static Classes only allow static members to be defined.
    // If you declare our next example class as static
    // (static class Fiborial) you will get the following compile error
    // Error: cannot declare instance members in a static class
    
    // Instance Class
    class Fiborial {
        // Instance Field
        private var instanceCount : int;
        // Static Field
        private static var staticCount : int;
        // Instance Read-Only Property
        // Within instance members, you can always use  
        // the 'this' reference pointer to access your (instance) members.
        public function get InstanceCount() : int {
            return this.instanceCount;
        }
        // Static Read-Only Property
        // Remeber that Properties are Methods to the CLR, so, you can also
        // define static properties for static fields. 
        // As with Static Methods, you cannot reference your class members
        // with the 'this' reference pointer since static members are not
        // instantiated.        
        public static function get StaticCount() : int {
            return staticCount;
        }
        // Instance Constructor
        public function Fiborial() {
            this.instanceCount = 0;
            Console.WriteLine('\nInstance Constructor {0}', this.instanceCount);
        }
        // Static Constructor
        static Fiborial {
            staticCount = 0;
            Console.WriteLine('\nStatic Constructor {0}', staticCount);
        }
        // Instance Method
        public function Factorial(n : int)
        {
            this.instanceCount += 1;
            Console.WriteLine('\nFactorial({0})', n);
        }
        // Static Method
        public static function Fibonacci(n : int)
        {
            staticCount += 1;
            Console.WriteLine('\nFibonacci({0})', n);
        }
    };       
};

import FiborialExtrasJs2;
// Calling Static Constructor and Methods
// No need to instantiate
Fiborial.Fibonacci(5);

// Calling Instance Constructor and Methods
// Instance required
var fib : Fiborial = new Fiborial;
fib.Factorial(5);

Fiborial.Fibonacci(15);
fib.Factorial(5);

// Calling Instance Constructor and Methods
// for a second object
var fib2 : Fiborial = new Fiborial;
fib2.Factorial(5);

Console.WriteLine();
// Calling Static Property
Console.WriteLine('Static Count = {0}', Fiborial.StaticCount);
// Calling Instance Property of object 1 and 2
Console.WriteLine('Instance 1 Count = {0}', fib.InstanceCount);
Console.WriteLine('Instance 2 Count = {0}', fib2.InstanceCount);
&lt;/pre&gt;&lt;br /&gt;
And the Output is:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="https://lh6.googleusercontent.com/-o-agQhUaxPY/TXEgMMf8wAI/AAAAAAAAF4U/puymTkLW0HA/s1600/fiborial_js_extras2.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="346" src="https://lh6.googleusercontent.com/-o-agQhUaxPY/TXEgMMf8wAI/AAAAAAAAF4U/puymTkLW0HA/s400/fiborial_js_extras2.PNG" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;a href="http://4.bp.blogspot.com/_0_HCzHGe4_k/TM8x5bVLv0I/AAAAAAAAFyU/ZHtgJE97Fdk/s1600/delphi_properties.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;br /&gt;
&lt;/a&gt;&lt;br /&gt;
&lt;a href="http://2.bp.blogspot.com/_0_HCzHGe4_k/TJYz5ZgkFGI/AAAAAAAAFwk/Y8rwLu2Bags/s1600/output_ipy_ext.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;br /&gt;
&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Factorial using System.Int64, System.Double, System.Numerics.BigInteger&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
The Factorial of numbers over 20 are massive!&lt;br /&gt;
For instance: !40 = 815915283247897734345611269596115894272000000000!&lt;br /&gt;
Because of this, the previous version of this program was giving the "wrong" result &lt;br /&gt;
!40 = -70609262346240000 when using "long" (System.Int64) type, but it was not until I did the Fiborial version in VB.NET that I realized about this faulty code, because instead of giving me a wrong value, VB.NET and JScript.NET execution thrown an Overflow Exception when using the "Long/long" (System.Int64) type.&lt;br /&gt;
&lt;br /&gt;
My first idea was to use ulong and ULong, but both failed for "big" numbers. I then used Double (double floating point) type and got no more exception/wrong result. The result of the factorial was now correct !40 = 1.1962222086548E+56, but still I wanted to show the Integer value of it, so I did some research and found that there is a new System.Numerics.BigInteger class in the .NET Framework 4.0. Adding the reference to the project and using this new class as the return type of the Factorial methods, I was able to get the result I was expecting.&lt;br /&gt;
!40 = 815915283247897734345611269596115894272000000000&lt;br /&gt;
&lt;br /&gt;
What I also found was that using different types change the time the algorithm takes to finish:&lt;br /&gt;
System.Int64 &amp;lt; System.Double &amp;lt; System.Numerics.BigInteger  &lt;br /&gt;
Almost by double!&lt;br /&gt;
&lt;br /&gt;
To illustrate what I just "tried" to say, lets have a look at the following code and the output we get.  &lt;br /&gt;
&lt;br /&gt;
&lt;pre class="javascript" name="code"&gt;import System;  
import System.Diagnostics;
import System.Numerics;
import Microsoft.JScript; // to get the JScriptException

// Long Factorial 
function FactorialInt64(n : int) : long {
    if (n == 1)
        return 1;
    else
        return n * FactorialInt64(n - 1);
}

// Double/Number Factorial 
function FactorialDouble(n : int) : Number {
    if (n == 1)
        return 1;
    else
        return n * FactorialDouble(n - 1);
}

// BigInteger Factorial 
function FactorialBigInteger(n : int) : BigInteger {
    if (n == 1)
        return new BigInteger(1);
    else
        return n * FactorialBigInteger(n - 1);
}

function Main() {
    var timer : Stopwatch = new Stopwatch;
    var facIntResult : long = 0;
    var facDblResult : Number = 0;
    var facBigResult : BigInteger = new BigInteger(0);
    var i : int = 0;
    
    Console.WriteLine('\nFactorial using Int64');
    // Benchmark Factorial using Int64
    // Overflow Exception!!! 
    // in JScript case this is a JsScriptException
    try {
        for (i = 5; i &amp;lt;= 50; i += 5) {
            timer.Start();
            facIntResult = FactorialInt64(i);
            timer.Stop();
            Console.WriteLine(' ({0}) = {1} : {2}', i, timer.Elapsed, facIntResult);
        }
    } catch(ex : JScriptException) {
        // yummy ^_^  
        Console.WriteLine(' Oops! {0} ', ex.Message);
    }    
    Console.WriteLine('\nFactorial using Double');
    // Benchmark Factorial using Double/Number
    for (i = 5; i &amp;lt;= 50; i += 5) {
        timer.Start();
        facDblResult = FactorialDouble(i);
        timer.Stop();
        Console.WriteLine(' ({0}) = {1} : {2}', i, timer.Elapsed, facDblResult);
    }
    Console.WriteLine('\nFactorial using BigInteger');
    // Benchmark Factorial using BigInteger
    for (i = 5; i &amp;lt;= 50; i += 5) {
        timer.Start();
        facBigResult = FactorialBigInteger(i);
        timer.Stop();
        Console.WriteLine(' ({0}) = {1} : {2}', i, timer.Elapsed, facBigResult);
    }
}

Main();
&lt;/pre&gt;&lt;br /&gt;
NOTE: you need to manually add a reference to the System.Numerics.dll assembly to your project so you can add it to your code, and in this particular case, you also need to reference Microsoft.JScript.dll assembly to get the JScriptException class.&lt;br /&gt;
&lt;br /&gt;
And the Output is:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="https://lh6.googleusercontent.com/-w-_zxAN0q-o/TXEgVGgkweI/AAAAAAAAF4Y/ygM53d5kBgc/s1600/fiborial_js_extras_big_int.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="570" src="https://lh6.googleusercontent.com/-w-_zxAN0q-o/TXEgVGgkweI/AAAAAAAAF4Y/ygM53d5kBgc/s640/fiborial_js_extras_big_int.PNG" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/694679611587040520-2559540527098625786?l=carlosqt.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/ynR6I-4hfcKRIhA_QpOhalBYzp0/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ynR6I-4hfcKRIhA_QpOhalBYzp0/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/ynR6I-4hfcKRIhA_QpOhalBYzp0/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ynR6I-4hfcKRIhA_QpOhalBYzp0/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/CarlosQuintanillasBlog/~4/cvl4vda7R4s" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://carlosqt.blogspot.com/feeds/2559540527098625786/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://carlosqt.blogspot.com/2011/03/factorial-and-fibonacci-in-jscriptnet.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/694679611587040520/posts/default/2559540527098625786?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/694679611587040520/posts/default/2559540527098625786?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/CarlosQuintanillasBlog/~3/cvl4vda7R4s/factorial-and-fibonacci-in-jscriptnet.html" title="Factorial and Fibonacci in JScript.NET" /><author><name>Carlos QT</name><uri>http://www.blogger.com/profile/15415604076909500411</uri><email>carlosqt@gmail.com</email><gd:extendedProperty name="OpenSocialUserId" value="14144067369073378952" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://lh4.googleusercontent.com/-c4tTqVi2Ms8/TXEczGaiiUI/AAAAAAAAF4M/29FjAdIc7xs/s72-c/fiborial_js.PNG" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://carlosqt.blogspot.com/2011/03/factorial-and-fibonacci-in-jscriptnet.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DUEBQX4yeCp7ImA9Wx9bF0s.&quot;"><id>tag:blogger.com,1999:blog-694679611587040520.post-2995947999533420719</id><published>2011-02-26T16:47:00.000-08:00</published><updated>2011-02-26T16:47:30.090-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-02-26T16:47:30.090-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="DelphiPrism" /><category scheme="http://www.blogger.com/atom/ns#" term="CLR" /><title>Factorial and Fibonacci in Delphi Prism</title><content type="html">&lt;a class="twitter-share-button" data-count="horizontal" data-via="carlosqt" href="http://twitter.com/share"&gt;Tweet&lt;/a&gt;&lt;script src="http://platform.twitter.com/widgets.js" type="text/javascript"&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;br /&gt;
Here below a little program in Delphi Prism that implements 2 classes (in fact, they are 3). There is the main class, called Fiborial (Fibo(nnacci)+(Facto)rial) that implements the &lt;i&gt;Fibonacci&lt;/i&gt; and the &lt;i&gt;Factorial&lt;/i&gt; algorithms in two ways, one &lt;i&gt;Recursive&lt;/i&gt; (using recursion) and the other &lt;i&gt;Imperative&lt;/i&gt; (using loops and states). The second class is just an instance class that does the same thing, but its there just to show the difference between static and instance classes, and finally the third one (which will not appear in other languages) is the Program class which has the static execution method "Main".&lt;br /&gt;
&lt;br /&gt;
You can also find 3 more little examples at the bottom. One prints out the Factorial's Series and Fibonacci's Series, the second one just shows a class that mixes both: static and instance members, and finally the third one that uses different return types (including System.Numerics.BigInteger) for the Factorial method to compare the timing and result.&lt;br /&gt;
&lt;br /&gt;
As with the previous posts, you can copy and paste the code below in your favorite IDE/Editor and start playing and learning with it. This little "working" program will teach you some more basics of the Programming Language.&lt;br /&gt;
&lt;br /&gt;
There are some "comments" on the code added just to tell you what are or how are some features called. In case you want to review the theory, you can read my previous post, where I give a definition of each of the concepts mentioned on the code. You can find it here: &lt;a href="http://carlosqt.blogspot.com/2011/01/new-series-factorial-and-fibonacci.html"&gt;http://carlosqt.blogspot.com/2011/01/new-series-factorial-and-fibonacci.html&lt;/a&gt;&amp;nbsp;&lt;a href="http://carlosqt.blogspot.com/2010/08/new-series-languages-basics-by-example.html"&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;The Fiborial Program&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="delphi" name="code"&gt;// Factorial and Fibonacci in Delphi Prism
namespace FiborialDelphi;

interface
uses
    System,
    System.Diagnostics,
    System.Collections.Generic,
    System.Numerics;

type
    // Static Class 
    StaticFiborial = public static class
    private
        // Static/Class Field
        class var 
            fClassName: string;        
    public
        // Static/Class Constructor 
        class constructor;
        // Static/Class Method - Factorial Recursive    
        class method FactorialR(n: integer): BigInteger;
        // Static/Class Method - Factorial Imperative
        class method FactorialI(n: integer): BigInteger;
        // Static/Class Method - Fibonacci Recursive
        class method FibonacciR(n: integer): Int64;
        // Static/Class Method - Fibonacci Imperative
        class method FibonacciI(n: integer): Int64;
        // Static/Class Method - Benchmarking Algorithms 
        class method BenchmarkAlgorithm(algorithm: integer; values: List&amp;lt;integer&amp;gt;);
    end;

type
    // Instance Class 
    InstanceFiborial = public class
    private
        // Instance Field
        var
            fClassName: string;
    public
        // Instance Constructor 
        constructor;
        // Instance Method - Factorial Recursive    
        method FactorialR(n: integer): BigInteger;
        // Instance Method - Factorial Imperative
        method FactorialI(n: integer): BigInteger;
        // Instance Method - Fibonacci Recursive
        method FibonacciR(n: integer): Int64;
        // Instance Method - Fibonacci Imperative
        method FibonacciI(n: integer): Int64;
    end;

type
    ConsoleApp = class
    public
        class method Main(args: array of string);
    end;

implementation

// Static/Class Constructor   
class constructor StaticFiborial;
begin
    fClassName := 'Static/Class Constructor';
    Console.WriteLine(fClassName);
end;
// Static/Class Method - Factorial Recursive    
class method StaticFiborial.FactorialR(n: integer): BigInteger;
begin
    if n = 1 then 
        result := 1
    else 
        result := n * FactorialR(n - 1);
end;
// Static/Class Method - Factorial Imperative
class method StaticFiborial.FactorialI(n: integer): BigInteger;
var 
    res: BigInteger := 1;
begin
    for i:integer := n downto 1 step 1 do
        res := res * i;
    result := res;
end;
// Static/Class Method - Fibonacci Recursive
class method StaticFiborial.FibonacciR(n: integer): Int64;
begin
    if n &amp;lt; 2 then
        result := 1
    else
        result := FibonacciR(n - 1) + FibonacciR(n - 2);    
end;
// Static/Class Method - Fibonacci Imperative
class method StaticFiborial.FibonacciI(n: integer): Int64;
var
    tmp, pre, cur: Int64;        
begin    
    tmp := 0;
    pre := 1;
    cur := 1;
    for i: integer := 2 to n step 1 do
    begin
        tmp := cur + pre;
        pre := cur;
        cur := tmp;
    end;
    result := cur;
end;
// Static Method - Benchmarking Algorithms
class method StaticFiborial.BenchmarkAlgorithm(algorithm: integer; values: List&amp;lt;integer&amp;gt;);
var
    timer: StopWatch;
    i, testValue: integer;
    facTimeResult: BigInteger := 0;
    fibTimeResult: Int64 := 0;
begin
    i := 0;
    testValue := 0;
    timer := new StopWatch();
    // 'switch/case' Flow Constrol Statement 
    case algorithm of  
        1: begin
            Console.WriteLine(''#10'Factorial Imperative:');
            // 'For' Loop Statement
            for i: integer := 0 to values.Count - 1 step 1 do
            begin
                testValue := values[i];
                // Taking Time    
                timer.Start();    
                facTimeResult := FactorialI(testValue);
                timer.Stop();                            
                // Getting Time    
                Console.WriteLine(' ({0}) = {1}', testValue, timer.Elapsed);
            end;
        end;
        2: begin
            Console.WriteLine(''#10'Factorial Recursive:');
            // 'While' Loop Statement 
            while i &amp;lt; values.Count do 
            begin
                testValue := values[i];
                // Taking Time    
                timer.Start();    
                facTimeResult := FactorialR(testValue);
                timer.Stop();                            
                // Getting Time    
                Console.WriteLine(' ({0}) = {1}', testValue, timer.Elapsed);
                inc(i);
            end;
        end;
        3: begin
            Console.WriteLine(''#10'Fibonacci Imperative:');
            // 'Repeat/Do' Loop Statement
            repeat        
                testValue := values[i];
                // Taking Time    
                timer.Start();    
                facTimeResult := FibonacciI(testValue);
                timer.Stop();
                // Getting Time    
                Console.WriteLine(' ({0}) = {1}', testValue, timer.Elapsed);
                inc(i);
            until i = values.Count - 1
        end;
        4: begin            
            Console.WriteLine(''#10'Fibonacci Recursive:');
            // 'For Each' Loop Statement
            for each item in values do
            begin
                testValue := item;  
                // Taking Time    
                timer.Start();    
                facTimeResult := FibonacciR(testValue);
                timer.Stop();
                // Getting Time    
                Console.WriteLine(' ({0}) = {1}', testValue, timer.Elapsed);
            end;
        end;
        else Console.WriteLine('DONG!');
    end;  
end;

// Instance Constructor   
constructor InstanceFiborial;
begin
    self.fClassName := 'Instance Constructor';
    Console.WriteLine(self.fClassName);
end;
// Instance Method - Factorial Recursive
method InstanceFiborial.FactorialR(n: integer): BigInteger;
begin
    // Calling Static Method    
    result := StaticFiborial.FactorialR(n);
end;
// Instance Method - Factorial Imperative
method InstanceFiborial.FactorialI(n: integer): BigInteger;
begin
    // Calling Static Method    
    result := StaticFiborial.FactorialI(n);
end;
// Instance Method - Fibonacci Recursive
method InstanceFiborial.FibonacciR(n: integer): Int64;
begin
    // Calling Static Method
    result := StaticFiborial.FibonacciR(n);
end;
// Instance Method - Fibonacci Imperative
method InstanceFiborial.FibonacciI(n: integer): Int64;
begin        
    // Calling Static Method
    result := StaticFiborial.FibonacciI(n);
end;

class method ConsoleApp.Main(args: array of string);
var
    values: List&amp;lt;integer&amp;gt;;
    ff: InstanceFiborial; 
begin
    Console.WriteLine(''#10'Static Class');
    // Calling Static Class and Methods  
    // No instantiation needed. Calling method directly from the class  
    Console.WriteLine('FacImp(5) = {0}', StaticFiborial.FactorialI(5));  
    Console.WriteLine('FacRec(5) = {0}', StaticFiborial.FactorialR(5));  
    Console.WriteLine('FibImp(11)= {0}', StaticFiborial.FibonacciI(11));  
    Console.WriteLine('FibRec(11)= {0}', StaticFiborial.FibonacciR(11));  
  
    Console.WriteLine(''#10'Instance Class');  
    // Calling Instance Class and Methods   
    // Need to instantiate before using. Calling method from instantiated object  
    ff := new InstanceFiborial();  
    Console.WriteLine('FacImp(5) = {0}', ff.FactorialI(5));  
    Console.WriteLine('FacRec(5) = {0}', ff.FactorialR(5));  
    Console.WriteLine('FibImp(11)= {0}', ff.FibonacciI(11));  
    Console.WriteLine('FibRec(11)= {0}', ff.FibonacciR(11));  
  
    // Create a (generic) list of integer values to test  
    // From 5 to 50 by 5  
    values := new List&amp;lt;integer&amp;gt;();  
    for i:integer := 5 to 50 step 5 do
        values.Add(i);  
  
    // Benchmarking Fibonacci                       
    // 1 = Factorial Imperative              
    StaticFiborial.BenchmarkAlgorithm(1, values);  
    // 2 = Factorial Recursive  
    StaticFiborial.BenchmarkAlgorithm(2, values);   
  
    // Benchmarking Factorial              
    // 3 = Fibonacci Imperative  
    StaticFiborial.BenchmarkAlgorithm(3, values);  
    // 4 = Fibonacci Recursive  
    StaticFiborial.BenchmarkAlgorithm(4, values);   
  
    // Stop and Exit  
    Console.Read();  
end;

end.
&lt;/pre&gt;&lt;br /&gt;
And the Output is: &lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="https://lh4.googleusercontent.com/-rj9A991VYo4/TWmCQaf9cQI/AAAAAAAAF38/j9DffSwAI2E/s1600/fiborial_delphi.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="640" src="https://lh4.googleusercontent.com/-rj9A991VYo4/TWmCQaf9cQI/AAAAAAAAF38/j9DffSwAI2E/s640/fiborial_delphi.PNG" width="291" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;a href="http://2.bp.blogspot.com/_0_HCzHGe4_k/TM8Wwm7ILyI/AAAAAAAAFyQ/AziXveRyTGo/s1600/output_delphi.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;br /&gt;
&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Humm, looks like Fibonnaci's algorithm implemented using recursion is definitively more complex than the others 3 right? I will grab these results for this and each of the upcoming posts to prepare a comparison of time execution between all the programming languages, then we will be able to talk about the algorithm's complexity as well.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Printing the Factorial and Fibonacci Series&lt;/b&gt;&lt;br /&gt;
&lt;pre class="delphi" name="code"&gt;namespace FiborialSeries;

interface
uses
    System,
    System.Text,
    System.Numerics;

type
    Fiborial = static class
    public
        class method GetFactorialSeries(n: integer): string;
        class method GetFibonnaciSeries(n: integer): string;
        class method Factorial(n: integer): BigInteger;
        class method Fibonacci(n: integer): Int64;
    end;

type
    ConsoleApp = class
    public
        class method Main(args: array of string);
    end;

implementation

class method Fiborial.GetFactorialSeries(n: integer): string;
var
    // Using a StringBuilder as a list of string elements    
    series: StringBuilder;
begin
    // Create the String that will hold the list
    series := new StringBuilder();
    // We begin by concatenating the number you want to calculate
    // in the following format: "!# ="
    series.Append('!');
    series.Append(n);
    series.Append(' = ');
    // We iterate backwards through the elements of the series
    for i: integer := n downto 1 do
    begin
        // and append it to the list
        series.Append(i);
        if i &amp;gt; 1 then
            series.Append(' * ')
        else 
            series.Append(' = ');         
    end;
    // Get the result from the Factorial Method
    // and append it to the end of the list
    series.Append(Factorial(n));
    // return the list as a string
    result := series.ToString();
end;

class method Fiborial.GetFibonnaciSeries(n: integer): string;
var
    // Using a StringBuilder as a list of string elements
    series: StringBuilder;
begin
    // Create the String that will hold the list
    series := new StringBuilder();
    // We begin by concatenating the first 3 values which
    // are always constant
    series.Append('0, 1, 1');
    // Then we calculate the Fibonacci of each element
    // and add append it to the list
    for i: integer := 2 to n do
    begin
        if i &amp;lt; n then
            series.Append(', ')
        else
            series.Append(' = ');
                
        series.Append(Fibonacci(i));
    end;
    // return the list as a string
    result := series.ToString();
end;

class method Fiborial.Factorial(n: integer): BigInteger;
begin
    if n = 1 then 
        result := 1
    else 
        result := n * Factorial(n - 1);
end;

class method Fiborial.Fibonacci(n: integer): Int64;
begin
    if n &amp;lt; 2 then
        result := 1
    else
        result := Fibonacci(n - 1) + Fibonacci(n - 2);    
end;

class method ConsoleApp.Main(args: array of string);
begin
    // Printing Factorial Series
    Console.WriteLine();
    Console.WriteLine(Fiborial.GetFactorialSeries(5));
    Console.WriteLine(Fiborial.GetFactorialSeries(7));
    Console.WriteLine(Fiborial.GetFactorialSeries(9));
    Console.WriteLine(Fiborial.GetFactorialSeries(11));
    Console.WriteLine(Fiborial.GetFactorialSeries(40));
    // Printing Fibonacci Series
    Console.WriteLine();
    Console.WriteLine(Fiborial.GetFibonnaciSeries(5));
    Console.WriteLine(Fiborial.GetFibonnaciSeries(7));
    Console.WriteLine(Fiborial.GetFibonnaciSeries(9));
    Console.WriteLine(Fiborial.GetFibonnaciSeries(11));
    Console.WriteLine(Fiborial.GetFibonnaciSeries(40));
    Console.Read();
end;

end.
&lt;/pre&gt;&lt;br /&gt;
And the Output is:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="https://lh4.googleusercontent.com/-WaUkfJlNXr4/TWmarWtpFGI/AAAAAAAAF4E/Y2Poa7_ggb4/s1600/fiborial_delphi_extras_series.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="316" src="https://lh4.googleusercontent.com/-WaUkfJlNXr4/TWmarWtpFGI/AAAAAAAAF4E/Y2Poa7_ggb4/s640/fiborial_delphi_extras_series.PNG" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Mixing Instance and Static Members in the same Class&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
We can also define instance classes that have both, instance and static members such as: fields, properties, constructors, methods, etc. However, we cannot do that if the class is marked as static because of the features mentioned in the previous post:&lt;br /&gt;
The main features of a static class are:&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;They only contain static members.&lt;/li&gt;
&lt;li&gt;They cannot be instantiated.&lt;/li&gt;
&lt;li&gt;They are sealed.&lt;/li&gt;
&lt;li&gt;They cannot contain Instance Constructors&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;pre class="delphi" name="code"&gt;namespace FiborialExtrasDelphi2;
// Instance Classes can have both: static and instance members. 
// However, Static Classes only allow static members to be defined.
// If you declare our next example class as static
// (static class Fiborial) you will get the following compile error
// Error: cannot declare instance members in a static class
interface

// Instance Class
type Fiborial = class
    private
        // Instance Field
        var fInstanceCount: integer;
        // Static Field
        class var fStaticCount: integer;
    public
        // Instance Read-Only Property   
        // Within instance members, you can always use  
        // the "this" reference pointer to access your (instance) members.     
        property InstanceCount : integer read self.fInstanceCount;
        // Static Read-Only Property     
        // Remeber that Properties are Methods to the CLR, so, you can also
        // define static properties for static fields. 
        // As with Static Methods, you cannot reference your class members
        // with the "this" reference pointer since static members are not
        // instantiated.          
        class property StaticCount : integer read fStaticCount;
        // Instance Constructor
        constructor;
        // Static Constructor
        class constructor;
        // Instance Method
        method Factorial(n: integer);
        // Static Method
        class method Fibonacci(n: integer);
    end;

type ConsoleApp = class
    public
        class method Main(args: array of string);
    end;

implementation

// Instance Constructor   
constructor Fiborial;
begin
    self.fInstanceCount := 0;
    Console.WriteLine(''#10'Instance Constructor {0}', self.fInstanceCount);
end;
// Static/Class Constructor   
class constructor Fiborial;
begin
    fStaticCount := 0;
    Console.WriteLine(''#10'Static Constructor {0}', fStaticCount);
end;
// Instance Method
method Fiborial.Factorial(n: integer);
begin
    inc(self.fInstanceCount);
    Console.WriteLine(''#10'Factorial({0})', n);
end;
// Static Method
class method Fiborial.Fibonacci(n: integer);
begin
    inc(fStaticCount);
    Console.WriteLine(''#10'Fibonacci({0})', n);
end;

class method ConsoleApp.Main(args: array of string);
begin
    // Calling Static Constructor and Methods
    // No need to instantiate
    Fiborial.Fibonacci(5);

    // Calling Instance Constructor and Methods
    // Instance required
    var fib := new Fiborial();
    fib.Factorial(5);            

    Fiborial.Fibonacci(15);            
    fib.Factorial(5);

    // Calling Instance Constructor and Methods
    // for a second object
    var fib2 := new Fiborial();
    fib2.Factorial(5);
            
    Console.WriteLine();
    // Calling Static Property
    Console.WriteLine('Static Count = {0}', Fiborial.StaticCount);
    // Calling Instance Property of object 1 and 2
    Console.WriteLine('Instance 1 Count = {0}', fib.InstanceCount);
    Console.WriteLine('Instance 2 Count = {0}', fib2.InstanceCount);
    Console.Read();
end;

end.
&lt;/pre&gt;&lt;br /&gt;
And the Output is:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="https://lh5.googleusercontent.com/-UN0O5b_Ga9Q/TWmagt1N7jI/AAAAAAAAF4A/tv5l9jf0JCk/s1600/fiborial_delphi_extras2.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="318" src="https://lh5.googleusercontent.com/-UN0O5b_Ga9Q/TWmagt1N7jI/AAAAAAAAF4A/tv5l9jf0JCk/s320/fiborial_delphi_extras2.PNG" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://2.bp.blogspot.com/_0_HCzHGe4_k/TJYz5ZgkFGI/AAAAAAAAFwk/Y8rwLu2Bags/s1600/output_ipy_ext.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;br /&gt;
&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Factorial using System.Int64, System.Double, System.Numerics.BigInteger&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
The Factorial of numbers over 20 are massive!&lt;br /&gt;
For instance: !40 = 815915283247897734345611269596115894272000000000!&lt;br /&gt;
Because of this, the previous version of this program was giving the "wrong" result &lt;br /&gt;
!40 = -70609262346240000 when using "long" (System.Int64) type, but it was on my previous post in VB.NET that I realized about this faulty code, because instead of giving me a wrong value, VB.NET execution thrown an Overflow Exception when using the "Long" (System.Int64) type.&lt;br /&gt;
&lt;br /&gt;
My first idea was to use ulong and ULong, but both failed for "big" numbers. I then used Double (double floating point) type and got no more exception/wrong result. The result of the factorial was now correct !40 = 1.1962222086548E+56, but still I wanted to show the Integer value of it, so I did some research and found that there is a new System::Numerics::BigInteger class in the .NET Framework 4.0. Adding the reference to the project and using this new class as the return type of the Factorial methods, I was able to get the result I was expecting.&lt;br /&gt;
!40 = 815915283247897734345611269596115894272000000000&lt;br /&gt;
&lt;br /&gt;
What I also found was that using different types change the time the algorithm takes to finish:&lt;br /&gt;
System.Int64 &amp;lt; System.Double &amp;lt; System.Numerics.BigInteger &lt;br /&gt;
Almost by double!&lt;br /&gt;
&lt;br /&gt;
To illustrate what I just "tried" to say, lets have a look at the following code and the output we get.  &lt;br /&gt;
&lt;br /&gt;
&lt;pre class="delphi" name="code"&gt;namespace FiborialExtrasDelphi3;

interface

uses   
    System,
    System.Numerics,
    System.Diagnostics;

type
    ConsoleApp = class
    public
        class method Main(args: array of string);
        class method FactorialInt64(n: integer): Int64;
        class method FactorialDouble(n: integer): Double;
        class method FactorialBigInteger(n: integer): BigInteger;
    end;

implementation

class method ConsoleApp.Main(args: array of string);
var
    timer: StopWatch;
    facIntResult: System.Int64 := 0;
    facDblResult: System.Double := 0;
    facBigResult: System.Numerics.BigInteger := 0;

begin
    timer := new StopWatch();
    Console.WriteLine(''#10'Factorial using Int64');    
    for i: integer := 5 to 50 step 5 do
    begin                
        timer.Start();
        facIntResult := FactorialInt64(i);
        timer.Stop();                                    
        Console.WriteLine(' ({0}) = {1} : {2}', i, timer.Elapsed, facIntResult);
    end;
    Console.WriteLine(''#10'Factorial using Double');
    for i: integer := 5 to 50 step 5 do
    begin                
        timer.Start();
        facDblResult := FactorialDouble(i);
        timer.Stop();                                    
        Console.WriteLine(' ({0}) = {1} : {2}', i, timer.Elapsed, facDblResult);
    end;
    Console.WriteLine(''#10'Factorial using BigInteger');
    for i: integer := 5 to 50 step 5 do
    begin                
        timer.Start();
        facBigResult := FactorialBigInteger(i);
        timer.Stop();                                    
        Console.WriteLine(' ({0}) = {1} : {2}', i, timer.Elapsed, facBigResult);
    end;
    Console.Read();
end;

class method ConsoleApp.FactorialInt64(n: integer): Int64;
begin
    if n = 1 then 
        result := 1
    else 
        result := n * FactorialInt64(n - 1);
end;

class method ConsoleApp.FactorialDouble(n: integer): Double;
begin
    if n = 1 then 
        result := 1
    else 
        result := n * FactorialDouble(n - 1);
end;

class method ConsoleApp.FactorialBigInteger(n: integer): BigInteger;
begin
    if n = 1 then 
        result := 1
    else 
        result := n * FactorialBigInteger(n - 1);
end;

end.
&lt;/pre&gt;&lt;br /&gt;
NOTE: you need to manually add a reference to the System.Numerics.dll assembly to your project so you can add it to your code.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
And the Output is:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="https://lh3.googleusercontent.com/-9TfSNC_MgGM/TWme4mv7SsI/AAAAAAAAF4I/x3yvsWNuAgU/s1600/fiborial_delphi_extras_big_int.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="500" src="https://lh3.googleusercontent.com/-9TfSNC_MgGM/TWme4mv7SsI/AAAAAAAAF4I/x3yvsWNuAgU/s640/fiborial_delphi_extras_big_int.PNG" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/694679611587040520-2995947999533420719?l=carlosqt.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/7WjksCktLMOT719CICAh00gHU3M/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/7WjksCktLMOT719CICAh00gHU3M/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/7WjksCktLMOT719CICAh00gHU3M/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/7WjksCktLMOT719CICAh00gHU3M/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/CarlosQuintanillasBlog/~4/kSlUTxiQrhA" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://carlosqt.blogspot.com/feeds/2995947999533420719/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://carlosqt.blogspot.com/2011/02/factorial-and-fibonacci-in-delphi-prism.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/694679611587040520/posts/default/2995947999533420719?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/694679611587040520/posts/default/2995947999533420719?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/CarlosQuintanillasBlog/~3/kSlUTxiQrhA/factorial-and-fibonacci-in-delphi-prism.html" title="Factorial and Fibonacci in Delphi Prism" /><author><name>Carlos QT</name><uri>http://www.blogger.com/profile/15415604076909500411</uri><email>carlosqt@gmail.com</email><gd:extendedProperty name="OpenSocialUserId" value="14144067369073378952" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://lh4.googleusercontent.com/-rj9A991VYo4/TWmCQaf9cQI/AAAAAAAAF38/j9DffSwAI2E/s72-c/fiborial_delphi.PNG" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://carlosqt.blogspot.com/2011/02/factorial-and-fibonacci-in-delphi-prism.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D0EFQncyeCp7ImA9Wx9bFko.&quot;"><id>tag:blogger.com,1999:blog-694679611587040520.post-7601372552991733316</id><published>2011-02-25T15:09:00.000-08:00</published><updated>2011-02-25T15:13:33.990-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-02-25T15:13:33.990-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="C++/CLI" /><category scheme="http://www.blogger.com/atom/ns#" term="CLR" /><title>Factorial and Fibonacci in C++/CLI</title><content type="html">&lt;a class="twitter-share-button" data-count="horizontal" data-via="carlosqt" href="http://twitter.com/share"&gt;Tweet&lt;/a&gt;&lt;script src="http://platform.twitter.com/widgets.js" type="text/javascript"&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;br /&gt;
Here below a little program in C++/CLI that implements 2 classes (in fact, they are 3). There is the main class, called Fiborial (Fibo(nnacci)+(Facto)rial) that implements the &lt;i&gt;Fibonacci&lt;/i&gt; and the &lt;i&gt;Factorial&lt;/i&gt; algorithms in two ways, one &lt;i&gt;Recursive&lt;/i&gt; (using recursion) and the other &lt;i&gt;Imperative&lt;/i&gt; (using loops and states). The second class is just an instance class that does the same thing, but its there just to show the difference between static and instance classes, and finally the third one (which will not appear in other languages) is the Program class which has the static execution method "Main".&lt;br /&gt;
&lt;br /&gt;
You can also find 3 more little examples at the bottom. One prints out the Factorial's Series and Fibonacci's Series, the second one just shows a class that mixes both: static and instance members, and finally the third one that uses different return types (including System::Numerics::BigInteger) for the Factorial method to compare the timing and result.&lt;br /&gt;
&lt;br /&gt;
As with the previous posts, you can copy and paste the code below in your favorite IDE/Editor and start playing and learning with it. This little "working" program will teach you some more basics of the Programming Language.&lt;br /&gt;
&lt;br /&gt;
There are some "comments" on the code added just to tell you what are or how are some features called. In case you want to review the theory, you can read my previous post, where I give a definition of each of the concepts mentioned on the code. You can find it here: &lt;a href="http://carlosqt.blogspot.com/2011/01/new-series-factorial-and-fibonacci.html"&gt;http://carlosqt.blogspot.com/2011/01/new-series-factorial-and-fibonacci.html&lt;/a&gt;&amp;nbsp;&lt;a href="http://carlosqt.blogspot.com/2010/08/new-series-languages-basics-by-example.html"&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;The Fiborial Program&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="csharp" name="code"&gt;// Factorial and Fibonacci in C++/CLI
#include "stdafx.h"
using namespace System;
using namespace System::Collections::Generic;
using namespace System::Diagnostics;
using namespace System::Numerics;

namespace FiborialCpp {
 // static class
 static ref class StaticFiborial {
 private:
  // Static Field
  static String^ className;
  // Static Constructor  
  static StaticFiborial() {  
   className = L"Static Constructor";  
   Console::WriteLine(className);              
  }  

 public:
  // Static Method - Factorial Recursive  
  static BigInteger FactorialR(int n) {  
   if (n == 1)
    return 1;
   else  
    return n * FactorialR(n - 1);
  }  
  // Static Method - Factorial Imperative  
  static BigInteger FactorialI(int n) {  
   BigInteger res = 1;  
   for (int i = n; i &amp;gt;= 1; i--) {
    res *= i;
   }
   return res;  
  }  
  // Static Method - Fibonacci Recursive  
  static long FibonacciR(int n) {  
   if (n &amp;lt; 2)  
    return 1;  
   else  
    return FibonacciR(n - 1) + FibonacciR(n - 2);  
  }  
  // Static Method - Fibonacci Imperative  
  static long FibonacciI(int n) {              
   long pre, cur, tmp = 0;  
   pre = cur = 1;              
   for (int i = 2; i &amp;lt;= n; i++) {  
    tmp = cur + pre;  
    pre = cur;  
    cur = tmp;  
   }  
   return cur;  
  }
  // Static Method - Benchmarking Algorithms  
  static void BenchmarkAlgorithm(int algorithm, List&amp;lt;int&amp;gt;^ values) {              
   Stopwatch ^timer = gcnew Stopwatch();  
   int i, testValue;  
   BigInteger facTimeResult = 0;  
   long fibTimeResult = 0;  
   i = testValue = 0;              
     
   // "Switch" Flow Constrol Statement  
   switch (algorithm)  
   {  
    case 1:  
     Console::WriteLine("\nFactorial Imperative:");  
     // "For" Loop Statement  
     for (i = 0; i &amp;lt; values-&amp;gt;Count; i++)
     {                          
      testValue = values[i];  
      // Taking Time  
      timer-&amp;gt;Start();  
      facTimeResult = FactorialI(testValue);  
      timer-&amp;gt;Stop();                          
      // Getting Time  
      Console::WriteLine(" ({0}) = {1}", testValue, timer-&amp;gt;Elapsed);  
     }                      
     break;  
    case 2:  
     Console::WriteLine("\nFactorial Recursive:");  
     // "While" Loop Statement  
     while (i &amp;lt; values-&amp;gt;Count)  
     {                          
      testValue = values[i];  
      // Taking Time  
      timer-&amp;gt;Start();  
      facTimeResult = FactorialR(testValue);  
      timer-&amp;gt;Stop();  
      // Getting Time  
      Console::WriteLine(" ({0}) = {1}", testValue, timer-&amp;gt;Elapsed);  
      i++;  
     }  
     break;  
    case 3:  
     Console::WriteLine("\nFibonacci Imperative:");  
     // "Do-While" Loop Statement  
     do {  
      testValue = values[i];  
      // Taking Time  
      timer-&amp;gt;Start();  
      fibTimeResult = FibonacciI(testValue);  
      timer-&amp;gt;Stop();  
      // Getting Time  
      Console::WriteLine(" ({0}) = {1}", testValue, timer-&amp;gt;Elapsed);  
      i++;  
     } while (i &amp;lt; values-&amp;gt;Count);  
     break;  
    case 4:  
     Console::WriteLine("\nFibonacci Recursive:");  
     // "For Each" Loop Statement  
     for each (int item in values)  
     {  
      testValue = item;  
      // Taking Time  
      timer-&amp;gt;Start();  
      fibTimeResult = FibonacciR(testValue);  
      timer-&amp;gt;Stop();  
      // Getting Time  
      Console::WriteLine(" ({0}) = {1}", testValue, timer-&amp;gt;Elapsed);  
     }  
     break;  
    default:  
     Console::WriteLine(L"DONG!");  
     break;  
   }                  
  }  
 };

 // Instance Class  
 public ref class InstanceFiborial {  
  // Instance Field  
  String^ className;  
  // Instance Constructor  
 public:
  InstanceFiborial() {  
   this-&amp;gt;className = "Instance Constructor";  
   Console::WriteLine(this-&amp;gt;className);  
  }  
  // Instance Method - Factorial Recursive  
  BigInteger FactorialR(int n) {  
   // Calling Static Method  
   return StaticFiborial::FactorialR(n);  
  }  
  // Instance Method - Factorial Imperative  
  BigInteger FactorialI(int n) {  
   // Calling Static Method  
   return StaticFiborial::FactorialI(n);  
  }  
  // Instance Method - Fibonacci Recursive  
  long FibonacciR(int n) {  
   // Calling Static Method  
   return StaticFiborial::FibonacciR(n);  
  }  
  // Instance Method - Factorial Imperative  
  long FibonacciI(int n) {  
   // Calling Static Method  
   return StaticFiborial::FibonacciI(n);  
  }  
 };
};

int main(array&amp;lt;System::String ^&amp;gt; ^args)
{ 
 Console::WriteLine("\nStatic Class");  
    // Calling Static Class and Methods  
    // No instantiation needed. Calling method directly from the class  
    Console::WriteLine("FacImp(5) = {0}", FiborialCpp::StaticFiborial::FactorialI(5));  
    Console::WriteLine("FacRec(5) = {0}", FiborialCpp::StaticFiborial::FactorialR(5));  
    Console::WriteLine("FibImp(11)= {0}", FiborialCpp::StaticFiborial::FibonacciI(11));  
    Console::WriteLine("FibRec(11)= {0}", FiborialCpp::StaticFiborial::FibonacciR(11));  
  
    Console::WriteLine("\nInstance Class");  
    // Calling Instance Class and Methods   
    // Need to instantiate before using. Calling method from instantiated object  
 FiborialCpp::InstanceFiborial ^ff = gcnew FiborialCpp::InstanceFiborial();  
    Console::WriteLine("FacImp(5) = {0}", ff-&amp;gt;FactorialI(5));  
    Console::WriteLine("FacRec(5) = {0}", ff-&amp;gt;FactorialR(5));  
    Console::WriteLine("FibImp(11)= {0}", ff-&amp;gt;FibonacciI(11));  
    Console::WriteLine("FibRec(11)= {0}", ff-&amp;gt;FibonacciR(11));  
  
    // Create a (generic) list of integer values to test  
    // From 5 to 50 by 5  
    List&amp;lt;int&amp;gt; ^values = gcnew List&amp;lt;int&amp;gt;();  
    for(int i = 5; i &amp;lt;= 50; i += 5)  
        values-&amp;gt;Add(i);  
  
    // Benchmarking Fibonacci                       
    // 1 = Factorial Imperative              
    FiborialCpp::StaticFiborial::BenchmarkAlgorithm(1, values);  
    // 2 = Factorial Recursive  
    FiborialCpp::StaticFiborial::BenchmarkAlgorithm(2, values);   
  
    // Benchmarking Factorial              
    // 3 = Fibonacci Imperative  
    FiborialCpp::StaticFiborial::BenchmarkAlgorithm(3, values);  
    // 4 = Fibonacci Recursive  
    FiborialCpp::StaticFiborial::BenchmarkAlgorithm(4, values);   
  
    // Stop and Exit  
    Console::Read();  

 return 0;
}
&lt;/pre&gt;&lt;br /&gt;
And the Output is: &lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-iWjCENx9j6E/TWgzeKjc1wI/AAAAAAAAF3o/MZUGICN67ZM/s1600/fiborial_cpp.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="640" src="http://2.bp.blogspot.com/-iWjCENx9j6E/TWgzeKjc1wI/AAAAAAAAF3o/MZUGICN67ZM/s640/fiborial_cpp.PNG" width="272" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;a href="http://2.bp.blogspot.com/_0_HCzHGe4_k/TM8Wwm7ILyI/AAAAAAAAFyQ/AziXveRyTGo/s1600/output_delphi.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;br /&gt;
&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Humm, looks like Fibonnaci's algorithm implemented using recursion is definitively more complex than the others 3 right? I will grab these results for this and each of the upcoming posts to prepare a comparison of time execution between all the programming languages, then we will be able to talk about the algorithm's complexity as well.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Printing the Factorial and Fibonacci Series&lt;/b&gt;&lt;br /&gt;
&lt;pre class="csharp" name="code"&gt;#include "stdafx.h"

using namespace System;
using namespace System::Text;
using namespace System::Numerics;  
 
namespace FiborialSeries {      

 static ref class Fiborial {  
 public:
  // Using a StringBuilder as a list of string elements  
  static String^ GetFactorialSeries(int n) {  
   // Create the String that will hold the list  
   StringBuilder ^series = gcnew StringBuilder();  
   // We begin by concatenating the number you want to calculate  
   // in the following format: "!# ="  
   series-&amp;gt;Append("!");  
   series-&amp;gt;Append(n);  
   series-&amp;gt;Append(" = ");  
   // We iterate backwards through the elements of the series  
   for (int i = n; i &amp;lt;= n &amp;amp;&amp;amp; i &amp;gt; 0; i--) {  
    // and append it to the list  
    series-&amp;gt;Append(i);  
    if (i &amp;gt; 1)  
     series-&amp;gt;Append(" * ");  
    else   
     series-&amp;gt;Append(" = ");   
   }  
   // Get the result from the Factorial Method  
   // and append it to the end of the list  
   series-&amp;gt;Append(Factorial(n));  
   // return the list as a string  
   return series-&amp;gt;ToString();  
  }  
  
  // Using a StringBuilder as a list of string elements  
  static String^ GetFibonnaciSeries(int n)  
  {  
   // Create the String that will hold the list  
   StringBuilder ^series = gcnew StringBuilder();  
   // We begin by concatenating the first 3 values which  
   // are always constant  
   series-&amp;gt;Append("0, 1, 1");  
   // Then we calculate the Fibonacci of each element  
   // and add append it to the list  
   for (int i = 2; i &amp;lt;= n; i++)  
   {  
    if (i &amp;lt; n)  
     series-&amp;gt;Append(", ");  
    else  
     series-&amp;gt;Append(" = ");  
      
    series-&amp;gt;Append(Fibonacci(i));  
   }  
   // return the list as a string  
   return series-&amp;gt;ToString();  
  }  
  
  static BigInteger Factorial(int n)  
  {  
   if (n == 1)  
    return 1;  
   else  
    return n * Factorial(n - 1);  
  }  
  
  static long Fibonacci(int n)  
  {  
   if (n &amp;lt; 2)  
    return 1;  
   else  
    return Fibonacci(n - 1) + Fibonacci(n - 2);  
  }    
 };  
};

using namespace FiborialSeries;
int main(array&amp;lt;System::String ^&amp;gt; ^args)
{
 // Printing Factorial Series  
 Console::WriteLine();  
 Console::WriteLine(Fiborial::GetFactorialSeries(5));  
 Console::WriteLine(Fiborial::GetFactorialSeries(7));  
 Console::WriteLine(Fiborial::GetFactorialSeries(9));  
 Console::WriteLine(Fiborial::GetFactorialSeries(11));  
 Console::WriteLine(Fiborial::GetFactorialSeries(40));  
 // Printing Fibonacci Series  
 Console::WriteLine();  
 Console::WriteLine(Fiborial::GetFibonnaciSeries(5));  
 Console::WriteLine(Fiborial::GetFibonnaciSeries(7));  
 Console::WriteLine(Fiborial::GetFibonnaciSeries(9));  
 Console::WriteLine(Fiborial::GetFibonnaciSeries(11));  
 Console::WriteLine(Fiborial::GetFibonnaciSeries(40));  
 Console::Read();
 return 0;
}
&lt;/pre&gt;&lt;br /&gt;
And the Output is:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-uM9SVi4bykc/TWgzkOeEn3I/AAAAAAAAF3s/TGd__EvgqLo/s1600/fiborial_cpp_extras_series.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="316" src="http://2.bp.blogspot.com/-uM9SVi4bykc/TWgzkOeEn3I/AAAAAAAAF3s/TGd__EvgqLo/s640/fiborial_cpp_extras_series.PNG" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Mixing Instance and Static Members in the same Class&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
We can also define instance classes that have both, instance and static members such as: fields, properties, constructors, methods, etc. However, we cannot do that if the class is marked as static because of the features mentioned in the previous post:&lt;br /&gt;
The main features of a static class are:&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;They only contain static members.&lt;/li&gt;
&lt;li&gt;They cannot be instantiated.&lt;/li&gt;
&lt;li&gt;They are sealed.&lt;/li&gt;
&lt;li&gt;They cannot contain Instance Constructors&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;pre class="csharp" name="code"&gt;#include &amp;quot;stdafx.h&amp;quot;

using namespace System;

namespace FiborialExtrasCpp2 {  
 // Instance Classes can have both: static and instance members.   
 // However, Static Classes only allow static members to be defined.  
 // If you declare our next example class as static  
 // (static class Fiborial) you will get the following compile error  
 // Error: cannot declare instance members in a static class  
  
 // Instance Class  
 ref class Fiborial {  
 // Instance Field  
  private:
   int instanceCount;  
 // Static Field  
 static int staticCount;   
 
 public:
  // Instance Read-Only Property  
  // Within instance members, you can always use
  // the &amp;quot;this&amp;quot; reference pointer to access your (instance) members.  s
  property int InstanceCount {  
   int get() { return this-&amp;gt;instanceCount; }
  }  
  // Static Read-Only Property  
  // Remeber that Properties are Methods to the CLR, so, you can also  
  // define static properties for static fields.   
  // As with Static Methods, you cannot reference your class members  
  // with the &amp;quot;this&amp;quot; reference pointer since static members are not  
  // instantiated.  
  static property int StaticCount {  
   int get() { return staticCount; }  
  }
  // Instance Constructor  
  Fiborial() {  
   this-&amp;gt;instanceCount = 0;  
   Console::WriteLine(&amp;quot;\nInstance Constructor {0}&amp;quot;, this-&amp;gt;instanceCount);  
  }
  // Static Constructor  
  static Fiborial() {  
   staticCount = 0;  
   Console::WriteLine(&amp;quot;\nStatic Constructor {0}&amp;quot;, staticCount);
  }
  // Instance Method  
  void Factorial(int n) {  
   this-&amp;gt;instanceCount += 1;  
   Console::WriteLine(&amp;quot;\nFactorial({0})&amp;quot;, n);  
  }
  // Static Method  
  static void Fibonacci(int n) {  
   staticCount += 1;  
   Console::WriteLine(&amp;quot;\nFibonacci({0})&amp;quot;, n);  
  }
 };  
};

using namespace FiborialExtrasCpp2;
int main(array&amp;lt;System::String ^&amp;gt; ^args)
 {
 // Calling Static Constructor and Methods  
 // No need to instantiate  
 Fiborial::Fibonacci(5);
  
 // Calling Instance Constructor and Methods  
 // Instance required  
 Fiborial ^fib = gcnew Fiborial();  
 fib-&amp;gt;Factorial(5);
  
 Fiborial::Fibonacci(15);  
 fib-&amp;gt;Factorial(5);  
  
 // Calling Instance Constructor and Methods  
 // for a second object  
 Fiborial ^fib2 = gcnew Fiborial();  
 fib2-&amp;gt;Factorial(5);  
  
 Console::WriteLine();  
 // Calling Static Property  
 Console::WriteLine(&amp;quot;Static Count = {0}&amp;quot;, Fiborial::StaticCount);
 // Calling Instance Property of object 1 and 2  
 Console::WriteLine(&amp;quot;Instance 1 Count = {0}&amp;quot;, fib-&amp;gt;InstanceCount);
 Console::WriteLine(&amp;quot;Instance 2 Count = {0}&amp;quot;, fib2-&amp;gt;InstanceCount);
 Console::Read();
 return 0;
}
&lt;/pre&gt;&lt;br /&gt;
And the Output is:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-z68cmTUhT0Y/TWg0aP_JaDI/AAAAAAAAF34/5m3FXzyRwZU/s1600/fiborial_cpp_extras2.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="328" src="http://1.bp.blogspot.com/-z68cmTUhT0Y/TWg0aP_JaDI/AAAAAAAAF34/5m3FXzyRwZU/s400/fiborial_cpp_extras2.PNG" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;a href="http://4.bp.blogspot.com/_0_HCzHGe4_k/TM8x5bVLv0I/AAAAAAAAFyU/ZHtgJE97Fdk/s1600/delphi_properties.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;br /&gt;
&lt;/a&gt;&lt;a href="http://2.bp.blogspot.com/_0_HCzHGe4_k/TJYz5ZgkFGI/AAAAAAAAFwk/Y8rwLu2Bags/s1600/output_ipy_ext.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;br /&gt;
&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Factorial using System::Int64, System::Double, System::Numerics::BigInteger&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
The Factorial of numbers over 20 are massive!&lt;br /&gt;
For instance: !40 = 815915283247897734345611269596115894272000000000!&lt;br /&gt;
Because of this, the previous version of this program was giving the "wrong" result &lt;br /&gt;
!40 = -70609262346240000 when using "long" (System::Int64) type, but it was on my previous post in VB.NET that I realized about this faulty code, because instead of giving me a wrong value, VB.NET execution thrown an Overflow Exception when using the "Long" (System::Int64) type.&lt;br /&gt;
&lt;br /&gt;
My first idea was to use ulong and ULong, but both failed for "big" numbers. I then used Double (double floating point) type and got no more exception/wrong result. The result of the factorial was now correct !40 = 1.1962222086548E+56, but still I wanted to show the Integer value of it, so I did some research and found that there is a new System::Numerics::BigInteger class in the .NET Framework 4.0. Adding the reference to the project and using this new class as the return type of the Factorial methods, I was able to get the result I was expecting.&lt;br /&gt;
!40 = 815915283247897734345611269596115894272000000000&lt;br /&gt;
&lt;br /&gt;
What I also found was that using different types change the time the algorithm takes to finish:&lt;br /&gt;
System::Int64 &amp;lt; System::Double &amp;lt; System::Numerics::BigInteger  &lt;br /&gt;
Almost by double!&lt;br /&gt;
&lt;br /&gt;
To illustrate what I just "tried" to say, lets have a look at the following code and the output we get.  &lt;br /&gt;
&lt;br /&gt;
&lt;pre class="csharp" name="code"&gt;#include "stdafx.h"

using namespace System;
using namespace System::Numerics;
using namespace System::Diagnostics;

// Long Factorial   
static Int64 FactorialInt64(int n) {  
    if (n == 1)  
        return 1;  
    else  
        return n * FactorialInt64(n - 1);  
}  
  
// Double Factorial   
static Double FactorialDouble(int n) {  
    if (n == 1)  
        return 1;  
    else  
        return n * FactorialDouble(n - 1);  
}  
          
// BigInteger Factorial   
static BigInteger FactorialBigInteger(int n) {  
    if (n == 1)  
        return 1;  
    else  
        return n * FactorialBigInteger(n - 1);  
}  

int main(array&amp;lt;System::String ^&amp;gt; ^args) {
    Stopwatch ^timer = gcnew Stopwatch();
    Int64 facIntResult = 0;  
    Double facDblResult = 0;  
    BigInteger facBigResult = 0;  
  
    Console::WriteLine("\nFactorial using Int64");  
    // Benchmark Factorial using Int64  
    for (int i = 5; i &amp;lt;= 50; i += 5)  
    {  
        timer-&amp;gt;Start();  
        facIntResult = FactorialInt64(i);  
        timer-&amp;gt;Stop();  
        Console::WriteLine(" ({0}) = {1} : {2}", i, timer-&amp;gt;Elapsed, facIntResult);  
    }  
    Console::WriteLine("\nFactorial using Double");  
    // Benchmark Factorial using Double  
    for (int i = 5; i &amp;lt;= 50; i += 5)  
    {  
        timer-&amp;gt;Start();  
        facDblResult = FactorialDouble(i);  
        timer-&amp;gt;Stop();  
        Console::WriteLine(" ({0}) = {1} : {2}", i, timer-&amp;gt;Elapsed, facDblResult);  
    }  
    Console::WriteLine("\nFactorial using BigInteger");  
    // Benchmark Factorial using BigInteger  
    for (int i = 5; i &amp;lt;= 50; i += 5)  
    {  
        timer-&amp;gt;Start();  
        facBigResult = FactorialBigInteger(i);  
        timer-&amp;gt;Stop();  
        Console::WriteLine(" ({0}) = {1} : {2}", i, timer-&amp;gt;Elapsed, facBigResult);
    }
 Console::Read();
    return 0;
}
&lt;/pre&gt;&lt;br /&gt;
NOTE: you need to manually add a reference to the System.Numerics.dll assembly to your project so you can add it to your code.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
And the Output is:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-n2O0thAXgiQ/TWgzvni4KDI/AAAAAAAAF30/_T5fhyHd2RQ/s1600/fiborial_cpp_extras_big_int.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="488" src="http://1.bp.blogspot.com/-n2O0thAXgiQ/TWgzvni4KDI/AAAAAAAAF30/_T5fhyHd2RQ/s640/fiborial_cpp_extras_big_int.PNG" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/694679611587040520-7601372552991733316?l=carlosqt.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/sSljJcaxefGxKVGBrxuokMjFWtY/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/sSljJcaxefGxKVGBrxuokMjFWtY/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/sSljJcaxefGxKVGBrxuokMjFWtY/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/sSljJcaxefGxKVGBrxuokMjFWtY/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/CarlosQuintanillasBlog/~4/x1HzCyrvBDs" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://carlosqt.blogspot.com/feeds/7601372552991733316/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://carlosqt.blogspot.com/2011/02/factorial-and-fibonacci-in-ccli.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/694679611587040520/posts/default/7601372552991733316?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/694679611587040520/posts/default/7601372552991733316?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/CarlosQuintanillasBlog/~3/x1HzCyrvBDs/factorial-and-fibonacci-in-ccli.html" title="Factorial and Fibonacci in C++/CLI" /><author><name>Carlos QT</name><uri>http://www.blogger.com/profile/15415604076909500411</uri><email>carlosqt@gmail.com</email><gd:extendedProperty name="OpenSocialUserId" value="14144067369073378952" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/-iWjCENx9j6E/TWgzeKjc1wI/AAAAAAAAF3o/MZUGICN67ZM/s72-c/fiborial_cpp.PNG" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://carlosqt.blogspot.com/2011/02/factorial-and-fibonacci-in-ccli.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D0QAQH8-fSp7ImA9Wx9bEUg.&quot;"><id>tag:blogger.com,1999:blog-694679611587040520.post-3798385998917436980</id><published>2011-02-19T14:42:00.000-08:00</published><updated>2011-02-19T14:42:21.155-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-02-19T14:42:21.155-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="VB.NET" /><category scheme="http://www.blogger.com/atom/ns#" term="CLR" /><title>Factorial and Fibonacci in VB.NET</title><content type="html">&lt;a class="twitter-share-button" data-count="horizontal" data-via="carlosqt" href="http://twitter.com/share"&gt;Tweet&lt;/a&gt;&lt;script src="http://platform.twitter.com/widgets.js" type="text/javascript"&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;br /&gt;
Here below a little program in VB.NET that implements 2 classes (in fact, they are 3). There is the main class, called Fiborial (Fibo(nnacci)+(Facto)rial) that implements the &lt;i&gt;Fibonacci&lt;/i&gt; and the &lt;i&gt;Factorial&lt;/i&gt; algorithms in two ways, one &lt;i&gt;Recursive&lt;/i&gt; (using recursion) and the other &lt;i&gt;Imperative&lt;/i&gt; (using loops and states). The second class is just an instance class that does the same thing, but its there just to show the difference between static (or shared in VB.NET) and instance classes, and finally the third one (which will not appear in other languages) is the Program class which has the static execution method "Main".&lt;br /&gt;
&lt;br /&gt;
You can also find 3 more little examples at the bottom. One prints out the Factorial's Series and Fibonacci's Series, the second one just shows a class that mixes both: static and instance members, and finally the third one that uses different return types (including System.Numerics.BigInteger) for the Factorial method to compare the timing and result.&lt;br /&gt;
&lt;br /&gt;
As with the previous posts, you can copy and paste the code below in your favorite IDE/Editor and start playing and learning with it. This little "working" program will teach you some more basics of the Programming Language.&lt;br /&gt;
&lt;br /&gt;
There are some "comments" on the code added just to tell you what are or how are some features called. In case you want to review the theory, you can read my previous post, where I give a definition of each of the concepts mentioned on the code. You can find it here: &lt;a href="http://carlosqt.blogspot.com/2011/01/new-series-factorial-and-fibonacci.html"&gt;http://carlosqt.blogspot.com/2011/01/new-series-factorial-and-fibonacci.html&lt;/a&gt;&amp;nbsp;&lt;a href="http://carlosqt.blogspot.com/2010/08/new-series-languages-basics-by-example.html"&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;The Fiborial Program&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="vb" name="code"&gt;' Factorial and Fibonacci in VB.NET
Option Explicit On
Option Strict On

Imports System.Collections.Generic
Imports System.Diagnostics
Imports System.Numerics

Namespace FiborialVB
    ' Static Class (All Members in a Module are Static/Shared)
    Module StaticFiborial
        ' Static Field
        Dim className As String
        ' Static Constructor        
        Sub New()
            className = "Static Constructor"
            Console.WriteLine(className)
        End Sub
        ' Static Method - Factorial Recursive
        Public Function FactorialR(ByVal n As Integer) As BigInteger
            If n = 1 Then
                Return 1
            Else
                Return n * FactorialR(n - 1)
            End If
        End Function
        ' Static Method - Factorial Imperative
        Public Function FactorialI(ByVal n As Integer) As BigInteger
            Dim res As BigInteger = 1
            For i = n To 1 Step -1
                res *= i
            Next            
            Return res
        End Function
        ' Static Method - Fibonacci Recursive
        Public Function FibonacciR(ByVal n As Integer) As Long
            If n &amp;lt; 2 Then
                Return 1
            Else
                Return FibonacciR(n - 1) + FibonacciR(n - 2)
            End If
        End Function
        ' Static Method - Fibonacci Imperative
        Public Function FibonacciI(ByVal n As Integer) As Long
            Dim i As Integer = 2
            Dim pre As Long = 1, cur As Long = 1
            Dim tmp As Long = 0
            While i &amp;lt;= n
                tmp = cur + pre
                pre = cur
                cur = tmp
                i += 1
            End While
            Return cur
        End Function
        ' Static Method - Benchmarking Algorithms
        Public Sub BenchmarkAlgorithm(ByVal algorithm As Integer,
                                      ByVal values As List(Of Integer))
            Dim timer As New Stopwatch()
            Dim i As Integer, facTimeResult As BigInteger,
                fibTimeResult As Long, testValue As Integer
            ' "Case/Switch" Flow Constrol Statement
            Select Case algorithm
                Case 1
                    Console.WriteLine(ControlChars.CrLf &amp;amp; "Factorial Imperative:")
                    ' "For" Loop Statement
                    For i = 0 To values.Count - 1 Step 1
                        testValue = values(i)
                        ' Taking Time
                        timer.Start()
                        facTimeResult = FactorialI(testValue)
                        timer.Stop()
                        ' Getting Time
                        Console.WriteLine(" ({0}) = {1}", testValue, timer.Elapsed)
                    Next
                Case 2
                    Console.WriteLine(ControlChars.CrLf &amp;amp; "Factorial Recursive:")
                    ' "While" Loop Statement
                    While i &amp;lt; values.Count
                        testValue = values(i)
                        ' Taking Time
                        timer.Start()
                        facTimeResult = FactorialR(testValue)
                        timer.Stop()
                        ' Getting Time
                        Console.WriteLine(" ({0}) = {1}", testValue, timer.Elapsed)
                        i += 1
                    End While
                Case 3
                    Console.WriteLine(ControlChars.CrLf &amp;amp; "Fibonacci Imperative:")
                    ' "Do-While" Loop Statement
                    Do
                        testValue = values(i)
                        ' Taking Time
                        timer.Start()
                        fibTimeResult = FibonacciI(testValue)
                        timer.Stop()
                        ' Getting Time
                        Console.WriteLine(" ({0}) = {1}", testValue, timer.Elapsed)
                        i += 1
                    Loop While i &amp;lt; values.Count
                Case 4
                    Console.WriteLine(ControlChars.CrLf &amp;amp; "Fibonacci Recursive:")
                    ' "For Each" Loop Statement
                    For Each item As Integer In values
                        testValue = item
                        ' Taking Time
                        timer.Start()
                        fibTimeResult = FibonacciR(testValue)
                        timer.Stop()
                        ' Getting Time
                        Console.WriteLine(" ({0}) = {1}", testValue, timer.Elapsed)
                    Next
                Case Else
                    Console.WriteLine("DONG!")
            End Select
        End Sub
    End Module

    ' Instance Class
    Public Class InstanceFiborial
        ' Instance Field
        Dim className As String
        ' Instance Constructor
        Sub New()
            Me.className = "Instance Constructor"
            Console.WriteLine(className)
        End Sub
        ' Instance Method - Factorial Recursive
        Public Function FactorialR(ByVal n As Integer) As BigInteger
            ' Calling Static Method
            Return StaticFiborial.FactorialR(n)
        End Function
        ' Instance Method - Factorial Imperative
        Public Function FactorialI(ByVal n As Integer) As BigInteger
            ' Calling Static Method
            Return StaticFiborial.FactorialI(n)
        End Function
        ' Instance Method - Fibonacci Recursive
        Public Function FibonacciR(ByVal n As Integer) As Long
            ' Calling Static Method
            Return StaticFiborial.FibonacciR(n)
        End Function
        ' Instance Method - Fibonacci Imperative
        Public Function FibonacciI(ByVal n As Integer) As Long
            ' Calling Static Method
            Return StaticFiborial.FibonacciI(n)
        End Function
    End Class

    ' Console Program  
    Friend Module Program
        Public Sub Main()

            Console.WriteLine(ControlChars.CrLf &amp;amp; "Static Class")
            ' Calling Static Class and Methods
            ' No instantiation needed. Calling method directly from the class
            Console.WriteLine("FacImp(5) = {0}", StaticFiborial.FactorialI(5))
            Console.WriteLine("FacRec(5) = {0}", StaticFiborial.FactorialR(5))
            Console.WriteLine("FibImp(11)= {0}", StaticFiborial.FibonacciI(11))
            Console.WriteLine("FibRec(11)= {0}", StaticFiborial.FibonacciR(11))

            Console.WriteLine(ControlChars.CrLf &amp;amp; "Instance Class")
            ' Calling Instance Class and Methods 
            ' Need to instantiate before using. Calling method from instantiated object
            Dim ff As New InstanceFiborial()
            Console.WriteLine("FacImp(5) = {0}", ff.FactorialI(5))
            Console.WriteLine("FacRec(5) = {0}", ff.FactorialR(5))
            Console.WriteLine("FibImp(11)= {0}", ff.FibonacciI(11))
            Console.WriteLine("FibRec(11)= {0}", ff.FibonacciR(11))

            ' Create a (generic) list of integer values to test
            ' From 5 to 50 by 5
            Dim values As New List(Of Integer)
            For i = 5 To 50 Step 5
                values.Add(i)
            Next
            ' Benchmarking Fibonacci
            ' 1 = Factorial Imperative            
            StaticFiborial.BenchmarkAlgorithm(1, values)
            ' 2 = Factorial Recursive
            StaticFiborial.BenchmarkAlgorithm(2, values)

            ' Benchmarking Factorial
            ' 3 = Fibonacci Imperative            
            StaticFiborial.BenchmarkAlgorithm(3, values)
            ' 4 = Fibonacci Recursive
            StaticFiborial.BenchmarkAlgorithm(4, values)

            ' Stop and exit              
            Console.Read()
        End Sub
    End Module

End Namespace
&lt;/pre&gt;&lt;br /&gt;
And the Output is: &lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-hAHW3qYmaxI/TWBCXxavMeI/AAAAAAAAF3U/B_RuOwhnpWQ/s1600/fiborial_vb.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="640" src="http://2.bp.blogspot.com/-hAHW3qYmaxI/TWBCXxavMeI/AAAAAAAAF3U/B_RuOwhnpWQ/s640/fiborial_vb.PNG" width="276" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;a href="http://2.bp.blogspot.com/_0_HCzHGe4_k/TM8Wwm7ILyI/AAAAAAAAFyQ/AziXveRyTGo/s1600/output_delphi.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;br /&gt;
&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Humm, looks like Fibonnaci's algorithm implemented using recursion is definitively more complex than the others 3 right? I will grab these results for this and each of the upcoming posts to prepare a comparison of time execution between all the programming languages, then we will be able to talk about the algorithm's complexity as well.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Printing the Factorial and Fibonacci Series&lt;/b&gt;&lt;br /&gt;
&lt;pre class="vb" name="code"&gt;Imports System.Text
Imports System.Numerics

Namespace FiborialSeries

    Module Fiborial
        ' Using a StringBuilder as a list of string elements
        Function GetFactorialSeries(ByVal n As Integer) As String
            ' Create the String that will hold the list
            Dim series As New StringBuilder()
            ' We begin by concatenating the number you want to calculate
            ' in the following format: "!# ="
            series.Append("!")
            series.Append(n)
            series.Append(" = ")
            ' We iterate backwards through the elements of the series
            For i = n To 1 Step -1
                ' and append it to the list
                series.Append(i)
                If i &amp;gt; 1 Then
                    series.Append(" * ")
                Else
                    series.Append(" = ")
                End If
            Next
            ' Get the result from the Factorial Method
            ' and append it to the end of the list
            series.Append(Factorial(n))
            ' return the list as a string
            Return series.ToString()
        End Function

        ' Using a StringBuilder as a list of string elements
        Function GetFibonnaciSeries(ByVal n As Integer) As String
            ' Create the String that will hold the list
            Dim series As New StringBuilder()
            ' We begin by concatenating the first 3 values which
            ' are always constant
            series.Append("0, 1, 1")
            ' Then we calculate the Fibonacci of each element
            ' and add append it to the list
            For i = 2 To n Step 1
                If i &amp;lt; n Then
                    series.Append(", ")
                Else
                    series.Append(" = ")
                End If
                series.Append(Fibonacci(i))
            Next
            ' return the list as a string
            Return series.ToString()
        End Function

        Function Factorial(ByVal n As Integer) As BigInteger
            If n = 1 Then
                Return 1
            Else
                Return n * Factorial(n - 1)
            End If
        End Function

        Function Fibonacci(ByVal n As Integer) As Long
            If n &amp;lt; 2 Then
                Return 1
            Else
                Return Fibonacci(n - 1) + Fibonacci(n - 2)
            End If
        End Function
    End Module

    Module Program
        Sub Main()
            ' Printing Factorial Series
            Console.WriteLine()
            Console.WriteLine(Fiborial.GetFactorialSeries(5))
            Console.WriteLine(Fiborial.GetFactorialSeries(7))
            Console.WriteLine(Fiborial.GetFactorialSeries(9))
            Console.WriteLine(Fiborial.GetFactorialSeries(11))
            Console.WriteLine(Fiborial.GetFactorialSeries(40))
            ' Printing Fibonacci Series
            Console.WriteLine()
            Console.WriteLine(Fiborial.GetFibonnaciSeries(5))
            Console.WriteLine(Fiborial.GetFibonnaciSeries(7))
            Console.WriteLine(Fiborial.GetFibonnaciSeries(9))
            Console.WriteLine(Fiborial.GetFibonnaciSeries(11))
            Console.WriteLine(Fiborial.GetFibonnaciSeries(40))
        End Sub
    End Module

End Namespace
&lt;/pre&gt;&lt;br /&gt;
And the Output is:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-cWqltdkp9oY/TWBCdcbwusI/AAAAAAAAF3Y/8hqzcvXFrvw/s1600/fiborial_vb_extras_series.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="316" src="http://2.bp.blogspot.com/-cWqltdkp9oY/TWBCdcbwusI/AAAAAAAAF3Y/8hqzcvXFrvw/s640/fiborial_vb_extras_series.PNG" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Mixing Instance and Static/Shared Members in the same Class&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
We can also define instance classes that have both, instance and static members such as: fields, properties, constructors, methods, etc. However, you cannot do that if instead of a Class you used a Module since a Module in VB.NET is like a Static Class in C#, and remember that a Static Class has the following characteristics:&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;They only contain static members.&lt;/li&gt;
&lt;li&gt;They cannot be instantiated.&lt;/li&gt;
&lt;li&gt;They are sealed.&lt;/li&gt;
&lt;li&gt;They cannot contain Instance Constructors&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;pre class="vb" name="code"&gt;Namespace FiborialExtrasVb2

    ' Instance Class
    Class Fiborial
        ' Instance Field
        Private _instanceCount As Integer
        ' Static/Shared Field
        Private Shared _staticCount As Integer
        ' Instance Read-Only Property
        ' Within instance members, you can always use  
        ' the "Me" reference pointer to access your (instance) members.
        Public ReadOnly Property InstanceCount() As Integer
            Get
                Return Me._instanceCount
            End Get
        End Property
        ' Static/Shared Read-Only Property
        ' Remeber that Properties are Methods to the CLR, so, you can also
        ' define static/shared properties for static/shared fields. 
        ' As with Static/Shared Methods, you cannot reference your class members
        ' with the "Me" reference pointer since static/shared members are not
        ' instantiated.
        Public Shared ReadOnly Property StaticCount() As Integer
            Get
                Return _staticCount
            End Get
        End Property
        ' Instance Constructor
        Public Sub New()
            Me._instanceCount = 0
            Console.WriteLine(ControlChars.CrLf &amp;amp; "Instance Constructor {0}",
                              Me._instanceCount)
        End Sub
        ' Static/Shared Constructor
        Shared Sub New()
            _staticCount = 0
            Console.WriteLine(ControlChars.CrLf &amp;amp; "Static/Shared Constructor {0}",
                              _staticCount)
        End Sub
        ' Instance Method
        Public Sub Factorial(ByVal n As Integer)
            Me._instanceCount += 1
            Console.WriteLine(ControlChars.CrLf &amp;amp; "Factorial({0})", n)
        End Sub
        ' Static/Shared Method
        Public Shared Sub Fibonacci(ByVal n As Integer)
            _staticCount += 1
            Console.WriteLine(ControlChars.CrLf &amp;amp; "Fibonacci({0})", n)
        End Sub
    End Class

    Module Program
        Sub Main()
            ' Calling Static/Shared Constructor and Methods
            ' No need to instantiate
            Fiborial.Fibonacci(5)

            ' Calling Instance Constructor and Methods
            ' Instance required
            Dim fib As New Fiborial()
            fib.Factorial(5)

            Fiborial.Fibonacci(15)
            fib.Factorial(5)

            ' Calling Instance Constructor and Methods
            ' for a second object
            Dim fib2 As New Fiborial()
            fib2.Factorial(5)

            Console.WriteLine()
            ' Calling Static/Shared Property
            Console.WriteLine("Static Count = {0}", Fiborial.StaticCount)
            ' Calling Instance Property of object 1 and 2
            Console.WriteLine("Instance 1 Count = {0}", fib.InstanceCount)
            Console.WriteLine("Instance 2 Count = {0}", fib2.InstanceCount)
        End Sub
    End Module

End Namespace
&lt;/pre&gt;&lt;br /&gt;
And the Output is:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-QnQePzH9Y8k/TWBCjJU-IxI/AAAAAAAAF3c/Tc0swieUJfk/s1600/fiborial_vb_extras2.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="320" src="http://1.bp.blogspot.com/-QnQePzH9Y8k/TWBCjJU-IxI/AAAAAAAAF3c/Tc0swieUJfk/s400/fiborial_vb_extras2.PNG" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;a href="http://4.bp.blogspot.com/_0_HCzHGe4_k/TM8x5bVLv0I/AAAAAAAAFyU/ZHtgJE97Fdk/s1600/delphi_properties.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;br /&gt;
&lt;/a&gt;&lt;a href="http://2.bp.blogspot.com/_0_HCzHGe4_k/TJYz5ZgkFGI/AAAAAAAAFwk/Y8rwLu2Bags/s1600/output_ipy_ext.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;br /&gt;
&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Factorial using System.Int64, System.Double, System.Numerics.BigInteger&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
The Factorial of numbers over 20 are massive!&lt;br /&gt;
For instance: !40 = 815915283247897734345611269596115894272000000000!&lt;br /&gt;
Because of this, the previous version of this program was giving the "wrong" result &lt;br /&gt;
!40 = -70609262346240000 when using "long" (System.Int64) type, but it was not until I did the Fiborial version in VB.NET that I realized about this faulty code, because instead of giving me a wrong value, VB.NET execution thrown an Overflow Exception when using the "Long" (System.Int64) type.&lt;br /&gt;
&lt;br /&gt;
My first idea was to use ulong and ULong, but both failed for "big" numbers. I then used Double (double floating point) type and got no more exception/wrong result. The result of the factorial was now correct !40 = 1.1962222086548E+56, but still I wanted to show the Integer value of it, so I did some research and found that there is a new System.Numerics.BigInteger class in the .NET Framework 4.0. Adding the reference to the project and using this new class as the return type of the Factorial methods, I was able to get the result I was expecting.&lt;br /&gt;
!40 = 815915283247897734345611269596115894272000000000&lt;br /&gt;
&lt;br /&gt;
What I also found was that using different types change the time the algorithm takes to finish:&lt;br /&gt;
System.Int64 &amp;lt; System.Double &amp;lt; System.Numerics.BigInteger  &lt;br /&gt;
Almost by double!&lt;br /&gt;
&lt;br /&gt;
To illustrate what I just "tried" to say, lets have a look at the following code and the output we get.  &lt;br /&gt;
&lt;br /&gt;
&lt;pre class="vb" name="code"&gt;Imports System.Diagnostics
Imports System.Numerics

Namespace FiborialExtrasCs3
    Module Program
        Sub Main()
            Dim timer As New Stopwatch()
            Dim facIntResult As System.Int64 = 0
            Dim facDblResult As System.Double = 0
            Dim facBigResult As System.Numerics.BigInteger = 0

            Console.WriteLine(ControlChars.CrLf &amp;amp; "Factorial using Int64")
            ' Benchmark Factorial using Int64
            ' Overflow Exception!!!
            Try
                For i = 5 To 50 Step 5
                    timer.Start()
                    facIntResult = FactorialInt64(i)
                    timer.Stop()
                    Console.WriteLine(" ({0}) = {1} : {2}", i, timer.Elapsed, facIntResult)
                Next
            Catch ex As OverflowException
                ' yummy ^_^
                Console.WriteLine(" Oops! {0} ", ex.Message)
            End Try
            Console.WriteLine(ControlChars.CrLf &amp;amp; "Factorial using Double")
            ' Benchmark Factorial using Double
            For i = 5 To 50 Step 5
                timer.Start()
                facDblResult = FactorialDouble(i)
                timer.Stop()
                Console.WriteLine(" ({0}) = {1} : {2}", i, timer.Elapsed, facDblResult)
            Next
            Console.WriteLine(ControlChars.CrLf &amp;amp; "Factorial using BigInteger")
            ' Benchmark Factorial using BigInteger
            For i = 5 To 50 Step 5
                timer.Start()
                facBigResult = FactorialBigInteger(i)
                timer.Stop()
                Console.WriteLine(" ({0}) = {1} : {2}", i, timer.Elapsed, facBigResult)
            Next
        End Sub
        'Long Factorial 
        Public Function FactorialInt64(ByVal n As Integer) As Int64
            If n = 1 Then
                Return 1
            Else
                Return n * FactorialInt64(n - 1)
            End If
        End Function
        ' Double Factorial 
        Public Function FactorialDouble(ByVal n As Integer) As Double
            If n = 1 Then
                Return 1
            Else
                Return n * FactorialDouble(n - 1)
            End If
        End Function
        ' BigInteger Factorial 
        Public Function FactorialBigInteger(ByVal n As Integer) As BigInteger
            If n = 1 Then
                Return 1
            Else
                Return n * FactorialBigInteger(n - 1)
            End If
        End Function
    End Module
End Namespace
&lt;/pre&gt;&lt;br /&gt;
NOTE: you need to manually add a reference to the System.Numerics assembly to your project so you can add it to your code.&lt;br /&gt;
&lt;br /&gt;
And the Output is:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/--pXNypHiJqQ/TWBCq30EpEI/AAAAAAAAF3g/FrjNkRrdVvE/s1600/fiborial_vb_extras_big_int.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="454" src="http://2.bp.blogspot.com/--pXNypHiJqQ/TWBCq30EpEI/AAAAAAAAF3g/FrjNkRrdVvE/s640/fiborial_vb_extras_big_int.PNG" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/694679611587040520-3798385998917436980?l=carlosqt.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/FaMXYi8xR_WjMAN9hLLVD75oA94/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/FaMXYi8xR_WjMAN9hLLVD75oA94/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/FaMXYi8xR_WjMAN9hLLVD75oA94/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/FaMXYi8xR_WjMAN9hLLVD75oA94/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/CarlosQuintanillasBlog/~4/q2kIDPxveXE" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://carlosqt.blogspot.com/feeds/3798385998917436980/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://carlosqt.blogspot.com/2011/02/factorial-and-fibonacci-in-vbnet.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/694679611587040520/posts/default/3798385998917436980?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/694679611587040520/posts/default/3798385998917436980?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/CarlosQuintanillasBlog/~3/q2kIDPxveXE/factorial-and-fibonacci-in-vbnet.html" title="Factorial and Fibonacci in VB.NET" /><author><name>Carlos QT</name><uri>http://www.blogger.com/profile/15415604076909500411</uri><email>carlosqt@gmail.com</email><gd:extendedProperty name="OpenSocialUserId" value="14144067369073378952" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/-hAHW3qYmaxI/TWBCXxavMeI/AAAAAAAAF3U/B_RuOwhnpWQ/s72-c/fiborial_vb.PNG" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://carlosqt.blogspot.com/2011/02/factorial-and-fibonacci-in-vbnet.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D0QDQH4-fyp7ImA9Wx9bEUg.&quot;"><id>tag:blogger.com,1999:blog-694679611587040520.post-161620563506046261</id><published>2011-01-29T11:01:00.000-08:00</published><updated>2011-02-19T14:42:51.057-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-02-19T14:42:51.057-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="C#" /><category scheme="http://www.blogger.com/atom/ns#" term="CLR" /><title>Factorial and Fibonacci in C#</title><content type="html">&lt;a class="twitter-share-button" data-count="horizontal" data-via="carlosqt" href="http://twitter.com/share"&gt;Tweet&lt;/a&gt;&lt;script src="http://platform.twitter.com/widgets.js" type="text/javascript"&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;br /&gt;
UPDATE: updated code examples and section using System.Numerics.BigInteger.&lt;br /&gt;
&lt;br /&gt;
Here below a little program in C# that implements 2 classes (in fact, they are 3). There is the main class, called Fiborial (Fibo(nnacci)+(Facto)rial) that implements the &lt;i&gt;Fibonacci&lt;/i&gt; and the &lt;i&gt;Factorial&lt;/i&gt; algorithms in two ways, one &lt;i&gt;Recursive&lt;/i&gt; (using recursion) and the other &lt;i&gt;Imperative&lt;/i&gt; (using loops and states). The second class is just an instance class that does the same thing, but its there just to show the difference between static and instance classes, and finally the third one (which will not appear in other languages) is the Program class which has the static execution method "Main".&lt;br /&gt;
&lt;br /&gt;
You can also find 3 more little examples at the bottom. One prints out the Factorial's Series and Fibonacci's Series, the second one just shows a class that mixes both: static and instance members, and finally the third one that uses different return types (including System.Numerics.BigInteger) for the Factorial method to compare the timing and result.&lt;br /&gt;
&lt;br /&gt;
As with the previous posts, you can copy and paste the code below in your favorite IDE/Editor and start playing and learning with it. This little "working" program will teach you some more basics of the Programming Language.&lt;br /&gt;
&lt;br /&gt;
There are some "comments" on the code added just to tell you what are or how are some features called. In case you want to review the theory, you can read my previous post, where I give a definition of each of the concepts mentioned on the code. You can find it here: &lt;a href="http://carlosqt.blogspot.com/2011/01/new-series-factorial-and-fibonacci.html"&gt;http://carlosqt.blogspot.com/2011/01/new-series-factorial-and-fibonacci.html&lt;/a&gt;&amp;nbsp;&lt;a href="http://carlosqt.blogspot.com/2010/08/new-series-languages-basics-by-example.html"&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;The Fiborial Program&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="csharp" name="code"&gt;// Factorial and Fibonacci in C#
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Numerics;

namespace FiborialCs
{
    // Static Class
    static class StaticFiborial
    {
        // Static Field
        static string className;
        // Static Constructor
        static StaticFiborial()
        {
            className = "Static Constructor";
            Console.WriteLine(className);            
        }
        // Static Method - Factorial Recursive
        public static BigInteger FactorialR(int n)
        {
            if (n == 1)
                return 1;
            else
                return n * FactorialR(n - 1);
        }
        // Static Method - Factorial Imperative
        public static BigInteger FactorialI(int n)
        {
            BigInteger res = 1;
            for (int i = n; i &amp;gt;= 1; i--)
            {                
                res *= i;
            }
            return res;
        }
        // Static Method - Fibonacci Recursive
        public static long FibonacciR(int n)
        {
            if (n &amp;lt; 2)
                return 1;
            else
                return FibonacciR(n - 1) + FibonacciR(n - 2);
        }
        // Static Method - Fibonacci Imperative
        public static long FibonacciI(int n)
        {            
            long pre, cur, tmp = 0;
            pre = cur = 1;            
            for (int i = 2; i &amp;lt;= n; i++)
            {
                tmp = cur + pre;
                pre = cur;
                cur = tmp;
            }
            return cur;
        }
        // Static Method - Benchmarking Algorithms
        public static void BenchmarkAlgorithm(int algorithm, List&amp;lt;int&amp;gt; values)
        {            
            Stopwatch timer = new Stopwatch();
            int i, testValue;
            BigInteger facTimeResult = 0;
            long fibTimeResult = 0;
            i = testValue = 0;            
            
            // "Switch" Flow Constrol Statement
            switch (algorithm)
            {
                case 1:
                    Console.WriteLine("\nFactorial Imperative:");
                    // "For" Loop Statement
                    for (i = 0; i &amp;lt; values.Count; i++)
                    {                        
                        testValue = values[i];
                        // Taking Time
                        timer.Start();
                        facTimeResult = FactorialI(testValue);
                        timer.Stop();                        
                        // Getting Time
                        Console.WriteLine(" ({0}) = {1}", testValue, timer.Elapsed);
                    }                    
                    break;
                case 2:
                    Console.WriteLine("\nFactorial Recursive:");
                    // "While" Loop Statement
                    while (i &amp;lt; values.Count)
                    {                        
                        testValue = values[i];
                        // Taking Time
                        timer.Start();
                        facTimeResult = FactorialR(testValue);
                        timer.Stop();
                        // Getting Time
                        Console.WriteLine(" ({0}) = {1}", testValue, timer.Elapsed);
                        i++;
                    }
                    break;
                case 3:
                    Console.WriteLine("\nFibonacci Imperative:");
                    // "Do-While" Loop Statement
                    do {
                        testValue = values[i];
                        // Taking Time
                        timer.Start();
                        fibTimeResult = FibonacciI(testValue);
                        timer.Stop();
                        // Getting Time
                        Console.WriteLine(" ({0}) = {1}", testValue, timer.Elapsed);
                        i++;
                    } while (i &amp;lt; values.Count);
                    break;
                case 4:
                    Console.WriteLine("\nFibonacci Recursive:");
                    // "For Each" Loop Statement
                    foreach (int item in values)
                    {
                        testValue = item;
                        // Taking Time
                        timer.Start();
                        fibTimeResult = FibonacciR(testValue);
                        timer.Stop();
                        // Getting Time
                        Console.WriteLine(" ({0}) = {1}", testValue, timer.Elapsed);
                    }
                    break;
                default:
                    Console.WriteLine("DONG!");
                    break;
            }                
        }
    }

    // Instance Class
    public class InstanceFiborial
    {
        // Instance Field
        string className;
        // Instance Constructor
        public InstanceFiborial()
        {
            this.className = "Instance Constructor";
            Console.WriteLine(this.className);
        }
        // Instance Method - Factorial Recursive
        public BigInteger FactorialR(int n)
        {
            // Calling Static Method
            return StaticFiborial.FactorialR(n);
        }
        // Instance Method - Factorial Imperative
        public BigInteger FactorialI(int n)
        {
            // Calling Static Method
            return StaticFiborial.FactorialI(n);
        }
        // Instance Method - Fibonacci Recursive
        public long FibonacciR(int n)
        {
            // Calling Static Method
            return StaticFiborial.FibonacciR(n);
        }
        // Instance Method - Factorial Imperative
        public long FibonacciI(int n)
        {
            // Calling Static Method
            return StaticFiborial.FibonacciI(n);
        }
    }

    public class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("\nStatic Class");
            // Calling Static Class and Methods
            // No instantiation needed. Calling method directly from the class
            Console.WriteLine("FacImp(5) = {0}", StaticFiborial.FactorialI(5));
            Console.WriteLine("FacRec(5) = {0}", StaticFiborial.FactorialR(5));
            Console.WriteLine("FibImp(11)= {0}", StaticFiborial.FibonacciI(11));
            Console.WriteLine("FibRec(11)= {0}", StaticFiborial.FibonacciR(11));

            Console.WriteLine("\nInstance Class");
            // Calling Instance Class and Methods 
            // Need to instantiate before using. Calling method from instantiated object
            InstanceFiborial ff = new InstanceFiborial();
            Console.WriteLine("FacImp(5) = {0}", ff.FactorialI(5));
            Console.WriteLine("FacRec(5) = {0}", ff.FactorialR(5));
            Console.WriteLine("FibImp(11)= {0}", ff.FibonacciI(11));
            Console.WriteLine("FibRec(11)= {0}", ff.FibonacciR(11));

            // Create a (generic) list of integer values to test
            // From 5 to 50 by 5
            List&amp;lt;int&amp;gt; values = new List&amp;lt;int&amp;gt;();
            for(int i = 5; i &amp;lt;= 50; i += 5)
                values.Add(i);

            // Benchmarking Fibonacci                     
            // 1 = Factorial Imperative            
            StaticFiborial.BenchmarkAlgorithm(1, values);
            // 2 = Factorial Recursive
            StaticFiborial.BenchmarkAlgorithm(2, values); 

            // Benchmarking Factorial            
            // 3 = Fibonacci Imperative
            StaticFiborial.BenchmarkAlgorithm(3, values);
            // 4 = Fibonacci Recursive
            StaticFiborial.BenchmarkAlgorithm(4, values); 

            // Stop and Exit
            Console.Read();
        }
    }
}
&lt;/pre&gt;&lt;br /&gt;
And the Output is: &lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-qz8HC4mhHLA/TV7F1GDkNyI/AAAAAAAAF3I/5J7EbUCwd3Q/s1600/fiborial_cs.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="640" src="http://2.bp.blogspot.com/-qz8HC4mhHLA/TV7F1GDkNyI/AAAAAAAAF3I/5J7EbUCwd3Q/s640/fiborial_cs.PNG" width="318" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;a href="http://2.bp.blogspot.com/_0_HCzHGe4_k/TM8Wwm7ILyI/AAAAAAAAFyQ/AziXveRyTGo/s1600/output_delphi.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;br /&gt;
&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Humm, looks like Fibonnaci's algorithm implemented using recursion is definitively more complex than the others 3 right? I will grab these results for this and each of the upcoming posts to prepare a comparison of time execution between all the programming languages, then we will be able to talk about the algorithm's complexity as well.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Printing the Factorial and Fibonacci Series&lt;/b&gt;&lt;br /&gt;
&lt;pre class="csharp" name="code"&gt;using System;
using System.Text;
using System.Numerics;

namespace FiborialSeries
{    
    static class Fiborial
    {
        // Using a StringBuilder as a list of string elements
        public static string GetFactorialSeries(int n)
        {
            // Create the String that will hold the list
            StringBuilder series = new StringBuilder();
            // We begin by concatenating the number you want to calculate
            // in the following format: "!# ="
            series.Append("!");
            series.Append(n);
            series.Append(" = ");
            // We iterate backwards through the elements of the series
            for (int i = n; i &amp;lt;= n &amp;amp;&amp;amp; i &amp;gt; 0; i--)
            {
                // and append it to the list
                series.Append(i);
                if (i &amp;gt; 1)
                    series.Append(" * ");
                else 
                    series.Append(" = "); 
            }
            // Get the result from the Factorial Method
            // and append it to the end of the list
            series.Append(Factorial(n));
            // return the list as a string
            return series.ToString();
        }

        // Using a StringBuilder as a list of string elements
        public static string GetFibonnaciSeries(int n)
        {
            // Create the String that will hold the list
            StringBuilder series = new StringBuilder();
            // We begin by concatenating the first 3 values which
            // are always constant
            series.Append("0, 1, 1");
            // Then we calculate the Fibonacci of each element
            // and add append it to the list
            for (int i = 2; i &amp;lt;= n; i++)
            {
                if (i &amp;lt; n)
                    series.Append(", ");
                else
                    series.Append(" = ");
                
                series.Append(Fibonacci(i));
            }
            // return the list as a string
            return series.ToString();
        }

        public static BigInteger Factorial(int n)
        {
            if (n == 1)
                return 1;
            else
                return n * Factorial(n - 1);
        }

        public static long Fibonacci(int n)
        {
            if (n &amp;lt; 2)
                return 1;
            else
                return Fibonacci(n - 1) + Fibonacci(n - 2);
        }
        
    }

    class Program
    {
        static void Main(string[] args)
        {            
            // Printing Factorial Series
            Console.WriteLine();
            Console.WriteLine(Fiborial.GetFactorialSeries(5));
            Console.WriteLine(Fiborial.GetFactorialSeries(7));
            Console.WriteLine(Fiborial.GetFactorialSeries(9));
            Console.WriteLine(Fiborial.GetFactorialSeries(11));
            Console.WriteLine(Fiborial.GetFactorialSeries(40));
            // Printing Fibonacci Series
            Console.WriteLine();
            Console.WriteLine(Fiborial.GetFibonnaciSeries(5));
            Console.WriteLine(Fiborial.GetFibonnaciSeries(7));
            Console.WriteLine(Fiborial.GetFibonnaciSeries(9));
            Console.WriteLine(Fiborial.GetFibonnaciSeries(11));
            Console.WriteLine(Fiborial.GetFibonnaciSeries(40));
        }
    }
}
&lt;/pre&gt;&lt;br /&gt;
And the Output is:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-VnmsQKymX6A/TV7F9gdP6mI/AAAAAAAAF3M/WX3-L7LTG4E/s1600/fiborial_cs_extras_series.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="315" src="http://1.bp.blogspot.com/-VnmsQKymX6A/TV7F9gdP6mI/AAAAAAAAF3M/WX3-L7LTG4E/s640/fiborial_cs_extras_series.PNG" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Mixing Instance and Static Members in the same Class&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
We can also define instance classes that have both, instance and static members such as: fields, properties, constructors, methods, etc. However, we cannot do that if the class is marked as static because of the features mentioned in the previous post:&lt;br /&gt;
The main features of a static class are:&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;They only contain static members.&lt;/li&gt;
&lt;li&gt;They cannot be instantiated.&lt;/li&gt;
&lt;li&gt;They are sealed.&lt;/li&gt;
&lt;li&gt;They cannot contain Instance Constructors&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;pre class="csharp" name="code"&gt;using System;
namespace FiborialExtrasCs2
{
    // Instance Classes can have both: static and instance members. 
    // However, Static Classes only allow static members to be defined.
    // If you declare our next example class as static
    // (static class Fiborial) you will get the following compile error
    // Error: cannot declare instance members in a static class
    
    // Instance Class
    class Fiborial
    {
        // Instance Field
        private int instanceCount;
        // Static Field
        private static int staticCount;        
        // Instance Read-Only Property
        // Within instance members, you can always use  
        // the "this" reference pointer to access your (instance) members.
        public int InstanceCount
        {
            get { return this.instanceCount; }
        }
        // Static Read-Only Property
        // Remeber that Properties are Methods to the CLR, so, you can also
        // define static properties for static fields. 
        // As with Static Methods, you cannot reference your class members
        // with the "this" reference pointer since static members are not
        // instantiated.        
        public static int StaticCount
        {
            get { return staticCount; }
        }
        // Instance Constructor
        public Fiborial()
        {
            this.instanceCount = 0;
            Console.WriteLine("\nInstance Constructor {0}", this.instanceCount);
        }
        // Static Constructor
        static Fiborial()
        {
            staticCount = 0;
            Console.WriteLine("\nStatic Constructor {0}", staticCount);
        }

        // Instance Method
        public void Factorial(int n)
        {
            this.instanceCount += 1;
            Console.WriteLine("\nFactorial({0})", n);
        }

        // Static Method
        public static void Fibonacci(int n)
        {
            staticCount += 1;
            Console.WriteLine("\nFibonacci({0})", n);
        }                
    }
    
    class Program
    {
        static void Main(string[] args)
        {
            // Calling Static Constructor and Methods
            // No need to instantiate
            Fiborial.Fibonacci(5);            

            // Calling Instance Constructor and Methods
            // Instance required
            Fiborial fib = new Fiborial();
            fib.Factorial(5);            

            Fiborial.Fibonacci(15);            
            fib.Factorial(5);

            // Calling Instance Constructor and Methods
            // for a second object
            Fiborial fib2 = new Fiborial();
            fib2.Factorial(5);
            
            Console.WriteLine();
            // Calling Static Property
            Console.WriteLine("Static Count = {0}", Fiborial.StaticCount);
            // Calling Instance Property of object 1 and 2
            Console.WriteLine("Instance 1 Count = {0}", fib.InstanceCount);
            Console.WriteLine("Instance 2 Count = {0}", fib2.InstanceCount);
        }
    }
}
&lt;/pre&gt;&lt;br /&gt;
And the Output is:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/_0_HCzHGe4_k/TURToGdHe5I/AAAAAAAAF24/3fS5N1CwEWA/s1600/fiborial_cs_extras2.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="326" src="http://2.bp.blogspot.com/_0_HCzHGe4_k/TURToGdHe5I/AAAAAAAAF24/3fS5N1CwEWA/s400/fiborial_cs_extras2.PNG" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;a href="http://4.bp.blogspot.com/_0_HCzHGe4_k/TM8x5bVLv0I/AAAAAAAAFyU/ZHtgJE97Fdk/s1600/delphi_properties.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;br /&gt;
&lt;/a&gt;&lt;br /&gt;
&lt;a href="http://2.bp.blogspot.com/_0_HCzHGe4_k/TJYz5ZgkFGI/AAAAAAAAFwk/Y8rwLu2Bags/s1600/output_ipy_ext.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;br /&gt;
&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Factorial using System.Int64, System.Double, System.Numerics.BigInteger&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
The Factorial of numbers over 20 are massive!&lt;br /&gt;
For instance: !40 = 815915283247897734345611269596115894272000000000!&lt;br /&gt;
Because of this, the previous version of this program was giving the "wrong" result &lt;br /&gt;
!40 = -70609262346240000 when using "long" (System.Int64) type, but it was not until I did the Fiborial version in VB.NET that I realized about this faulty code, because instead of giving me a wrong value, VB.NET execution thrown an Overflow Exception when using the "Long" (System.Int64) type.&lt;br /&gt;
&lt;br /&gt;
My first idea was to use ulong and ULong, but both failed for "big" numbers. I then used Double (double floating point) type and got no more exception/wrong result. The result of the factorial was now correct !40 = 1.1962222086548E+56, but still I wanted to show the Integer value of it, so I did some research and found that there is a new System.Numerics.BigInteger class in the .NET Framework 4.0. Adding the reference to the project and using this new class as the return type of the Factorial methods, I was able to get the result I was expecting.&lt;br /&gt;
!40 = 815915283247897734345611269596115894272000000000&lt;br /&gt;
&lt;br /&gt;
What I also found was that using different types change the time the algorithm takes to finish:&lt;br /&gt;
System.Int64 &amp;lt; System.Double &amp;lt; System.Numerics.BigInteger  &lt;br /&gt;
Almost by double!&lt;br /&gt;
&lt;br /&gt;
To illustrate what I just "tried" to say, lets have a look at the following code and the output we get.  &lt;br /&gt;
&lt;br /&gt;
&lt;pre class="csharp" name="code"&gt;using System;
using System.Numerics;
using System.Diagnostics;

namespace FiborialExtrasCs3
{
    class Program
    {
        static void Main(string[] args)
        {
            Stopwatch timer = new Stopwatch();
            System.Int64 facIntResult = 0;
            System.Double facDblResult = 0;
            System.Numerics.BigInteger facBigResult = 0;

            Console.WriteLine(&amp;quot;\nFactorial using Int64&amp;quot;);
            // Benchmark Factorial using Int64
            for (int i = 5; i &amp;lt;= 50; i += 5)
            {
                timer.Start();
                facIntResult = FactorialInt64(i);
                timer.Stop();
                Console.WriteLine(&amp;quot; ({0}) = {1} : {2}&amp;quot;, i, timer.Elapsed, facIntResult);
            }
            Console.WriteLine(&amp;quot;\nFactorial using Double&amp;quot;);
            // Benchmark Factorial using Double
            for (int i = 5; i &amp;lt;= 50; i += 5)
            {
                timer.Start();
                facDblResult = FactorialDouble(i);
                timer.Stop();
                Console.WriteLine(&amp;quot; ({0}) = {1} : {2}&amp;quot;, i, timer.Elapsed, facDblResult);
            }
            Console.WriteLine(&amp;quot;\nFactorial using BigInteger&amp;quot;);
            // Benchmark Factorial using BigInteger
            for (int i = 5; i &amp;lt;= 50; i += 5)
            {
                timer.Start();
                facBigResult = FactorialBigInteger(i);
                timer.Stop();
                Console.WriteLine(&amp;quot; ({0}) = {1} : {2}&amp;quot;, i, timer.Elapsed, facBigResult);
            }
        }

        // Long Factorial 
        public static Int64 FactorialInt64(int n)
        {
            if (n == 1)
                return 1;
            else
                return n * FactorialInt64(n - 1);
        }

        // Double Factorial 
        public static Double FactorialDouble(int n)
        {
            if (n == 1)
                return 1;
            else
                return n * FactorialDouble(n - 1);
        }
        
        // BigInteger Factorial 
        public static BigInteger FactorialBigInteger(int n)
        {
            if (n == 1)
                return 1;
            else
                return n * FactorialBigInteger(n - 1);
        }
    }
}
&lt;/pre&gt;&lt;br /&gt;
NOTE: you need to manually add a reference to the System.Numerics assembly to your project so you can add it to your code.&lt;br /&gt;
&lt;br /&gt;
And the Output is:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-2-4d6QuBMJs/TV7QlOfAukI/AAAAAAAAF3Q/i6nhpGvOSgc/s1600/fiborial_cs_extras_big_int.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="510" src="http://1.bp.blogspot.com/-2-4d6QuBMJs/TV7QlOfAukI/AAAAAAAAF3Q/i6nhpGvOSgc/s640/fiborial_cs_extras_big_int.PNG" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/694679611587040520-161620563506046261?l=carlosqt.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/r7qVfkk2m2v42ZDmEbhGjCTpivU/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/r7qVfkk2m2v42ZDmEbhGjCTpivU/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/r7qVfkk2m2v42ZDmEbhGjCTpivU/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/r7qVfkk2m2v42ZDmEbhGjCTpivU/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/CarlosQuintanillasBlog/~4/1LVNsvTC7Bg" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://carlosqt.blogspot.com/feeds/161620563506046261/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://carlosqt.blogspot.com/2011/01/factorial-and-fibonacci-in-c.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/694679611587040520/posts/default/161620563506046261?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/694679611587040520/posts/default/161620563506046261?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/CarlosQuintanillasBlog/~3/1LVNsvTC7Bg/factorial-and-fibonacci-in-c.html" title="Factorial and Fibonacci in C#" /><author><name>Carlos QT</name><uri>http://www.blogger.com/profile/15415604076909500411</uri><email>carlosqt@gmail.com</email><gd:extendedProperty name="OpenSocialUserId" value="14144067369073378952" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/-qz8HC4mhHLA/TV7F1GDkNyI/AAAAAAAAF3I/5J7EbUCwd3Q/s72-c/fiborial_cs.PNG" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://carlosqt.blogspot.com/2011/01/factorial-and-fibonacci-in-c.html</feedburner:origLink></entry><entry gd:etag="W/&quot;AkEEQHgzeyp7ImA9Wx9VEUs.&quot;"><id>tag:blogger.com,1999:blog-694679611587040520.post-653344741629664300</id><published>2011-01-25T15:06:00.000-08:00</published><updated>2011-01-27T14:50:01.683-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-01-27T14:50:01.683-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Series" /><title>New Series - Factorial and Fibonacci</title><content type="html">&lt;a class="twitter-share-button" data-count="horizontal" data-via="carlosqt" href="http://twitter.com/share"&gt;Tweet&lt;/a&gt;&lt;script src="http://platform.twitter.com/widgets.js" type="text/javascript"&gt;
&lt;/script&gt;&lt;br /&gt;
I'm going to start a new series of posts called &lt;b&gt;"Factorial and Fibonacci in [Language]"&lt;/b&gt;. As with my previous 2 series, &lt;a href="http://carlosqt.blogspot.com/2010/06/oo-hello-world.html"&gt;"OO Hello World"&lt;/a&gt; and &lt;a href="http://carlosqt.blogspot.com/2010/08/new-series-languages-basics-by-example.html"&gt;"Language's Basics by Example"&lt;/a&gt;, my aim is to show programming language's basic features, and as such, I will be showing stuff such as: static members, instance member, recursion, more loops and conditional constructs, and whatever else comes up. The idea is to write a simple OO program that implements the Factorial and Fibonacci algorithms in a Functional (Recursion) and Imperative (Statements-Loops) way using static methods and fields plus different loop statements such as Do, While, For, For each, etc. I will also add the Timer classes provided by the language's framework to count how much time those algorithms take (benchmark?) and do some comparison of the timing by language.&lt;br /&gt;
&lt;br /&gt;
From now on, I will not be including 2 versions of the same program. First, to save some space and second, because counting keywords is not the main topic anymore. So, a mix of minimal and verbose syntax in each of the languages will be used instead.&lt;br /&gt;
&lt;br /&gt;
The languages:&lt;br /&gt;
.NET/CLR: &lt;a href="http://carlosqt.blogspot.com/2010/06/oo-hello-world-c.html"&gt;C#&lt;/a&gt;, &lt;a href="http://carlosqt.blogspot.com/2010/06/oo-hello-world-vbnet.html"&gt;VB.NET&lt;/a&gt;, &lt;a href="http://carlosqt.blogspot.com/2010/06/oo-hello-world-ccli.html"&gt;C++/CLI&lt;/a&gt;, &lt;a href="http://carlosqt.blogspot.com/2010/06/oo-hello-world-f.html"&gt;F#&lt;/a&gt;, &lt;a href="http://carlosqt.blogspot.com/2010/06/hello-world-in-boo-is-here-as-well.html"&gt;Boo&lt;/a&gt;, &lt;a href="http://carlosqt.blogspot.com/2010/06/oo-hello-world-phalanger.html"&gt;Phalanger&lt;/a&gt;, &lt;a href="http://carlosqt.blogspot.com/2010/06/oo-hello-world-ironpython.html"&gt;IronPython&lt;/a&gt;, &lt;a href="http://carlosqt.blogspot.com/2010/06/oo-hello-world-ironruby.html"&gt;IronRuby&lt;/a&gt;, &lt;a href="http://carlosqt.blogspot.com/2010/06/oo-hello-world-delphi-prism.html"&gt;Delphi Prism&lt;/a&gt;, &lt;a href="http://carlosqt.blogspot.com/2010/06/oo-hello-world-zonnon.html"&gt;Zonnon&lt;/a&gt;, &lt;a href="http://carlosqt.blogspot.com/2010/06/oo-hello-world-nemerle.html"&gt;Nemerle&lt;/a&gt;, &lt;a href="http://carlosqt.blogspot.com/2010/07/oo-hello-world-cobra.html"&gt;Cobra&lt;/a&gt;, &lt;a href="http://carlosqt.blogspot.com/2010/07/oo-hello-world-jscript.html"&gt;JScript.NET&lt;/a&gt;&lt;br /&gt;
Java/JVM: &lt;a href="http://carlosqt.blogspot.com/2010/06/oo-hello-world-groovy.html"&gt;Groovy&lt;/a&gt;, &lt;a href="http://carlosqt.blogspot.com/2010/07/oo-hello-world-java.html"&gt;Java&lt;/a&gt;, &lt;a href="http://carlosqt.blogspot.com/2010/07/oo-hello-world-jython.html"&gt;Jython&lt;/a&gt;, &lt;a href="http://carlosqt.blogspot.com/2010/07/oo-hello-world-jruby.html"&gt;JRuby&lt;/a&gt;, &lt;a href="http://carlosqt.blogspot.com/2010/07/oo-hello-world-fantom.html"&gt;Fantom&lt;/a&gt;, &lt;a href="http://carlosqt.blogspot.com/2010/07/oo-hello-world-scala.html"&gt;Scala&lt;/a&gt;, &lt;a href="http://carlosqt.blogspot.com/2010/08/oo-hello-world-javafx.html"&gt;JavaFX&lt;/a&gt;, &lt;a href="http://carlosqt.blogspot.com/2010/11/oo-hello-world-gosu.html"&gt;Gosu&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The Program's Structure will be (more or less) as follows:&lt;br /&gt;
&lt;pre class="csharp" name="code"&gt;// Factorial and Fibonacci in Language
    // Static Class
        // Static Fields
        // Static Constructor
        // Static Method 1
            // Recursive Fibonacci
        // Static Method 2
            // Imperative Fibonacci
        // Static Method 3
            // Recursive Factorial
        // Static Method 4
            // Imperative Factorial
        // Static Method 5
            // For Loop Range
                // Start Timer
                // Call Static Method: Recursive Fibonacci
                // Stop Timer
                // Print Result
            // While Loop Range
                // Start Timer
                // Call Static Method: Imperative Fibonacci
                // Stop Timer
                // Print Result
            // Do Loop Range
                // Start Timer
                // Call Static Method: Recursive Factorial
                // Stop Timer
                // Print Result
            // For Each Loop Range
                // Start Timer
                // Call Static Method: Imperative Factorial
                // Stop Timer
                // Print Result

    // Instance Class
        // Instance Fields
        // Instance Constructor
        // Instance Method 1
            // Call Static Recursive Fibonacci
        // Instance Method 2
            // Call Static Imperative Fibonacci
        // Instance Method 3
            // Call Static Recursive Factorial
        // Instance Method 4
            // Call Static Imperative Factorial

    // Console Program/Script
        // Calling Static Class and Methods
        // Calling Instance Class and Methods
        // Create a List of values to test
        // Benchmarking Fibonacci
        // Call Factorial Imperative
        // Call Factorial Recursive
        // Benchmarking Factorial
        // Call Fibonacci Imperative
        // Call Fibonacci Recursive
        // Stop and exit
&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
And here below some definitions of the new concepts:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Factorial&lt;/b&gt;&lt;br /&gt;
"In mathematics, the factorial of a positive integer n,[1] denoted by n!, is the product of all positive integers less than or equal to n. For example:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;5! = 5 x 4 x 3 x 2 x 1 = 120&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
0! is a special case that is explicitly defined to be 1."&lt;br /&gt;
Taken from: &lt;a href="http://en.wikipedia.org/wiki/Factorial#Definition"&gt;http://en.wikipedia.org/wiki/Factorial#Definition&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Fibonacci&lt;/b&gt;&lt;br /&gt;
"In mathematics, the Fibonacci numbers are the numbers in the following integer sequence:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;0,1,1,2,3,5,8,13,21,34,55,89,144, ...&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
By definition, the first two Fibonacci numbers are 0 and 1, and each subsequent number is the sum of the previous two. Some sources omit the initial 0, instead beginning the sequence with two 1s." Taken from: &lt;a href="http://en.wikipedia.org/wiki/Fibonacci_series"&gt;http://en.wikipedia.org/wiki/Fibonacci_series&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Recursion&lt;/b&gt;&lt;br /&gt;
"Recursion is the process of repeating items in a self-similar way. For instance, when the surfaces of two mirrors are exactly parallel with each other the nested images that occur are a form of infinite recursion. The term has a variety of meanings specific to a variety of disciplines ranging from linguistics to logic. The most common application of recursion is in mathematics and computer science, in which it refers to a method of defining functions in which the function being defined is applied within its own definition; specifically it is defining an infinite statement using finite components." Taken from: &lt;a href="http://en.wikipedia.org/wiki/Recursion"&gt;http://en.wikipedia.org/wiki/Recursion&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Imperative&lt;/b&gt;&lt;br /&gt;
"In computer science, imperative programming is a programming paradigm that describes computation in terms of statements that change a program state. In much the same way that imperative mood in natural languages expresses commands to take action, imperative programs define sequences of commands for the computer to perform." Taken from: &lt;a href="http://en.wikipedia.org/wiki/Imperative_programming"&gt;http://en.wikipedia.org/wiki/Imperative_programming&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Static Class&lt;/b&gt;&lt;br /&gt;
"A class can be declared static, indicating that it contains only static members. It is not possible to create instances of a static class using the new keyword. &lt;br /&gt;
&lt;br /&gt;
Use a static class to contain methods that are not associated with a particular object. For example, it is a common requirement to create a set of methods that do not act on instance data and are not associated to a specific object in your code. You could use a static class to hold those methods.&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;The main features of a static class are:&lt;/li&gt;
&lt;li&gt;They only contain static members.&lt;/li&gt;
&lt;li&gt;They cannot be instantiated.&lt;/li&gt;
&lt;li&gt;They are sealed.&lt;/li&gt;
&lt;li&gt;They cannot contain Instance Constructors (C# Programming Guide).&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
Creating a static class is therefore much the same as creating a class that contains only static members and a private constructor. A private constructor prevents the class from being instantiated.&lt;br /&gt;
&lt;br /&gt;
The advantage of using a static class is that the compiler can check to make sure that no instance members are accidentally added. The compiler will guarantee that instances of this class cannot be created. &lt;br /&gt;
&lt;br /&gt;
Static classes are sealed and therefore cannot be inherited. Static classes cannot contain a constructor, although it is still possible to declare a static constructor to assign initial values or set up some static state." Taken from: &lt;a href="http://msdn.microsoft.com/en-us/library/79b3xss3(v=vs.80).aspx"&gt;http://msdn.microsoft.com/en-us/library/79b3xss3(v=vs.80).aspx&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Static Variable&lt;/b&gt;&lt;br /&gt;
"In computer programming, a static variable is a variable that has been allocated statically — whose lifetime extends across the entire run of the program. This is in contrast to the more ephemeral automatic variables (local variables), whose storage is allocated and deallocated on the call stack; and in contrast to objects whose storage is dynamically allocated." Taken from: &lt;a href="http://en.wikipedia.org/wiki/Static_variable#Static_Variables_as_Class_Variables"&gt;http://en.wikipedia.org/wiki/Static_variable#Static_Variables_as_Class_Variables&lt;/a&gt; &lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Static Method&lt;/b&gt;&lt;br /&gt;
"In object-oriented programming, a method is a subroutine that is exclusively associated either with a class (in which case it is called a class method or a static method) or with an object (in which case it is an instance method).&lt;br /&gt;
&lt;br /&gt;
As mentioned above, a method may be declared as static, meaning that it acts at the class level rather than at the instance level. Therefore, a static method cannot refer to a specific instance of the class (i.e. it cannot refer to this, self, Me, etc.), unless such references are made through a parameter referencing an instance of the class, although in such cases they must be accessed through the parameter's identifier instead of this. Most importantly there is no need to make an object for accessing data .i.e. without creating an object we can access the data members of a static class." Taken from: &lt;a href="http://en.wikipedia.org/wiki/Static_method#Static_methods"&gt;http://en.wikipedia.org/wiki/Static_method#Static_methods&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Static Constructor&lt;/b&gt;&lt;br /&gt;
"A static constructor is a static data initializer. Static constructors allow complex static variable initialization.[1] Static constructors can be called once and call is made implicitly by the run-time right before the first time the class is accessed. Any call to a class (static or constructor call), triggers the static constructor execution. Static constructors are thread safe and are a great way to implement a singleton pattern. When used in a generic programming class, static constructors are called on every new generic instantiation one per type (static variables are instantiated as well)." Taken from:&lt;a href="http://en.wikipedia.org/wiki/Constructor_(object-oriented_programming)#C.23_static_constructor"&gt;http://en.wikipedia.org/wiki/Constructor_(object-oriented_programming)#C.23_static_constructor&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Benchmark&lt;/b&gt;&lt;br /&gt;
"In computing, a benchmark is the act of running a computer program, a set of programs, or other operations, in order to assess the relative performance of an object, normally by running a number of standard tests and trials against it. The term 'benchmark' is also mostly utilized for the purposes of elaborately-designed benchmarking programs themselves." Taken from: &lt;a href="http://en.wikipedia.org/wiki/Benchmark_(computing)"&gt;http://en.wikipedia.org/wiki/Benchmark_(computing)&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style="background-color: blue;"&gt;&lt;span style="color: blue;"&gt;&lt;span style="background-color: white;"&gt;return;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/694679611587040520-653344741629664300?l=carlosqt.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/BdEEiKJ4XJoMJ7MxWiU8JTYVEvg/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/BdEEiKJ4XJoMJ7MxWiU8JTYVEvg/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/BdEEiKJ4XJoMJ7MxWiU8JTYVEvg/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/BdEEiKJ4XJoMJ7MxWiU8JTYVEvg/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/CarlosQuintanillasBlog/~4/5Wli-817cBo" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://carlosqt.blogspot.com/feeds/653344741629664300/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://carlosqt.blogspot.com/2011/01/new-series-factorial-and-fibonacci.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/694679611587040520/posts/default/653344741629664300?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/694679611587040520/posts/default/653344741629664300?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/CarlosQuintanillasBlog/~3/5Wli-817cBo/new-series-factorial-and-fibonacci.html" title="New Series - Factorial and Fibonacci" /><author><name>Carlos QT</name><uri>http://www.blogger.com/profile/15415604076909500411</uri><email>carlosqt@gmail.com</email><gd:extendedProperty name="OpenSocialUserId" value="14144067369073378952" /></author><thr:total>0</thr:total><feedburner:origLink>http://carlosqt.blogspot.com/2011/01/new-series-factorial-and-fibonacci.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CUUAR3s9cSp7ImA9Wx9WEU4.&quot;"><id>tag:blogger.com,1999:blog-694679611587040520.post-1743009779541863657</id><published>2011-01-15T15:14:00.000-08:00</published><updated>2011-01-15T15:14:06.569-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-01-15T15:14:06.569-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Keywords" /><category scheme="http://www.blogger.com/atom/ns#" term="Python" /><title>Counting Source Code Keywords using Python 3</title><content type="html">&lt;a class="twitter-share-button" data-count="horizontal" data-via="carlosqt" href="http://twitter.com/share"&gt;Tweet&lt;/a&gt;&lt;script src="http://platform.twitter.com/widgets.js" type="text/javascript"&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;br /&gt;
Now that I finished my last post about counting keywords in source code, I will give away the little script I did to help me with the counting. It definitively requires some improvements to cover some extra cases I did not consider, but it work just fine if you manage to avoid them... or even better, implement them yourself :D&lt;br /&gt;
&lt;br /&gt;
1. Multi-line comments are not supported. If there are reserved words within the comments, they will be counted as keywords. But worry not; single line comments work fine.&lt;br /&gt;
&lt;br /&gt;
2. Text literals are not supported. If there are reserved words within the string, they will be counted as keywords.&lt;br /&gt;
&lt;br /&gt;
I think regular expressions can handle those 2 cases. I'll add those two features if I need them in the future.&lt;br /&gt;
&lt;br /&gt;
The programming language used was Python version 3.1.3&lt;br /&gt;
&lt;br /&gt;
I formatted some parts of the code to correctly display it using the size limit of this blog's page. For instance, if the script doesn't compile; try using one line comma separated lists and if statements.&lt;br /&gt;
&lt;br /&gt;
I think the code is simple and very easy to read... that's what all programmers say about their own code, right? Anyway, here below, I will begin by showing, function by function, the code of the script including lots of unnecessary comments and some screen shots that help explain what it does. Next, I will show a complete example of how to use it and the output. &lt;br /&gt;
The complete script without comments it's available at the bottom of this post.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Dissecting the Script&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="python" name="code"&gt;# import from sys to handle script's (command line) parameters
import sys
# get_line_comment_char function returns the Language's single 
# line character(s)
# only one &amp;quot;single comments character&amp;quot; is taken in consideration 
# even if the language supports multiple single line comments
# I grouped languages using the same comment character to reduce 
# the number of ifs
def get_line_comment_char(language):
    language = language.lower()    
    if language in ('c#', 'csharp', 'cpp', 'cppcli', 'c++', 'c++cli', 'f#', 
                    'fsharp', 'boo', 'phalanger', 'php', 'delphiprism', 'delphi', 
                    'nemerle', 'groovy', 'java', 'fantom', 'fan', 'jscript', 
                    'jscriptnet', 'scala', 'javafx', 'javafxscript', 'gosu'):
        return '//'
    elif language in ('vb', 'vbnet', 'visualbasic'):
        return '\''
    elif language in ('jython', 'ironpython', 'python', 'jruby', 'ironruby', 
                    'ruby', 'cobra'):
        return '#'        
    elif language in ('zonnon'):
        return '(*'
    return None
&lt;/pre&gt;&lt;br /&gt;
Example:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/_0_HCzHGe4_k/TTIRgff0ZjI/AAAAAAAAFz0/pm_iLnzi6kE/s1600/def_get_line_comment_char.PNG" imageanchor="1" style="clear:left; float:left;margin-right:1em; margin-bottom:1em"&gt;&lt;img border="0" height="199" width="364" src="http://2.bp.blogspot.com/_0_HCzHGe4_k/TTIRgff0ZjI/AAAAAAAAFz0/pm_iLnzi6kE/s400/def_get_line_comment_char.PNG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="python" name="code"&gt;# get_language_keywords function returns a list of all the 
# keywords (reserved words) for the given language
# except for the primitive types since I didn't consider them 
# as keywords for my comparison purposes
# if you need them, you can take the complete keywords lists 
# this blog's Keywords page
# I removed the lists to save space because it makes the program
# too long and less readable, so, in the function below, 
# for every ocurrence of keywords = '' you change '' with the list 
# of keywords of that language.
def get_language_keywords(language):
    language = language.lower()    
    if language == 'c#' or language == 'csharp':
        keywords = '' 
    elif language == 'vb' or language == 'vbnet' 
        or language == 'visualbasic':        
        keywords = '' 
    elif language == 'cpp' or language == 'cppcli' 
        or language == 'c++' or language == 'c++cli':
        keywords = '' 
    elif language == 'f#' or language == 'fsharp':        
        keywords = '' 
    elif language == &amp;quot;boo&amp;quot;:
        keywords = '' 
    elif language == 'phalanger' or language == 'php':
        keywords = '' 
    elif language == 'jython' or language == 'ironpython' 
        or language == 'python':        
        keywords = '' 
    elif language == 'jruby' or language == 'ironruby' 
        or language == 'ruby':
        keywords = '' 
    elif language == 'delphiprism' or language == 'delphi':
        keywords = '' 
    elif language == 'zonnon':
        keywords = '' 
    elif language == 'nemerle':
        keywords = '' 
    elif language == 'groovy':
        keywords = '' 
    elif language == 'java':
        keywords = '' 
    elif language == 'cobra':
        keywords = '' 
    elif language == 'fantom' or language == 'fan':
        keywords = '' 
    elif language == 'jscript' or language == 'jscriptnet':
        keywords = '' 
    elif language == 'scala':
        keywords = '' 
    elif language == 'javafx' or language == 'javafxscript':
        keywords = '' 
    elif language == 'gosu':
        keywords = '' 
    else:
        keywords = ''
    return keywords.split()
&lt;/pre&gt;&lt;br /&gt;
Example:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/_0_HCzHGe4_k/TTIS6UihK8I/AAAAAAAAFz8/Dr0zqXdaxYY/s1600/def_get_language_keywords.PNG" imageanchor="1" style="clear:left; float:left;margin-right:1em; margin-bottom:1em"&gt;&lt;img border="0" height="198" width="400" src="http://3.bp.blogspot.com/_0_HCzHGe4_k/TTIS6UihK8I/AAAAAAAAFz8/Dr0zqXdaxYY/s400/def_get_language_keywords.PNG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="python" name="code"&gt;# is_keyword function returns true if the given keyword is a 
# valid keyword in the given language
def is_keyword(key, language_keys):    
    if key in language_keys:
        return True
    return False
&lt;/pre&gt;&lt;br /&gt;
Example:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/_0_HCzHGe4_k/TTIT4RuMA_I/AAAAAAAAF0E/oJTQJ3OHCQo/s1600/def_is_keyword.PNG" imageanchor="1" style="clear:left; float:left;margin-right:1em; margin-bottom:1em"&gt;&lt;img border="0" height="120" width="400" src="http://2.bp.blogspot.com/_0_HCzHGe4_k/TTIT4RuMA_I/AAAAAAAAF0E/oJTQJ3OHCQo/s400/def_is_keyword.PNG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="python" name="code"&gt;# remove_special_characters function removes special characters 
# from the given text and returns the resulting sequence
# special characters includes open and closing blocks, 
# operators, and so on (see the list below).
def remove_special_characters(text):
    special_characters = ('(','[','{','}',']',')','+','-','*','/','=','^','&amp;amp;',
                        '%','$','#','@','!','~','\'','\&amp;quot;', '?', '&amp;gt;', '&amp;lt;', ':', 
                        ';', ',', '.')
    for character in special_characters:
        text = text.replace(character, ' ')
    return text
&lt;/pre&gt;&lt;br /&gt;
Example:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/_0_HCzHGe4_k/TTIWKlieuLI/AAAAAAAAF0M/fisCMmaZR1c/s1600/def_remove_special_characters.PNG" imageanchor="1" style="clear:left; float:left;margin-right:1em; margin-bottom:1em"&gt;&lt;img border="0" height="86" width="400" src="http://1.bp.blogspot.com/_0_HCzHGe4_k/TTIWKlieuLI/AAAAAAAAF0M/fisCMmaZR1c/s400/def_remove_special_characters.PNG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="python" name="code"&gt;# remove_duplicates_in_list function removes any duplicate value 
# found in the given sequence and returns the resulting sequence
def remove_duplicates_in_list(sequence):
    # Thanks to Dave Kirby for this function taken from comments in 
    # http://www.peterbe.com/plog/uniqifiers-benchmark 
    seen = set()
    seen_add = seen.add
    return [x for x in sequence if x not in seen and not seen_add(x)]
&lt;/pre&gt;&lt;br /&gt;
Example:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/_0_HCzHGe4_k/TTIXF7-rVsI/AAAAAAAAF0U/TeRQnHhOM-U/s1600/def_remove_duplicates_in_list.PNG" imageanchor="1" style="clear:left; float:left;margin-right:1em; margin-bottom:1em"&gt;&lt;img border="0" height="83" width="400" src="http://3.bp.blogspot.com/_0_HCzHGe4_k/TTIXF7-rVsI/AAAAAAAAF0U/TeRQnHhOM-U/s400/def_remove_duplicates_in_list.PNG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="python" name="code"&gt;# count_ocurrences_in_list function returns a new list of paired values 
# that contain the keyword and how many times it appeared in the code
# using the standard count method of the sequences types
def count_ocurrences_in_list(sequence):
    totals_by_word = []
    no_duplicates = remove_duplicates_in_list(sequence)
    for word in no_duplicates:
        totals_by_word.append((word,sequence.count(word)))
    return totals_by_word
&lt;/pre&gt;&lt;br /&gt;
Example:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/_0_HCzHGe4_k/TTIXxFikTtI/AAAAAAAAF0c/57h5xPnvtZA/s1600/def_count_ocurrences_in_list.PNG" imageanchor="1" style="clear:left; float:left;margin-right:1em; margin-bottom:1em"&gt;&lt;img border="0" height="89" width="400" src="http://1.bp.blogspot.com/_0_HCzHGe4_k/TTIXxFikTtI/AAAAAAAAF0c/57h5xPnvtZA/s400/def_count_ocurrences_in_list.PNG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="python" name="code"&gt;# print_results function prints the given sequence to the console
# It displays the list of Keyword and Total Number of Keywords
def print_results(sequence):
    print('', end='\n')    
    for item in sequence:
        print('%s, %s' % (item[0], item[1]))    
&lt;/pre&gt;&lt;br /&gt;
Example:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/_0_HCzHGe4_k/TTIZQwEnLRI/AAAAAAAAF0k/lRDlgoQJ9p0/s1600/def_print_results.PNG" imageanchor="1" style="clear:left; float:left;margin-right:1em; margin-bottom:1em"&gt;&lt;img border="0" height="198" width="400" src="http://3.bp.blogspot.com/_0_HCzHGe4_k/TTIZQwEnLRI/AAAAAAAAF0k/lRDlgoQJ9p0/s400/def_print_results.PNG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="python" name="code"&gt;# print_to_file function creates an output file and prints the given 
# sequence into it. 
# It writes the list of Keyword and Total Number of Keywords
def print_to_file(sequence, output):
    with open(output, mode='w', encoding='utf-8') as output_file:
        output_file.write('\n')
        for item in sequence:
            output_file.write('%s, %s\n' % (item[0], item[1]))
&lt;/pre&gt;&lt;br /&gt;
Example:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/_0_HCzHGe4_k/TTIaDWcRxfI/AAAAAAAAF0s/p5L7d53hHK4/s1600/def_print_to_file.PNG" imageanchor="1" style="clear:left; float:left;margin-right:1em; margin-bottom:1em"&gt;&lt;img border="0" height="100" width="400" src="http://3.bp.blogspot.com/_0_HCzHGe4_k/TTIaDWcRxfI/AAAAAAAAF0s/p5L7d53hHK4/s400/def_print_to_file.PNG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
Output:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/_0_HCzHGe4_k/TTIaXWVnwII/AAAAAAAAF00/3V8e8gKv0oM/s1600/def_print_to_file_output_file.PNG" imageanchor="1" style="clear:left; float:left;margin-right:1em; margin-bottom:1em"&gt;&lt;img border="0" height="220" width="400" src="http://1.bp.blogspot.com/_0_HCzHGe4_k/TTIaXWVnwII/AAAAAAAAF00/3V8e8gKv0oM/s400/def_print_to_file_output_file.PNG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
Opening CSV:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/_0_HCzHGe4_k/TTIaxbuiLCI/AAAAAAAAF08/G_gu28vQTms/s1600/def_print_to_file_output_open_csv.PNG" imageanchor="1" style="clear:left; float:left;margin-right:1em; margin-bottom:1em"&gt;&lt;img border="0" height="271" width="277" src="http://4.bp.blogspot.com/_0_HCzHGe4_k/TTIaxbuiLCI/AAAAAAAAF08/G_gu28vQTms/s400/def_print_to_file_output_open_csv.PNG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="python" name="code"&gt;# Main function. The program's entry point.
def main(argv=None):
    # if command line arguments are not empty
    if argv is None:
        # assign them to the local sequence variable argv
        argv = sys.argv
    
    # validate the script was used correctly. 
    if len(argv) != 4:
        # Otherwise, print the usage message to the console
        print(&amp;quot;usage: program language sourcefile outputfile&amp;quot;)
        # and exit the script
        sys.exit()
&lt;/pre&gt;&lt;br /&gt;
Example:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/_0_HCzHGe4_k/TTIbepClA6I/AAAAAAAAF1E/n-9nKS_VwpM/s1600/main_script_usage.PNG" imageanchor="1" style="clear:left; float:left;margin-right:1em; margin-bottom:1em"&gt;&lt;img border="0" height="75" width="400" src="http://4.bp.blogspot.com/_0_HCzHGe4_k/TTIbepClA6I/AAAAAAAAF1E/n-9nKS_VwpM/s400/main_script_usage.PNG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="python" name="code"&gt;# get command line arguments
    # parameter 2 should be the language of the source code you want to count
    programming_language = sys.argv[1]    
    # parameter 3 should be the file that contains the source code you want to count
    source_file = sys.argv[2]    
    # parameter 4 should be the file that will contain the counting results
    output_file = sys.argv[3]     
    # get the list of reserved words for the given programming language
    language_keywords = get_language_keywords(programming_language)
    # get the single line comment character for the given programming language
    comment_character = get_line_comment_char(programming_language)
&lt;/pre&gt;&lt;br /&gt;
Example:&lt;br /&gt;
Here I added some print() and exit() to stop execution of the script&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/_0_HCzHGe4_k/TTIcbMQiFJI/AAAAAAAAF1M/_ROlpcb8xAc/s1600/main_script_print_parameters.PNG" imageanchor="1" style="clear:left; float:left;margin-right:1em; margin-bottom:1em"&gt;&lt;img border="0" height="123" width="400" src="http://3.bp.blogspot.com/_0_HCzHGe4_k/TTIcbMQiFJI/AAAAAAAAF1M/_ROlpcb8xAc/s400/main_script_print_parameters.PNG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="python" name="code"&gt;# define a variable that will hold the total number of keywords found in the file
    total_keywords_found = 0
    # define a list that will store all valid language keywords found in the file
    list_of_keywords_found = []
&lt;/pre&gt;&lt;br /&gt;
&lt;pre class="python" name="code"&gt;line_number = 0
    # open a file as read only (default mode)
    with open(source_file, encoding='utf-8') as source_code:
        # navigate through the lines of the file
        for line in source_code:
            # get the line number. Used only for console display purposes
            line_number += 1
&lt;/pre&gt;&lt;br /&gt;
Example:&lt;br /&gt;
The following line adds the line number to the beginning of the line being read&lt;br /&gt;
print('{:&gt;4} {}'.format(line_number, line.rstrip()), end='\n')&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/_0_HCzHGe4_k/TTIepdVn6YI/AAAAAAAAF1U/IhN9dNPMO4s/s1600/main_script_print_line_number_code.PNG" imageanchor="1" style="clear:left; float:left;margin-right:1em; margin-bottom:1em"&gt;&lt;img border="0" height="160" width="400" src="http://1.bp.blogspot.com/_0_HCzHGe4_k/TTIepdVn6YI/AAAAAAAAF1U/IhN9dNPMO4s/s400/main_script_print_line_number_code.PNG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="python" name="code"&gt;# remove line comment if there is one based on the 
            # language's single line comment character  
            comment_idx = line.find(comment_character)
            if comment_idx &amp;gt;= 0:
                line = line[0:comment_idx]
&lt;/pre&gt;&lt;br /&gt;
Example:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/_0_HCzHGe4_k/TTIgBKEHkgI/AAAAAAAAF1c/TTeE0zIP2xo/s1600/main_script_remove_comments.PNG" imageanchor="1" style="clear:left; float:left;margin-right:1em; margin-bottom:1em"&gt;&lt;img border="0" height="141" width="400" src="http://4.bp.blogspot.com/_0_HCzHGe4_k/TTIgBKEHkgI/AAAAAAAAF1c/TTeE0zIP2xo/s400/main_script_remove_comments.PNG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="python" name="code"&gt;# remove special characters from remaining text in line 
            # (operators and open-close characters)
            line = remove_special_characters(line)
            # create a list with all remaining words in the line
            words = line.split()
&lt;/pre&gt;&lt;br /&gt;
Example:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/_0_HCzHGe4_k/TTIg6AOKE0I/AAAAAAAAF1k/wcIPFz7ESp8/s1600/main_script_split_words.PNG" imageanchor="1" style="clear:left; float:left;margin-right:1em; margin-bottom:1em"&gt;&lt;img border="0" height="105" width="400" src="http://3.bp.blogspot.com/_0_HCzHGe4_k/TTIg6AOKE0I/AAAAAAAAF1k/wcIPFz7ESp8/s400/main_script_split_words.PNG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="python" name="code"&gt;# navigate through the words of the sequence
            for word in words:
                # if the current word is a valid keyword for the 
                # given language
                if is_keyword(word, language_keywords):                    
                    # add to the list of 
                    # &amp;quot;total keywords found in the source code&amp;quot; the word
                    list_of_keywords_found.append(word)
                    # increment the number of total words found 
                    # in the source code
                    total_keywords_found = total_keywords_found + 1
&lt;/pre&gt;&lt;br /&gt;
Example:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/_0_HCzHGe4_k/TTIhtDydM4I/AAAAAAAAF1s/SNa5NaUILjQ/s1600/main_script_find_keys.PNG" imageanchor="1" style="clear:left; float:left;margin-right:1em; margin-bottom:1em"&gt;&lt;img border="0" height="120" width="400" src="http://2.bp.blogspot.com/_0_HCzHGe4_k/TTIhtDydM4I/AAAAAAAAF1s/SNa5NaUILjQ/s400/main_script_find_keys.PNG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="python" name="code"&gt;# define a list that will store all paired 
    # values (keyword and total ocurrences of that keyword)
    totals_to_output = []    
    # insert first pair of values as the first element of the list, 
    # that is the Programming Language and the Total Keywords found
    totals_to_output.append((programming_language.capitalize(),str(total_keywords_found)))
    # insert all other pairs of values (keyword and total ocurrences 
    # of that keyword) found on the source code
    totals_to_output.extend(count_ocurrences_in_list(list_of_keywords_found))
&lt;/pre&gt;&lt;br /&gt;
Example:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/_0_HCzHGe4_k/TTIiXZIX6OI/AAAAAAAAF10/KFcxMrfWTBI/s1600/main_script_print_hdr_and_list_of_results.PNG" imageanchor="1" style="clear:left; float:left;margin-right:1em; margin-bottom:1em"&gt;&lt;img border="0" height="131" width="400" src="http://1.bp.blogspot.com/_0_HCzHGe4_k/TTIiXZIX6OI/AAAAAAAAF10/KFcxMrfWTBI/s400/main_script_print_hdr_and_list_of_results.PNG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="python" name="code"&gt;# print the results to the console
    print_results(totals_to_output)
    # print the results to the output file
    print_to_file(totals_to_output, output_file)

# run the program
if __name__ == &amp;quot;__main__&amp;quot;:    
    main()
&lt;/pre&gt;&lt;br /&gt;
Example:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/_0_HCzHGe4_k/TTIjAnwK3zI/AAAAAAAAF18/o7sKnoU89BI/s1600/main_script_final_result.PNG" imageanchor="1" style="clear:left; float:left;margin-right:1em; margin-bottom:1em"&gt;&lt;img border="0" height="231" width="400" src="http://1.bp.blogspot.com/_0_HCzHGe4_k/TTIjAnwK3zI/AAAAAAAAF18/o7sKnoU89BI/s400/main_script_final_result.PNG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Using the Script&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
How to use is was already shown in the step by step example above, but here below I just show you how I did the counting for my previous post "&lt;a href="http://carlosqt.blogspot.com/2011/01/how-many-keywords-in-your-source-code.html"&gt;Keywords in source code Round 2&lt;/a&gt;"&lt;br /&gt;
&lt;br /&gt;
First I created 2 folders:&lt;br /&gt;
1. SrcCode&lt;br /&gt;
2. OutCode&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/_0_HCzHGe4_k/TTIlE-zzVPI/AAAAAAAAF2E/i9bKJP8zf1U/s1600/usage_folders.PNG" imageanchor="1" style="clear:left; float:left;margin-right:1em; margin-bottom:1em"&gt;&lt;img border="0" height="324" width="400" src="http://3.bp.blogspot.com/_0_HCzHGe4_k/TTIlE-zzVPI/AAAAAAAAF2E/i9bKJP8zf1U/s400/usage_folders.PNG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then, I added all the source code files I wanted to count from into the SrcCode folder.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/_0_HCzHGe4_k/TTIlvM0iuCI/AAAAAAAAF2M/KEvL9tq8zxQ/s1600/usage_srccode_files.PNG" imageanchor="1" style="clear:left; float:left;margin-right:1em; margin-bottom:1em"&gt;&lt;img border="0" height="400" width="281" src="http://3.bp.blogspot.com/_0_HCzHGe4_k/TTIlvM0iuCI/AAAAAAAAF2M/KEvL9tq8zxQ/s400/usage_srccode_files.PNG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Next step was to create a batch file that runs the python script for all the files in the SrcCode folder.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/_0_HCzHGe4_k/TTImVftVhFI/AAAAAAAAF2U/2RNjRXTqa3I/s1600/usage_bat_file.PNG" imageanchor="1" style="clear:left; float:left;margin-right:1em; margin-bottom:1em"&gt;&lt;img border="0" height="205" width="400" src="http://3.bp.blogspot.com/_0_HCzHGe4_k/TTImVftVhFI/AAAAAAAAF2U/2RNjRXTqa3I/s400/usage_bat_file.PNG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
And ran it&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/_0_HCzHGe4_k/TTImnfqxt2I/AAAAAAAAF2c/8apSJYoCjLc/s1600/usage_run_bat.PNG" imageanchor="1" style="clear:left; float:left;margin-right:1em; margin-bottom:1em"&gt;&lt;img border="0" height="72" width="400" src="http://3.bp.blogspot.com/_0_HCzHGe4_k/TTImnfqxt2I/AAAAAAAAF2c/8apSJYoCjLc/s400/usage_run_bat.PNG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Console Output&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/_0_HCzHGe4_k/TTInKSac96I/AAAAAAAAF2k/7hlbwzatl4M/s1600/usage_console_output.PNG" imageanchor="1" style="clear:left; float:left;margin-right:1em; margin-bottom:1em"&gt;&lt;img border="0" height="399" width="400" src="http://2.bp.blogspot.com/_0_HCzHGe4_k/TTInKSac96I/AAAAAAAAF2k/7hlbwzatl4M/s400/usage_console_output.PNG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Files Output in folder OutCode&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/_0_HCzHGe4_k/TTIndEgo3TI/AAAAAAAAF2s/ibQ3D4KOvWI/s1600/usage_files_output.PNG" imageanchor="1" style="clear:left; float:left;margin-right:1em; margin-bottom:1em"&gt;&lt;img border="0" height="400" width="281" src="http://1.bp.blogspot.com/_0_HCzHGe4_k/TTIndEgo3TI/AAAAAAAAF2s/ibQ3D4KOvWI/s400/usage_files_output.PNG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Et Voilà! I then started merging together the results and did the graphs.&lt;br /&gt;
&lt;br /&gt;
Hope this script works for you or at least shows you some cool python features :)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Final Script&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Just don't forget to add the language keywords! take them from the Keywords Page.&lt;br /&gt;
Example:&lt;br /&gt;
keywords = 'public private static internal for if else while switch'&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="python" name="code"&gt;import sys

def get_line_comment_char(language):
    language = language.lower()    
    if language in ('c#', 'csharp', 'cpp', 'cppcli', 'c++', 'c++cli', 'f#', 
                    'fsharp', 'boo', 'phalanger', 'php', 'delphiprism', 'delphi', 
                    'nemerle', 'groovy', 'java', 'fantom', 'fan', 'jscript', 
                    'jscriptnet', 'scala', 'javafx', 'javafxscript', 'gosu'):
        return '//'
    elif language in ('vb', 'vbnet', 'visualbasic'):
        return '\''
    elif language in ('jython', 'ironpython', 'python', 'jruby', 'ironruby', 
                    'ruby', 'cobra'):
        return '#'        
    elif language in ('zonnon'):
        return '(*'
    return None

def get_language_keywords(language):
    language = language.lower()    
    if language == 'c#' or language == 'csharp':
        keywords = '' 
    elif language == 'vb' or language == 'vbnet' 
        or language == 'visualbasic':        
        keywords = '' 
    elif language == 'cpp' or language == 'cppcli' 
        or language == 'c++' or language == 'c++cli':
        keywords = '' 
    elif language == &amp;quot;f#&amp;quot; or language == &amp;quot;fsharp&amp;quot;:        
        keywords = '' 
    elif language == &amp;quot;boo&amp;quot;:
        keywords = '' 
    elif language == 'phalanger' or language == 'php':
        keywords = '' 
    elif language == 'jython' or language == 'ironpython' 
        or language == 'python':        
        keywords = '' 
    elif language == 'jruby' or language == 'ironruby' 
        or language == 'ruby':
        keywords = '' 
    elif language == 'delphiprism' or language == 'delphi':
        keywords = '' 
    elif language == 'zonnon':
        keywords = '' 
    elif language == 'nemerle':
        keywords = '' 
    elif language == 'groovy':
        keywords = '' 
    elif language == 'java':
        keywords = '' 
    elif language == 'cobra':
        keywords = '' 
    elif language == 'fantom' or language == 'fan':
        keywords = '' 
    elif language == 'jscript' or language == 'jscriptnet':
        keywords = '' 
    elif language == 'scala':
        keywords = '' 
    elif language == 'javafx' or language == 'javafxscript':
        keywords = '' 
    elif language == 'gosu':
        keywords = '' 
    else:
        keywords = ''
    return keywords.split()

def is_keyword(key, language_keys):    
    if key in language_keys:
        return True
    return False

def remove_special_characters(text):
    special_characters = ('(','[','{','}',']',')','+','-','*','/','=','^','&amp;amp;',
                        '%','$','#','@','!','~','\'','\&amp;quot;', '?', '&amp;gt;', '&amp;lt;', ':', 
                        ';', ',', '.')
    for character in special_characters:
        text = text.replace(character, ' ')
    return text

def remove_duplicates_in_list(sequence):
    seen = set()
    seen_add = seen.add
    return [x for x in sequence if x not in seen and not seen_add(x)]

def count_ocurrences_in_list(sequence):
    totals_by_word = []
    no_duplicates = remove_duplicates_in_list(sequence)
    for word in no_duplicates:
        totals_by_word.append((word,sequence.count(word)))
    return totals_by_word

def print_results(sequence):
    print('', end='\n')    
    for item in sequence:
        print('%s, %s' % (item[0], item[1]))    

def print_to_file(sequence, output):
    with open(output, mode='w', encoding='utf-8') as output_file:
        output_file.write('\n')
        for item in sequence:
            output_file.write('%s, %s\n' % (item[0], item[1]))

def main(argv=None):
    if argv is None:
        argv = sys.argv
    
    if len(argv) != 4:
        print(&amp;quot;usage: program language sourcefile outputfile&amp;quot;)
        sys.exit()

    programming_language = sys.argv[1]    
    source_file = sys.argv[2]    
    output_file = sys.argv[3]     
    
    language_keywords = get_language_keywords(programming_language)
    comment_character = get_line_comment_char(programming_language)
    
    total_keywords_found = 0
    list_of_keywords_found = []
    
    line_number = 0
    with open(source_file, encoding='utf-8') as source_code:
        for line in source_code:
            line_number += 1
            comment_idx = line.find(comment_character)
            if comment_idx &amp;gt;= 0:
                line = line[0:comment_idx]
            line = remove_special_characters(line)
            words = line.split()
            for word in words:
                if is_keyword(word, language_keywords):                    
                    list_of_keywords_found.append(word)
                    total_keywords_found = total_keywords_found + 1

    totals_to_output = []    
    totals_to_output.append((programming_language.capitalize(),str(total_keywords_found)))
    totals_to_output.extend(count_ocurrences_in_list(list_of_keywords_found))
    
    print_results(totals_to_output)
    print_to_file(totals_to_output, output_file)
    
if __name__ == &amp;quot;__main__&amp;quot;:    
    main()
&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/694679611587040520-1743009779541863657?l=carlosqt.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/MOLQBZqmmb_L8TKnam6iwyAhZCA/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/MOLQBZqmmb_L8TKnam6iwyAhZCA/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/MOLQBZqmmb_L8TKnam6iwyAhZCA/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/MOLQBZqmmb_L8TKnam6iwyAhZCA/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/CarlosQuintanillasBlog/~4/oUTvleUn_Qs" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://carlosqt.blogspot.com/feeds/1743009779541863657/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://carlosqt.blogspot.com/2011/01/counting-source-code-keywords-using.html#comment-form" title="2 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/694679611587040520/posts/default/1743009779541863657?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/694679611587040520/posts/default/1743009779541863657?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/CarlosQuintanillasBlog/~3/oUTvleUn_Qs/counting-source-code-keywords-using.html" title="Counting Source Code Keywords using Python 3" /><author><name>Carlos QT</name><uri>http://www.blogger.com/profile/15415604076909500411</uri><email>carlosqt@gmail.com</email><gd:extendedProperty name="OpenSocialUserId" value="14144067369073378952" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/_0_HCzHGe4_k/TTIRgff0ZjI/AAAAAAAAFz0/pm_iLnzi6kE/s72-c/def_get_line_comment_char.PNG" height="72" width="72" /><thr:total>2</thr:total><feedburner:origLink>http://carlosqt.blogspot.com/2011/01/counting-source-code-keywords-using.html</feedburner:origLink></entry><entry gd:etag="W/&quot;A0UHR308eSp7ImA9Wx9VEUs.&quot;"><id>tag:blogger.com,1999:blog-694679611587040520.post-8243043866663186801</id><published>2011-01-14T14:23:00.000-08:00</published><updated>2011-01-27T15:00:36.371-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-01-27T15:00:36.371-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Keywords" /><title>How many keywords in your source code? Round 2</title><content type="html">&lt;a class="twitter-share-button" data-count="horizontal" data-via="carlosqt" href="http://twitter.com/share"&gt;Tweet&lt;/a&gt;&lt;script src="http://platform.twitter.com/widgets.js" type="text/javascript"&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;br /&gt;
Last year, in July 2011, I wrote a post about &lt;a href="http://carlosqt.blogspot.com/2010/07/how-many-keywords-do-you-type-in-your.html"&gt;How many keywords do you type in your code?&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;"Have you ever wondered how many keywords (reserved words) do you type in your programs? Can you type more or type less without changing what your program does? Can you change programming language and save some typing? And if so, to which language?".&amp;nbsp;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
Back then, I tried to answer those questions by showing some comparative graphics with the number of keywords needed to build 2 versions (minimal and verbose) of the same little program in 20 different programming languages (C#, VB.NET, C++/CLI, F#, Boo, Phalanger, IronPython, IronRuby, Delphi Prism, Zonnon, Nemerle, Cobra, JScript.NET, Java, JavaFX, Groovy, Jython, JRuby, Fantom, Scala).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The program I chose was an &lt;a href="http://carlosqt.blogspot.com/2010/06/oo-hello-world.html"&gt;OO version of the famous Hello World&lt;/a&gt; (Archive posts June-July 2010) and had the following structure:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="csharp" name="code"&gt;// OO Hello World
    // Import,using,etc.
    // Class
        // Field
        // Constructor
        // Method
    // Program
        // Instantiate Class
        // Call Method = OUTPUT (Hello, World!)
&lt;/pre&gt;&lt;br /&gt;
Finally, I added some comments and thoughts about the results, but... What if we do the same with a bigger example? Will the results be more or less the same if I a more elaborated program is used to do the comparison? Do the most verbose language and the most minimalistic of the previous post will still hold the title? &lt;br /&gt;
&lt;br /&gt;
That's exactly what this new post is all about! :) a new comparison on a more elaborated, still small, program using many more language constructs following the sample rules of the previous comparison:&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;2 Versions Minimal and Verbose.&lt;/li&gt;
&lt;li&gt;21 Programming Languages (the previous 20 + Gosu).&lt;/li&gt;
&lt;li&gt;Primitive Types such as int, float, double, string not considered as keywords.&lt;/li&gt;
&lt;li&gt;Same OO program and structure (taken from series &lt;a href="http://carlosqt.blogspot.com/2010/08/new-series-languages-basics-by-example.html"&gt;Language's Basics by Example&lt;/a&gt;).&lt;/li&gt;
&lt;li&gt;OO Hello World was small enough to count by hand, but this time I created a little  script written in Python 3 that does the automatic counting for me :) (source code to be provided in my next post).&amp;nbsp;&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;pre class="csharp" name="code"&gt;// Language Basics
    // Greet Class
        // Fields or Attributes
        // Properties
        // Constructor
        // Overloaded Constructor
        // Method 1
            // "if-then-else" statement
        // Method 2
            // "for" statement
        // Overloaded Method 2.1
            // "while" statement
        // Overloaded Method 2.2
            // use Date Class
            // "switch/case" statement

    // Console Program
        // Define object of type Greet 
        // Instantiate Greet. Call Constructor
        // Call Set Properties
        // Call Method 2
        // Call Method 2.1 and Get Properties
        // Call Method 2.2
        // Stop and exit - Read Input From Console
&lt;/pre&gt;&lt;br /&gt;
Here below th graphs! Click on the images to enlarge.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Total Keywords by Language&lt;/b&gt;&lt;br /&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;             &lt;td&gt;&lt;br /&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;                         &lt;td&gt;Language&lt;/td&gt;                         &lt;td&gt;Keywords&lt;/td&gt;                     &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;IronPython&lt;/td&gt;                         &lt;td&gt;31&lt;/td&gt;                     &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;Jython&lt;/td&gt;                         &lt;td&gt;31&lt;/td&gt;                     &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;IronRuby&lt;/td&gt;                         &lt;td&gt;38&lt;/td&gt;                     &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;JRuby&lt;/td&gt;                         &lt;td&gt;38&lt;/td&gt;                     &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;Scala&lt;/td&gt;                         &lt;td&gt;40&lt;/td&gt;                     &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;Fantom&lt;/td&gt;                         &lt;td&gt;46&lt;/td&gt;                     &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;Java&lt;/td&gt;                         &lt;td&gt;50&lt;/td&gt;                     &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;Zonnon&lt;/td&gt;                         &lt;td&gt;50&lt;/td&gt;                     &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;Gosu&lt;/td&gt;                         &lt;td&gt;53&lt;/td&gt;                     &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;Groovy&lt;/td&gt;                         &lt;td&gt;57&lt;/td&gt;                     &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;Nemerle&lt;/td&gt;                         &lt;td&gt;59&lt;/td&gt;                     &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;Boo&lt;/td&gt;                         &lt;td&gt;66&lt;/td&gt;                     &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;JavaFX&lt;/td&gt;                         &lt;td&gt;70&lt;/td&gt;                     &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;JScript.NET&lt;/td&gt;                         &lt;td&gt;75&lt;/td&gt;                     &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;C++/CLI&lt;/td&gt;                         &lt;td&gt;84&lt;/td&gt;                     &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;Phalanger&lt;/td&gt;                         &lt;td&gt;92&lt;/td&gt;                     &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;F#&lt;/td&gt;                         &lt;td&gt;97&lt;/td&gt;                     &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;C#&lt;/td&gt;                         &lt;td&gt;102&lt;/td&gt;                     &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;Delphi Prism&lt;/td&gt;                         &lt;td&gt;134&lt;/td&gt;                     &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;VB.NET&lt;/td&gt;                         &lt;td&gt;137&lt;/td&gt;                     &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;Cobra&lt;/td&gt;                         &lt;td&gt;139&lt;/td&gt;                     &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/td&gt;             &lt;td&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/_0_HCzHGe4_k/TS-BnG7UN_I/AAAAAAAAFzg/qo52lMRNQiU/s1600/Copy+of+image009.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="640" src="http://3.bp.blogspot.com/_0_HCzHGe4_k/TS-BnG7UN_I/AAAAAAAAFzg/qo52lMRNQiU/s640/Copy+of+image009.png" width="464" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;/td&gt;         &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Version 1 (Minimal)&lt;/b&gt;&lt;br /&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;             &lt;td&gt;&lt;br /&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;                         &lt;td&gt;Language&lt;/td&gt;                         &lt;td&gt;Keywords&lt;/td&gt;                     &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;VB.NET&lt;/td&gt;                         &lt;td&gt;130&lt;/td&gt;                     &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;Delphi Prism&lt;/td&gt;                         &lt;td&gt;94&lt;/td&gt;                     &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;Phalanger&lt;/td&gt;                         &lt;td&gt;89&lt;/td&gt;                     &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;Cobra&lt;/td&gt;                         &lt;td&gt;79&lt;/td&gt;                     &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;JScript.NET&lt;/td&gt;                         &lt;td&gt;72&lt;/td&gt;                     &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;Groovy&lt;/td&gt;                         &lt;td&gt;72&lt;/td&gt;                     &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;Gosu&lt;/td&gt;                         &lt;td&gt;72&lt;/td&gt;                     &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;C#&lt;/td&gt;                         &lt;td&gt;69&lt;/td&gt;                     &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;Boo&lt;/td&gt;                         &lt;td&gt;68&lt;/td&gt;                     &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;Zonnon&lt;/td&gt;                         &lt;td&gt;66&lt;/td&gt;                     &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;Java&lt;/td&gt;                         &lt;td&gt;65&lt;/td&gt;                     &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;JavaFX&lt;/td&gt;                         &lt;td&gt;64&lt;/td&gt;                     &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;C++/CLI&lt;/td&gt;                         &lt;td&gt;59&lt;/td&gt;                     &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;Jython&lt;/td&gt;                         &lt;td&gt;51&lt;/td&gt;                     &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;IronPython&lt;/td&gt;                         &lt;td&gt;48&lt;/td&gt;                     &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;JRuby&lt;/td&gt;                         &lt;td&gt;46&lt;/td&gt;                     &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;IronRuby&lt;/td&gt;                         &lt;td&gt;46&lt;/td&gt;                     &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;Fantom&lt;/td&gt;                         &lt;td&gt;46&lt;/td&gt;                     &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;F#&lt;/td&gt;                         &lt;td&gt;41&lt;/td&gt;                     &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;Scala&lt;/td&gt;                         &lt;td&gt;37&lt;/td&gt;                     &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;Nemerle&lt;/td&gt;                         &lt;td&gt;33&lt;/td&gt;                     &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/td&gt;             &lt;td&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/_0_HCzHGe4_k/TS-C0L2Ry2I/AAAAAAAAFzk/UPHQtLPXLrM/s1600/Copy+of+image001.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="640" src="http://4.bp.blogspot.com/_0_HCzHGe4_k/TS-C0L2Ry2I/AAAAAAAAFzk/UPHQtLPXLrM/s640/Copy+of+image001.png" width="462" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;/td&gt;         &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;
&lt;b&gt;Version 2 (Verbose)&lt;/b&gt;&lt;br /&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;             &lt;td&gt;&lt;br /&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;Language&lt;/td&gt;                         &lt;td&gt;Keywords&lt;/td&gt;                     &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;VB.NET&lt;/td&gt;                         &lt;td&gt;169&lt;/td&gt;                     &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;Delphi Prism&lt;/td&gt;                         &lt;td&gt;134&lt;/td&gt;                     &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;JScript.NET&lt;/td&gt;                         &lt;td&gt;118&lt;/td&gt;                     &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;Gosu&lt;/td&gt;                         &lt;td&gt;114&lt;/td&gt;                     &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;Boo&lt;/td&gt;                         &lt;td&gt;114&lt;/td&gt;                     &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;Cobra&lt;/td&gt;                         &lt;td&gt;109&lt;/td&gt;                     &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;JavaFX&lt;/td&gt;                         &lt;td&gt;105&lt;/td&gt;                     &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;Phalanger&lt;/td&gt;                         &lt;td&gt;103&lt;/td&gt;                     &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;Java&lt;/td&gt;                         &lt;td&gt;103&lt;/td&gt;                     &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;C#&lt;/td&gt;                         &lt;td&gt;103&lt;/td&gt;                     &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;Groovy&lt;/td&gt;                         &lt;td&gt;101&lt;/td&gt;                     &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;C++/CLI&lt;/td&gt;                         &lt;td&gt;101&lt;/td&gt;                     &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;Zonnon&lt;/td&gt;                         &lt;td&gt;90&lt;/td&gt;                     &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;Fantom&lt;/td&gt;                         &lt;td&gt;80&lt;/td&gt;                     &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;Nemerle&lt;/td&gt;                         &lt;td&gt;67&lt;/td&gt;                     &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;F#&lt;/td&gt;                         &lt;td&gt;54&lt;/td&gt;                     &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;Jython&lt;/td&gt;                         &lt;td&gt;53&lt;/td&gt;                     &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;IronPython&lt;/td&gt;                         &lt;td&gt;50&lt;/td&gt;                     &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;JRuby&lt;/td&gt;                         &lt;td&gt;48&lt;/td&gt;                     &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;IronRuby&lt;/td&gt;                         &lt;td&gt;48&lt;/td&gt;                     &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;Scala&lt;/td&gt;                         &lt;td&gt;41&lt;/td&gt;                     &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/td&gt;             &lt;td&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/_0_HCzHGe4_k/TS-DEILwEmI/AAAAAAAAFzs/5XqUuL8oI3s/s1600/Copy+of+image003.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="640" src="http://3.bp.blogspot.com/_0_HCzHGe4_k/TS-DEILwEmI/AAAAAAAAFzs/5XqUuL8oI3s/s640/Copy+of+image003.png" width="458" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;/td&gt;         &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Both (Minimal and Verbose)&amp;nbsp;&lt;/b&gt;&lt;br /&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;             &lt;td&gt;&lt;br /&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;                         &lt;td&gt;Language&lt;/td&gt;                         &lt;td&gt;Minimal&lt;/td&gt;                         &lt;td&gt;Verbose&lt;/td&gt;                     &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;VB.NET&lt;/td&gt;                         &lt;td&gt;130&lt;/td&gt;                         &lt;td&gt;169&lt;/td&gt;                     &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;Delphi Prism&lt;/td&gt;                         &lt;td&gt;94&lt;/td&gt;                         &lt;td&gt;134&lt;/td&gt;                     &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;Phalanger&lt;/td&gt;                         &lt;td&gt;89&lt;/td&gt;                         &lt;td&gt;103&lt;/td&gt;                     &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;Cobra&lt;/td&gt;                         &lt;td&gt;79&lt;/td&gt;                         &lt;td&gt;109&lt;/td&gt;                     &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;JScript.NET&lt;/td&gt;                         &lt;td&gt;72&lt;/td&gt;                         &lt;td&gt;118&lt;/td&gt;                     &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;Groovy&lt;/td&gt;                         &lt;td&gt;72&lt;/td&gt;                         &lt;td&gt;101&lt;/td&gt;                     &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;Gosu&lt;/td&gt;                         &lt;td&gt;72&lt;/td&gt;                         &lt;td&gt;114&lt;/td&gt;                     &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;C#&lt;/td&gt;                         &lt;td&gt;69&lt;/td&gt;                         &lt;td&gt;103&lt;/td&gt;                     &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;Boo&lt;/td&gt;                         &lt;td&gt;68&lt;/td&gt;                         &lt;td&gt;114&lt;/td&gt;                     &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;Zonnon&lt;/td&gt;                         &lt;td&gt;66&lt;/td&gt;                         &lt;td&gt;90&lt;/td&gt;                     &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;Java&lt;/td&gt;                         &lt;td&gt;65&lt;/td&gt;                         &lt;td&gt;103&lt;/td&gt;                     &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;JavaFX&lt;/td&gt;                         &lt;td&gt;64&lt;/td&gt;                         &lt;td&gt;105&lt;/td&gt;                     &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;C++/CLI&lt;/td&gt;                         &lt;td&gt;59&lt;/td&gt;                         &lt;td&gt;101&lt;/td&gt;                     &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;Jython&lt;/td&gt;                         &lt;td&gt;51&lt;/td&gt;                         &lt;td&gt;53&lt;/td&gt;                     &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;IronPython&lt;/td&gt;                         &lt;td&gt;48&lt;/td&gt;                         &lt;td&gt;50&lt;/td&gt;                     &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;JRuby&lt;/td&gt;                         &lt;td&gt;46&lt;/td&gt;                         &lt;td&gt;48&lt;/td&gt;                     &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;IronRuby&lt;/td&gt;                         &lt;td&gt;46&lt;/td&gt;                         &lt;td&gt;48&lt;/td&gt;                     &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;Fantom&lt;/td&gt;                         &lt;td&gt;46&lt;/td&gt;                         &lt;td&gt;80&lt;/td&gt;                     &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;F#&lt;/td&gt;                         &lt;td&gt;41&lt;/td&gt;                         &lt;td&gt;54&lt;/td&gt;                     &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;Scala&lt;/td&gt;                         &lt;td&gt;37&lt;/td&gt;                         &lt;td&gt;41&lt;/td&gt;                     &lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;Nemerle&lt;/td&gt;                         &lt;td&gt;33&lt;/td&gt;                         &lt;td&gt;67&lt;/td&gt;                     &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/td&gt;             &lt;td&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/_0_HCzHGe4_k/TS-C-SmQ3VI/AAAAAAAAFzo/HGRpBkD3x2M/s1600/Copy+of+image005.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="400" src="http://1.bp.blogspot.com/_0_HCzHGe4_k/TS-C-SmQ3VI/AAAAAAAAFzo/HGRpBkD3x2M/s400/Copy+of+image005.png" width="375" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;/td&gt;         &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Compare Basics and HelloWorld (Minimal and Verbose)&amp;nbsp;&lt;/b&gt;&lt;br /&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;             &lt;td&gt;&lt;br /&gt;
&lt;table border="0"&gt;&lt;tbody&gt;
&lt;tr&gt;                         &lt;td&gt;Language|&lt;/td&gt;  &lt;td&gt;Basics Minimal|&lt;/td&gt;  &lt;td&gt;Basics Verbose|&lt;/td&gt;  &lt;td&gt;&lt;span style="color: #cc0000;"&gt;Basics Differ&lt;/span&gt;|&lt;/td&gt;  &lt;td&gt;Hello  Minimal|&lt;/td&gt;  &lt;td&gt;Hello  Verbose|&lt;/td&gt;  &lt;td&gt;&lt;span style="color: #cc0000;"&gt;Hello  Differ&lt;/span&gt;|&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;VB.NET&lt;/td&gt;  &lt;td&gt;130&lt;/td&gt;&lt;td&gt;169&lt;/td&gt;&lt;td&gt;&lt;span style="color: #cc0000;"&gt;39&lt;/span&gt;&lt;/td&gt;&lt;td&gt;24&lt;/td&gt;&lt;td&gt;34&lt;/td&gt;&lt;td&gt;&lt;span style="color: #cc0000;"&gt;10&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;Delphi Prism&lt;/td&gt;  &lt;td&gt;94&lt;/td&gt;&lt;td&gt;134&lt;/td&gt;&lt;td&gt;&lt;span style="color: #cc0000;"&gt;40&lt;/span&gt;&lt;/td&gt;&lt;td&gt;35&lt;/td&gt;&lt;td&gt;39&lt;/td&gt;&lt;td&gt;&lt;span style="color: #cc0000;"&gt;4&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;Phalanger&lt;/td&gt;     &lt;td&gt;89&lt;/td&gt;&lt;td&gt;103&lt;/td&gt;&lt;td&gt;&lt;span style="color: #cc0000;"&gt;14&lt;/span&gt;&lt;/td&gt;&lt;td&gt;10&lt;/td&gt;&lt;td&gt;16&lt;/td&gt;&lt;td&gt;&lt;span style="color: #cc0000;"&gt;6&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;Cobra&lt;/td&gt;         &lt;td&gt;79&lt;/td&gt;&lt;td&gt;109&lt;/td&gt;&lt;td&gt;&lt;span style="color: #cc0000;"&gt;30&lt;/span&gt;&lt;/td&gt;&lt;td&gt;9&lt;/td&gt;&lt;td&gt;14&lt;/td&gt;&lt;td&gt;&lt;span style="color: #cc0000;"&gt;5&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;JScript.NET&lt;/td&gt;   &lt;td&gt;72&lt;/td&gt;&lt;td&gt;118&lt;/td&gt;&lt;td&gt;&lt;span style="color: #cc0000;"&gt;46&lt;/span&gt;&lt;/td&gt;&lt;td&gt;7&lt;/td&gt;&lt;td&gt;15&lt;/td&gt;&lt;td&gt;&lt;span style="color: #cc0000;"&gt;8&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;Groovy&lt;/td&gt;        &lt;td&gt;72&lt;/td&gt;&lt;td&gt;101&lt;/td&gt;&lt;td&gt;&lt;span style="color: #cc0000;"&gt;29&lt;/span&gt;&lt;/td&gt;&lt;td&gt;5&lt;/td&gt;&lt;td&gt;11&lt;/td&gt;&lt;td&gt;&lt;span style="color: #cc0000;"&gt;6&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;Gosu&lt;/td&gt;          &lt;td&gt;72&lt;/td&gt;&lt;td&gt;114&lt;/td&gt;&lt;td&gt;&lt;span style="color: #cc0000;"&gt;42&lt;/span&gt;&lt;/td&gt;&lt;td&gt;5&lt;/td&gt;&lt;td&gt;13&lt;/td&gt;&lt;td&gt;&lt;span style="color: #cc0000;"&gt;8&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;C#&lt;/td&gt;            &lt;td&gt;69&lt;/td&gt;&lt;td&gt;103&lt;/td&gt;&lt;td&gt;&lt;span style="color: #cc0000;"&gt;34&lt;/span&gt;&lt;/td&gt;&lt;td&gt;10&lt;/td&gt;&lt;td&gt;15&lt;/td&gt;&lt;td&gt;&lt;span style="color: #cc0000;"&gt;5&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;Boo&lt;/td&gt;           &lt;td&gt;68&lt;/td&gt;&lt;td&gt;114&lt;/td&gt;&lt;td&gt;&lt;span style="color: #cc0000;"&gt;46&lt;/span&gt;&lt;/td&gt;&lt;td&gt;7&lt;/td&gt;&lt;td&gt;17&lt;/td&gt;&lt;td&gt;&lt;span style="color: #cc0000;"&gt;10&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;Zonnon&lt;/td&gt;        &lt;td&gt;66&lt;/td&gt;&lt;td&gt;90&lt;/td&gt;&lt;td&gt;&lt;span style="color: #cc0000;"&gt;24&lt;/span&gt;&lt;/td&gt;&lt;td&gt;16&lt;/td&gt;&lt;td&gt;21&lt;/td&gt;&lt;td&gt;&lt;span style="color: #cc0000;"&gt;5&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;Java&lt;/td&gt;          &lt;td&gt;65&lt;/td&gt;&lt;td&gt;103&lt;/td&gt;&lt;td&gt;&lt;span style="color: #cc0000;"&gt;38&lt;/span&gt;&lt;/td&gt;&lt;td&gt;12&lt;/td&gt;&lt;td&gt;16&lt;/td&gt;&lt;td&gt;&lt;span style="color: #cc0000;"&gt;4&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;JavaFX&lt;/td&gt;        &lt;td&gt;64&lt;/td&gt;&lt;td&gt;105&lt;/td&gt;&lt;td&gt;&lt;span style="color: #cc0000;"&gt;41&lt;/span&gt;&lt;/td&gt;&lt;td&gt;5&lt;/td&gt;&lt;td&gt;15&lt;/td&gt;&lt;td&gt;&lt;span style="color: #cc0000;"&gt;10&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;C++/CLI&lt;/td&gt;       &lt;td&gt;59&lt;/td&gt;&lt;td&gt;101&lt;/td&gt;&lt;td&gt;&lt;span style="color: #cc0000;"&gt;42&lt;/span&gt;&lt;/td&gt;&lt;td&gt;11&lt;/td&gt;&lt;td&gt;16&lt;/td&gt;&lt;td&gt;&lt;span style="color: #cc0000;"&gt;5&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;Jython&lt;/td&gt;        &lt;td&gt;51&lt;/td&gt;&lt;td&gt;53&lt;/td&gt;&lt;td&gt;&lt;span style="color: #cc0000;"&gt;2&lt;/span&gt;&lt;/td&gt;&lt;td&gt;4&lt;/td&gt;&lt;td&gt;6&lt;/td&gt;&lt;td&gt;&lt;span style="color: #cc0000;"&gt;2&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;IronPython&lt;/td&gt;    &lt;td&gt;48&lt;/td&gt;&lt;td&gt;50&lt;/td&gt;&lt;td&gt;&lt;span style="color: #cc0000;"&gt;2&lt;/span&gt;&lt;/td&gt;&lt;td&gt;4&lt;/td&gt;&lt;td&gt;6&lt;/td&gt;&lt;td&gt;&lt;span style="color: #cc0000;"&gt;2&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;JRuby&lt;/td&gt;         &lt;td&gt;46&lt;/td&gt;&lt;td&gt;48&lt;/td&gt;&lt;td&gt;&lt;span style="color: #cc0000;"&gt;2&lt;/span&gt;&lt;/td&gt;&lt;td&gt;6&lt;/td&gt;&lt;td&gt;6&lt;/td&gt;&lt;td&gt;&lt;span style="color: #cc0000;"&gt;0&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;IronRuby&lt;/td&gt;      &lt;td&gt;46&lt;/td&gt;&lt;td&gt;48&lt;/td&gt;&lt;td&gt;&lt;span style="color: #cc0000;"&gt;2&lt;/span&gt;&lt;/td&gt;&lt;td&gt;6&lt;/td&gt;&lt;td&gt;6&lt;/td&gt;&lt;td&gt;&lt;span style="color: #cc0000;"&gt;0&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;Fantom&lt;/td&gt;        &lt;td&gt;46&lt;/td&gt;&lt;td&gt;80&lt;/td&gt;&lt;td&gt;&lt;span style="color: #cc0000;"&gt;34&lt;/span&gt;&lt;/td&gt;&lt;td&gt;5&lt;/td&gt;&lt;td&gt;9&lt;/td&gt;&lt;td&gt;&lt;span style="color: #cc0000;"&gt;4&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;F#&lt;/td&gt;            &lt;td&gt;41&lt;/td&gt;&lt;td&gt;54&lt;/td&gt;&lt;td&gt;&lt;span style="color: #cc0000;"&gt;13&lt;/span&gt;&lt;/td&gt;&lt;td&gt;5&lt;/td&gt;&lt;td&gt;12&lt;/td&gt;&lt;td&gt;&lt;span style="color: #cc0000;"&gt;7&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;Scala&lt;/td&gt;         &lt;td&gt;37&lt;/td&gt;&lt;td&gt;41&lt;/td&gt;&lt;td&gt;&lt;span style="color: #cc0000;"&gt;4&lt;/span&gt;&lt;/td&gt;&lt;td&gt;5&lt;/td&gt;&lt;td&gt;10&lt;/td&gt;&lt;td&gt;&lt;span style="color: #cc0000;"&gt;5&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;                         &lt;td&gt;Nemerle&lt;/td&gt;       &lt;td&gt;33&lt;/td&gt;&lt;td&gt;67&lt;/td&gt;&lt;td&gt;&lt;span style="color: #cc0000;"&gt;34&lt;/span&gt;&lt;/td&gt;&lt;td&gt;9&lt;/td&gt;&lt;td&gt;16&lt;/td&gt;&lt;td&gt;&lt;span style="color: #cc0000;"&gt;7&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/td&gt;             &lt;/tr&gt;
&lt;tr&gt; &lt;td&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/_0_HCzHGe4_k/TS-Gt-Y68RI/AAAAAAAAFzw/9Eu-0-8_ibs/s1600/Copy+of+image007.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="640" src="http://2.bp.blogspot.com/_0_HCzHGe4_k/TS-Gt-Y68RI/AAAAAAAAFzw/9Eu-0-8_ibs/s640/Copy+of+image007.png" width="580" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;/td&gt;          &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;
&lt;b style="mso-bidi-font-weight: normal;"&gt;CONCLUSIONS&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
As with the previous post, we can still notice the 3 main groups of languages:&lt;br /&gt;
1. Scripting/Dynamic Languages (Python, Ruby, Groovy, etc.) fewer keywords&lt;br /&gt;
2. Functional Languages (F#, Scala, Nemerle, etc.) more or less than the previous group&lt;br /&gt;
3. Imperative/Static Languages (C#, C++, VB.NET, Java, etc.) more keywords&lt;br /&gt;
&lt;br /&gt;
We can also see that the scripting/dynamic languages are the ones that define the fewer keywords and that's probably the reason why there are few or no difference in the number of keywords typed between the 2 versions of the same program (see latest graph above).&lt;br /&gt;
&lt;br /&gt;
The difference between the number of keywords of the most verbose and the most minimalistic program is of:&lt;br /&gt;
Basics Minimal: VB.NET 130 vs Nemerle 33 (97 keys of difference)&lt;br /&gt;
Basics Verbose: VB.NET 169 vs Scala 41 (128 keys of difference)&lt;br /&gt;
Big differences... and they could be much bigger if we include primitive types as keywords (because they are keywords, but were excluded for this comparison)&lt;br /&gt;
&lt;br /&gt;
When comparing a small program such as the OO Hello World in which didn't use many language constructs we still saw a big difference between the most verbose and the most minimalistic languages. That is still true when many more statements and constructs are added to the code as in the case of: Delphi Prism and VB.NET, however, this time we can clearly see that the most verbose language is not Delphi Prism but VB.NET!!! &lt;br /&gt;
&lt;br /&gt;
So, VB.NET congratulations! You are the most extra-typing language among the .NET and Java languages. I guess that's why Visual Studio 2010 auto-completes all the closing blocks keywords :D so you don't need to type that many... I'm wondering what about those programmers that love to code in raw text using notepad(++?)... I guess those brave of hearth do not program using VB. Am I right?  &lt;br /&gt;
&lt;br /&gt;
Nevertheless, I'm very curious about running the keywords counting on a Real Life program (hundreds-thousands lines of code) and see what the result is. &lt;br /&gt;
&lt;br /&gt;
And now, about the most minimalistic language? Well, this time was Nemerle, followed by Scala and F#. The 3 languages are multi-paradigm languages, but are mainly inspired by the Functional ones, so we can probably assume that functional languages use less keywords, less typing even if using their OO syntax features; that's probably why there are lots of blog posts about the difference in amount of code between Scala and Java; of course they always compare Java's Imperative syntax vs Scala's Functional syntax, which is fare enough because Scala is meant to be used as a functional language. Right? So, in summary, using OO or Functional syntax, you will usually have smaller programs. Of course, that depends how you write code and if you use, let's say, match-case instead of if-then-else.&lt;br /&gt;
&lt;br /&gt;
So what happened to the Scripting languages? weren't they the ones with smaller keywords sets? and I'm not talking about Groovy because remember that Groovy needs to be Java syntax compatible, but Python and Ruby? &lt;br /&gt;
&lt;br /&gt;
Let's have a look:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Ruby 48&lt;/b&gt;&lt;br /&gt;
&lt;pre class="ruby" name="code"&gt;module 1
class 1
def 11 # this is understandable
end 17 # and here is where the most keyword go! 
if 1
return 2
else 2
for 1
in 1
while 1
do 1
case 1 # using the case construct also requires lots of keys because 
when 4 # it uses when and then for each case you want to validate against
then 4 #
&lt;/pre&gt;&lt;br /&gt;
&lt;b&gt;IronPython 50&lt;/b&gt;&lt;br /&gt;
&lt;pre class="python" name="code"&gt;import 2
from 1
class 1
def 12  # this is understandable
return 5
if 2
else 2
for 1
in 1
print 4  # print is a keyword but other languages use  
           # Console.WriteLine | System.out.println 
while 1
or 16 # and here is where the most keyword go because 
           # python has no switch | case | match syntax 
elif 2
&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
What else... oh yes. Verbosity of the language has nothing to do with its elegance or expressiveness (for instance Delphi Prism vs Scala|F#).&lt;br /&gt;
&lt;br /&gt;
Finally, counting keywords in your code is probably not relevant, because it will vary a lot between programs, styles, paradigms, if code was automatically generated, manually typed, and so on.&lt;br /&gt;
In my case I used the 2 edges to compare the "Minimal" and "Verbose", but in real coding a combination based on the above might be used. &lt;br /&gt;
&lt;br /&gt;
That's pretty much it. &lt;br /&gt;
&lt;br /&gt;
Here below I added the counting results for all the 21 languages in case you wonder which keywords &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;b&gt;Basics Minimal&lt;/b&gt;&lt;/td&gt;&lt;td&gt;&lt;b&gt;Basics Verbose&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;b&gt;Boo 68&lt;/b&gt;&lt;/td&gt;&lt;td&gt;&lt;b&gt;Boo 114&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt; &lt;td&gt;&lt;pre class="python" name="code"&gt;import 1
class 1
as 17
get 3
return 5
set 3
def 6
constructor 2
self 4
private 1
if 2
else 2
for 1
in 1
while 1
or 16
elif 2
&lt;/pre&gt;&lt;/td&gt; &lt;td&gt;&lt;pre class="python" name="code"&gt;namespace 1
import 1
private 5
class 1
as 24
public 9
get 3
return 5
self 28
set 3
def 7
constructor 2
if 2
else 2
for 1
in 1
while 1
or 16
elif 2
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;b&gt;Basics Minimal&lt;/b&gt;&lt;/td&gt;&lt;td&gt;&lt;b&gt;Basics Verbose&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;b&gt;Cobra 79&lt;/b&gt;&lt;/td&gt;&lt;td&gt;&lt;b&gt;Cobra 109&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt; &lt;td&gt;&lt;pre class="csharp" name="code"&gt;class 2
var 3
pro 3
as 12
get 3
return 5
set 3
cue 2
base 2
def 5
is 1
private 1
if 1
else 2
for 1
in 1
print 4
while 1
branch 1
on 4
or 20
any 1
to 1
&lt;/pre&gt;&lt;/td&gt; &lt;td&gt;&lt;pre class="csharp" name="code"&gt;use 1
namespace 1
class 2
is 12
public 10
var 3
as 18
pro 3
get 3
return 5
set 3
cue 2
base 2
def 5
private 1
if 1
else 2
for 1
in 1
print 4
while 1
branch 1
on 4
or 20
shared 1
any 1
to 1
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;b&gt;Basics Minimal&lt;/b&gt;&lt;/td&gt;&lt;td&gt;&lt;b&gt;Basics Verbose&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;b&gt;C++/CLI 59&lt;/b&gt;&lt;/td&gt;&lt;td&gt;&lt;b&gt;C++/CLI 101&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt; &lt;td&gt;&lt;pre class="cpp" name="code"&gt;using 1
namespace 1
class 1
public 2
property 3
return 5
void 6
this 3
private 1
if 1
else 1
for 1
while 1
switch 1
case 24
break 5
default 1
gcnew 1
&lt;/pre&gt;&lt;/td&gt; &lt;td&gt;&lt;pre class="cpp" name="code"&gt;using 1
namespace 2
private 5
class 1
public 14
property 3
return 6
this 27
void 6
if 1
else 1
for 1
while 1
switch 1
case 24
break 5
default 1
gcnew 1
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;b&gt;Basics Minimal&lt;/b&gt;&lt;/td&gt;&lt;td&gt;&lt;b&gt;Basics Verbose&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;b&gt;C# 69&lt;/b&gt;&lt;/td&gt;&lt;td&gt;&lt;b&gt;C# 103&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt; &lt;td&gt;&lt;pre class="csharp" name="code"&gt;using 1
class 2
public 8
get 3
return 5
set 3
value 3
this 3
if 1
else 1
void 4
for 1
while 1
switch 1
case 24
break 5
default 1
static 1
new 1
&lt;/pre&gt;&lt;/td&gt; &lt;td&gt;&lt;pre class="csharp" name="code"&gt;using 1
namespace 1
internal 2
class 2
private 4
public 9
get 3
return 5
this 29
set 3
value 3
if 1
else 1
void 4
for 1
while 1
switch 1
case 24
break 5
default 1
static 1
new 1
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;b&gt;Basics Minimal&lt;/b&gt;&lt;/td&gt;&lt;td&gt;&lt;b&gt;Basics Verbose&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;b&gt;DelphiPrism 94&lt;/b&gt;&lt;/td&gt;&lt;td&gt;&lt;b&gt;DelphiPrism 134&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt; &lt;td&gt;&lt;pre class="delphi" name="code"&gt;namespace 1
interface 1
uses 1
type 2
class 4
private 1
method 14
public 2
property 3
read 3
write 3
constructor 4
end 17
array 2
of 3
implementation 1
begin 13
if 1
then 1
result 2
else 2
for 1
to 2
step 1
do 2
var 3
while 1
case 1
new 1
exit 1
&lt;/pre&gt;&lt;/td&gt; &lt;td&gt;&lt;pre class="delphi" name="code"&gt;namespace 1
interface 1
uses 1
type 2
public 11
class 4
private 6
var 6
method 14
property 3
read 3
write 3
constructor 4
end 17
array 2
of 3
implementation 1
begin 13
self 23
if 1
then 1
result 2
else 2
for 1
to 2
step 1
do 2
while 1
case 1
new 1
exit 1
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;b&gt;Basics Minimal&lt;/b&gt;&lt;/td&gt;&lt;td&gt;&lt;b&gt;Basics Verbose&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;b&gt;Fantom 46&lt;/b&gt;&lt;/td&gt;&lt;td&gt;&lt;b&gt;Fantom 80&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt; &lt;td&gt;&lt;pre class="csharp" name="code"&gt;class 2
private 4
return 5
it 3
new 1
if 1
else 1
for 1
while 1
switch 1
case 24
default 1
static 1
&lt;/pre&gt;&lt;/td&gt; &lt;td&gt;&lt;pre class="csharp" name="code"&gt;internal 1
class 2
private 4
public 9
return 5
this 24
it 3
new 1
if 1
else 1
for 1
while 1
switch 1
case 24
default 1
static 1
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;b&gt;Basics Minimal&lt;/b&gt;&lt;/td&gt;&lt;td&gt;&lt;b&gt;Basics Verbose&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;b&gt;F# 42&lt;/b&gt;&lt;/td&gt;&lt;td&gt;&lt;b&gt;F# 54&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt; &lt;td&gt;&lt;pre class="csharp" name="code"&gt;open 1
type 1
let 9
mutable 4
member 7
with 4
and 3
new 2
private 1
if 1
then 1
else 1
for 1
to 2
do 2
while 1
match 1
&lt;/pre&gt;&lt;/td&gt; &lt;td&gt;&lt;pre class="csharp" name="code"&gt;namespace 1
open 1
type 1
public 8
class 1
let 9
mutable 4
member 7
with 4
and 3
new 2
private 1
if 1
then 1
else 1
for 1
to 2
do 2
while 1
match 1
end 1
module 1
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;b&gt;Basics Minimal&lt;/b&gt;&lt;/td&gt;&lt;td&gt;&lt;b&gt;Basics Verbose&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;b&gt;Gosu 72&lt;/b&gt;&lt;/td&gt;&lt;td&gt;&lt;b&gt;Gosu 114&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt; &lt;td&gt;&lt;pre class="java" name="code"&gt;uses 4
class 1
var 8
property 6
get 4
return 5
set 3
private 1
function 4
else 1
for 1
while 1
new 3
switch 1
case 24
break 4
default 1
&lt;/pre&gt;&lt;/td&gt; &lt;td&gt;&lt;pre class="java" name="code"&gt;uses 4
public 12
class 1
private 4
var 8
property 6
get 4
return 5
this 27
set 3
function 4
else 1
for 1
while 1
new 3
switch 1
case 24
break 4
default 1
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;b&gt;Basics Minimal&lt;/b&gt;&lt;/td&gt;&lt;td&gt;&lt;b&gt;Basics Verbose&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;b&gt;Groovy 72&lt;/b&gt;&lt;/td&gt;&lt;td&gt;&lt;b&gt;Groovy 101&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt; &lt;td&gt;&lt;pre class="groovy" name="code"&gt;class 1
private 4
def 20
return 5
this 3
if 1
else 1
for 1
in 2
while 1
new 3
switch 1
case 24
break 4
default 1
&lt;/pre&gt;&lt;/td&gt; &lt;td&gt;&lt;pre class="groovy" name="code"&gt;package 1
public 12
class 1
private 4
return 5
this 29
void 6
def 3
if 1
else 1
for 1
in 2
while 1
new 3
switch 1
case 24
break 5
default 1
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;b&gt;Basics Minimal&lt;/b&gt;&lt;/td&gt;&lt;td&gt;&lt;b&gt;Basics Verbose&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;b&gt;IronPython 48&lt;/b&gt;&lt;/td&gt;&lt;td&gt;&lt;b&gt;IronPython 50&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt; &lt;td&gt;&lt;pre class="python" name="code"&gt;from 1
import 1
class 1
def 11
return 5
if 2
else 2
for 1
in 1
print 4
while 1
or 16
elif 2
&lt;/pre&gt;&lt;/td&gt; &lt;td&gt;&lt;pre class="python" name="code"&gt;import 2
from 1
class 1
def 12
return 5
if 2
else 2
for 1
in 1
print 4
while 1
or 16
elif 2
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;b&gt;Basics Minimal&lt;/b&gt;&lt;/td&gt;&lt;td&gt;&lt;b&gt;Basics Verbose&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;b&gt;IronRuby 46&lt;/b&gt;&lt;/td&gt;&lt;td&gt;&lt;b&gt;IronRuby 48&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt; &lt;td&gt;&lt;pre class="ruby" name="code"&gt;class 1
def 11
end 16
if 1
return 2
else 2
for 1
in 1
while 1
do 1
case 1
when 4
then 4
&lt;/pre&gt;&lt;/td&gt; &lt;td&gt;&lt;pre class="ruby" name="code"&gt;module 1
class 1
def 11
end 17
if 1
return 2
else 2
for 1
in 1
while 1
do 1
case 1
when 4
then 4
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;b&gt;Basics Minimal&lt;/b&gt;&lt;/td&gt;&lt;td&gt;&lt;b&gt;Basics Verbose&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;b&gt;Java 65&lt;/b&gt;&lt;/td&gt;&lt;td&gt;&lt;b&gt;Java 103&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt; &lt;td&gt;&lt;pre class="java" name="code"&gt;package 2
import 2
class 2
private 4
return 5
void 7
this 3
if 1
else 1
for 1
while 1
switch 1
case 24
break 5
default 1
public 2
static 1
new 2
&lt;/pre&gt;&lt;/td&gt; &lt;td&gt;&lt;pre class="java" name="code"&gt;package 2
import 2
public 14
class 2
private 4
return 5
this 29
void 7
if 1
else 1
for 1
while 1
switch 1
case 24
break 5
default 1
static 1
new 2
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;b&gt;Basics Minimal&lt;/b&gt;&lt;/td&gt;&lt;td&gt;&lt;b&gt;Basics Verbose&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;b&gt;JavaFX 64&lt;/b&gt;&lt;/td&gt;&lt;td&gt;&lt;b&gt;JavaFX 105&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt; &lt;td&gt;&lt;pre class="java" name="code"&gt;import 4
class 1
var 6
function 11
return 5
init 1
if 5
else 5
for 1
in 2
while 1
def 1
new 1
or 20
&lt;/pre&gt;&lt;/td&gt; &lt;td&gt;&lt;pre class="java" name="code"&gt;package 1
import 4
public 11
class 1
var 6
function 11
return 5
this 29
init 1
if 5
else 5
for 1
in 2
while 1
def 1
new 1
or 20
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;b&gt;Basics Minimal&lt;/b&gt;&lt;/td&gt;&lt;td&gt;&lt;b&gt;Basics Verbose&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;b&gt;JRuby 46&lt;/b&gt;&lt;/td&gt;&lt;td&gt;&lt;b&gt;JRuby 48&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt; &lt;td&gt;&lt;pre class="ruby" name="code"&gt;class 1
def 11
end 16
if 1
return 2
else 2
for 1
in 1
while 1
do 1
case 1
when 4
then 4
&lt;/pre&gt;&lt;/td&gt; &lt;td&gt;&lt;pre class="ruby" name="code"&gt;module 1
class 1
def 11
end 17
if 1
return 2
else 2
for 1
in 1
while 1
do 1
case 1
when 4
then 4
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;b&gt;Basics Minimal&lt;/b&gt;&lt;/td&gt;&lt;td&gt;&lt;b&gt;Basics Verbose&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;b&gt;JScript.NET 72&lt;/b&gt;&lt;/td&gt;&lt;td&gt;&lt;b&gt;JScript.NET 118&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt; &lt;td&gt;&lt;pre class="javascript" name="code"&gt;import 1
class 1
var 7
function 12
get 3
return 5
set 3
this 3
private 1
if 1
else 1
for 1
while 1
switch 1
case 24
break 5
default 1
new 1
&lt;/pre&gt;&lt;/td&gt; &lt;td&gt;&lt;pre class="javascript" name="code"&gt;import 1
package 1
public 12
class 1
private 4
var 7
function 13
get 3
return 5
this 29
set 3
if 1
else 1
void 3
for 1
while 1
switch 1
case 24
break 5
default 1
new 1
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;b&gt;Basics Minimal&lt;/b&gt;&lt;/td&gt;&lt;td&gt;&lt;b&gt;Basics Verbose&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;b&gt;Jython 51&lt;/b&gt;&lt;/td&gt;&lt;td&gt;&lt;b&gt;Jython 53&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt; &lt;td&gt;&lt;pre class="python" name="code"&gt;from 2
import 2
class 1
def 11
return 5
if 2
else 2
for 1
in 2
print 4
while 1
or 16
elif 2
&lt;/pre&gt;&lt;/td&gt; &lt;td&gt;&lt;pre class="python" name="code"&gt;import 3
from 2
class 1
def 12
return 5
if 2
else 2
for 1
in 2
print 4
while 1
or 16
elif 2
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;b&gt;Basics Minimal&lt;/b&gt;&lt;/td&gt;&lt;td&gt;&lt;b&gt;Basics Verbose&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;b&gt;Nemerle 33&lt;/b&gt;&lt;/td&gt;&lt;td&gt;&lt;b&gt;Nemerle 67&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt; &lt;td&gt;&lt;pre class="csharp" name="code"&gt;using 1
class 1
mutable 5
public 8
this 5
private 1
if 1
else 1
void 3
for 1
while 1
def 2
match 1
_ 2
&lt;/pre&gt;&lt;/td&gt; &lt;td&gt;&lt;pre class="csharp" name="code"&gt;using 1
namespace 1
internal 1
class 1
private 4
mutable 6
public 10
this 29
if 1
else 1
void 4
for 1
while 1
def 1
match 1
_ 2
module 1
static 1
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;b&gt;Basics Minimal&lt;/b&gt;&lt;/td&gt;&lt;td&gt;&lt;b&gt;Basics Verbose&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;b&gt;Phalanger 89&lt;/b&gt;&lt;/td&gt;&lt;td&gt;&lt;b&gt;Phalanger 103&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt; &lt;td&gt;&lt;pre class="php" name="code"&gt;namespace 1
class 2
private 4
function 12
return 5
this 24
if 1
else 1
for 1
echo 4
while 1
switch 1
case 24
break 4
default 1
static 1
new 1
exit 1
&lt;/pre&gt;&lt;/td&gt; &lt;td&gt;&lt;pre class="php" name="code"&gt;namespace 2
class 2
private 4
public 11
function 12
return 6
this 24
if 1
else 1
for 1
echo 4
while 1
switch 1
case 24
break 5
default 1
static 1
new 1
exit 1
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;b&gt;Basics Minimal&lt;/b&gt;&lt;/td&gt;&lt;td&gt;&lt;b&gt;Basics Verbose&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;b&gt;Scala 37&lt;/b&gt;&lt;/td&gt;&lt;td&gt;&lt;b&gt;Scala 41&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt; &lt;td&gt;&lt;pre class="scala" name="code"&gt;import 1
class 1
private 4
var 4
def 12
this 2
if 1
else 1
for 1
while 1
val 2
match 1
case 5
new 1
&lt;/pre&gt;&lt;/td&gt; &lt;td&gt;&lt;pre class="scala" name="code"&gt;package 1
import 2
class 1
private 4
var 4
def 13
this 2
if 1
else 1
for 1
while 1
val 2
match 1
case 5
object 1
new 1
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;b&gt;Basics Minimal&lt;/b&gt;&lt;/td&gt;&lt;td&gt;&lt;b&gt;Basics Verbose&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;b&gt;VB.NET 130&lt;/b&gt;&lt;/td&gt;&lt;td&gt;&lt;b&gt;VB.NET 169&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt; &lt;td&gt;&lt;pre class="scala" name="code"&gt;Imports 1
Friend 2
Class 2
Private 4
As 22
Property 6
Get 6
Return 5
End 21
Set 6
ByVal 11
Sub 12
New 3
Function 2
If 2
Then 1
Else 2
For 1
To 5
Next 1
Dim 3
While 2
Select 2
Case 6
Module 2
&lt;/pre&gt;&lt;/td&gt; &lt;td&gt;&lt;pre class="scala" name="code"&gt;Imports 1
Namespace 2
Friend 2
Class 2
Private 4
As 22
Public 9
Property 6
Get 6
Return 5
Me 27
End 22
Set 6
ByVal 11
Sub 12
New 3
Function 2
If 2
Then 1
Else 2
For 1
To 5
Next 1
Dim 3
While 2
Select 2
Case 6
Module 2
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;b&gt;Basics Minimal&lt;/b&gt;&lt;/td&gt;&lt;td&gt;&lt;b&gt;Basics Verbose&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;b&gt;Zonnon 66&lt;/b&gt;&lt;/td&gt;&lt;td&gt;&lt;b&gt;Zonnon 90&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt; &lt;td&gt;&lt;pre class="delphi" name="code"&gt;module 1
import 1
type 1
object 1
var 5
procedure 10
begin 12
return 5
end 16
if 1
then 1
else 2
for 1
to 2
do 2
while 1
case 1
of 1
new 1
exit 1
&lt;/pre&gt;&lt;/td&gt; &lt;td&gt;&lt;pre class="delphi" name="code"&gt;module 1
import 1
type 1
object 1
var 5
procedure 10
begin 12
return 5
self 24
end 16
if 1
then 1
else 2
for 1
to 2
do 2
while 1
case 1
of 1
new 1
exit 1
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/694679611587040520-8243043866663186801?l=carlosqt.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/AQ5QWSYpNm50pTlEiw6CylJBMc8/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/AQ5QWSYpNm50pTlEiw6CylJBMc8/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/AQ5QWSYpNm50pTlEiw6CylJBMc8/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/AQ5QWSYpNm50pTlEiw6CylJBMc8/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/CarlosQuintanillasBlog/~4/dpGLPBASGSg" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://carlosqt.blogspot.com/feeds/8243043866663186801/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://carlosqt.blogspot.com/2011/01/how-many-keywords-in-your-source-code.html#comment-form" title="2 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/694679611587040520/posts/default/8243043866663186801?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/694679611587040520/posts/default/8243043866663186801?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/CarlosQuintanillasBlog/~3/dpGLPBASGSg/how-many-keywords-in-your-source-code.html" title="How many keywords in your source code? Round 2" /><author><name>Carlos QT</name><uri>http://www.blogger.com/profile/15415604076909500411</uri><email>carlosqt@gmail.com</email><gd:extendedProperty name="OpenSocialUserId" value="14144067369073378952" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/_0_HCzHGe4_k/TS-BnG7UN_I/AAAAAAAAFzg/qo52lMRNQiU/s72-c/Copy+of+image009.png" height="72" width="72" /><thr:total>2</thr:total><feedburner:origLink>http://carlosqt.blogspot.com/2011/01/how-many-keywords-in-your-source-code.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D0AASX05eip7ImA9Wx9RF0o.&quot;"><id>tag:blogger.com,1999:blog-694679611587040520.post-4778982320443567838</id><published>2010-12-09T05:18:00.000-08:00</published><updated>2010-12-19T08:22:28.322-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-12-19T08:22:28.322-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="News" /><title>What a horrible night to have a curse.</title><content type="html">Let's &lt;span style="color: blue;"&gt;throw new&lt;/span&gt; Exception();&lt;b&gt; &lt;/b&gt;and instead of talking about programming languages or sharing some code, let me just write about some mixed stuff, and the blog's status.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;No new posts in almost a month!?&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Right... and the reason is that I'm back to WOW! haha... nah, I'm kidding, but I'm seriously thinking about it because of the new expansion Cataclysm! I ever wanted to be a Goblin Warrior! ooohhh yeah!&lt;br /&gt;
&lt;div align="center"&gt;&lt;span style="color: red;"&gt;&lt;b&gt;FOR THE HORDE!!!!!!&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/_0_HCzHGe4_k/TQDL1LIQVGI/AAAAAAAAFzE/kn4iFuhFbOw/s1600/for_the_horde.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://4.bp.blogspot.com/_0_HCzHGe4_k/TQDL1LIQVGI/AAAAAAAAFzE/kn4iFuhFbOw/s1600/for_the_horde.gif" /&gt;&lt;/a&gt;&lt;/div&gt;Anyway, it would be a little bit difficult because I have no Internet in our new apartment; the provider didn't active it even if I followed all they said to have it ready before moving, which bring us to the real reason of why there haven't been any new posts lately.&lt;br /&gt;
&lt;br /&gt;
I have been very busy for the last few weeks because I was moving apartment and I must admit that I totally underestimated the physical, psychological and time effort the whole thing required! The night before the move we had a long night finishing all remaining packaging, wraps, baggages and then I came with this "What a horrible night to have a curse." text from "Castlevania II Simon's Quest" which made me laugh about the situation... so, I wanted to share it with anyone in case you also have good (or bad) memories about it:&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/_0_HCzHGe4_k/TP4W3_AReEI/AAAAAAAAFy8/3LEh2NuesGc/s1600/castlevania_night.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="376" src="http://2.bp.blogspot.com/_0_HCzHGe4_k/TP4W3_AReEI/AAAAAAAAFy8/3LEh2NuesGc/s400/castlevania_night.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;b&gt;What has been active?&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
I always keep an eye on the latest releases on several .NET and Java Programming Languages. If there are new releases in any of the languages listed in the &lt;a href="http://carlosqt.blogspot.com/p/programming-languages.html"&gt;Blog's Languages Page&lt;/a&gt; I tweet about them:&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/_0_HCzHGe4_k/TQDJKBgLt8I/AAAAAAAAFzA/IGEBUoGxNW0/s1600/twitter_caslosqt.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="640" src="http://2.bp.blogspot.com/_0_HCzHGe4_k/TQDJKBgLt8I/AAAAAAAAFzA/IGEBUoGxNW0/s640/twitter_caslosqt.png" width="465" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
I also include some tweets about new releases of Programming IDEs such as Netbeans, Eclipse, IntelliJIDEA, VisualStudio and SharpDevelop, plus other interesting techy retweets.&amp;nbsp;&lt;a href="http://www.twitter.com/carlosqt"&gt;&lt;img alt="Follow carlosqt on Twitter" src="http://twitter-badges.s3.amazonaws.com/t_logo-a.png" /&gt;&lt;/a&gt; me :)&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;What to expect on the following posts&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
1. How many keywords to code the same PART 2! oh yes... based on the examples shown in the Basics by Example series, I will do again some counting and come back with the graphs showing if what we saw on the previous comparison keeps the same.&lt;br /&gt;
&lt;br /&gt;
2. More about Language's features. I will keep showing simple language constructs and stuff and not getting into specifics or advance material so I can keep tracking keywords and lines metrics for the same set of functionality.&lt;br /&gt;
&lt;br /&gt;
3. Keep updating this Blog's Pages (Languages, Keywords, eBooks). I'm still thinking in what to add on the IDE's section... for them moment I will just list the available IDEs and what languages each of them support in the base installation or via plug in.&lt;br /&gt;
&lt;br /&gt;
4. Include implementation of basic Algorithms, useful code snippets, and so on in all languages.&lt;br /&gt;
&lt;br /&gt;
5. Adding a new Page to show how to Install and Run the code examples on this blog on each of the ~20 languages. I usually do the examples using Notepad++ and then compile them using the command line so I can get the Output screen shot. The installation is usually Next Next but I want to include as well the process to install from scratch and install a new version (because sometimes a new release crashes the IDE or requires uninstalling first)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/694679611587040520-4778982320443567838?l=carlosqt.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/yemQmw1tSbyRasXF5SjCOrR9MNw/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/yemQmw1tSbyRasXF5SjCOrR9MNw/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/yemQmw1tSbyRasXF5SjCOrR9MNw/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/yemQmw1tSbyRasXF5SjCOrR9MNw/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/CarlosQuintanillasBlog/~4/edNevIXInRs" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://carlosqt.blogspot.com/feeds/4778982320443567838/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://carlosqt.blogspot.com/2010/12/what-horrible-night-to-have-curse.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/694679611587040520/posts/default/4778982320443567838?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/694679611587040520/posts/default/4778982320443567838?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/CarlosQuintanillasBlog/~3/edNevIXInRs/what-horrible-night-to-have-curse.html" title="What a horrible night to have a curse." /><author><name>Carlos QT</name><uri>http://www.blogger.com/profile/15415604076909500411</uri><email>carlosqt@gmail.com</email><gd:extendedProperty name="OpenSocialUserId" value="14144067369073378952" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://4.bp.blogspot.com/_0_HCzHGe4_k/TQDL1LIQVGI/AAAAAAAAFzE/kn4iFuhFbOw/s72-c/for_the_horde.gif" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://carlosqt.blogspot.com/2010/12/what-horrible-night-to-have-curse.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CUUGRX87eyp7ImA9Wx9TFkU.&quot;"><id>tag:blogger.com,1999:blog-694679611587040520.post-8976199915569017850</id><published>2010-11-13T12:02:00.000-08:00</published><updated>2010-11-25T03:07:04.103-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-11-25T03:07:04.103-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="JVM" /><category scheme="http://www.blogger.com/atom/ns#" term="Gosu" /><title>Gosu - Basics by Example</title><content type="html">&lt;a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" data-via="carlosqt"&gt;Tweet&lt;/a&gt;&lt;script type="text/javascript" src="http://platform.twitter.com/widgets.js"&gt;&lt;/script&gt;&lt;br /&gt;
&lt;br /&gt;
Extending my Basics by Example series to a new language :D. today's version of the post written in &lt;b&gt;Gosu&lt;/b&gt; Enjoy!&lt;br /&gt;
&lt;br /&gt;
You can copy and paste the code below in your favorite IDE/Editor and start playing and learning with it. This little "working" program will teach you the basics of the Programming Language.&lt;br /&gt;
&lt;br /&gt;
There are some "comments" on the code added just to tell you what are or how are some features called. In case you want to review the theory, you can read my previous post, where I give a definition of each of the concepts mentioned on the code. You can find it here: &lt;a href="http://carlosqt.blogspot.com/2010/08/new-series-languages-basics-by-example.html"&gt;http://carlosqt.blogspot.com/2010/08/new-series-languages-basics-by-example.html&lt;/a&gt;&amp;nbsp;&lt;a href="http://carlosqt.blogspot.com/2010/08/new-series-languages-basics-by-example.html"&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Greetings Program - Verbose&lt;/b&gt;&lt;br /&gt;
&lt;pre class="java" name="code"&gt;// Gosu Basics
classpath "."
//package gsgreetprogram
uses java.util.Calendar
uses java.util.GregorianCalendar
uses java.util.Scanner
uses java.lang.System

public class Greet {
    // Fields or Attributes
    private var _message: String
    private var _name: String
    private var _loopMessage: int
    // Properties
    public property get Message(): String {
        return this._message
    }
    public property set Message(value: String) {
        this._message = this.capitalize(value)
    }
    public property get Name(): String {
        return this._name 
    }
    public property set Name(value: String) {
        this._name = this.capitalize(value)
    }
    public property get LoopMessage(): int {
        return this._loopMessage
    }
    public property set LoopMessage(value: int) {
        this._loopMessage = value
    }
    // Constructor
    public construct() {
        this._message = ""
        this._name = ""
        this._loopMessage = 0
    }
    // Overloaded Constructor
    public construct(pmessage: String, pname: String, ploopMessage: int) {
        this._message = pmessage
        this._name = pname
        this._loopMessage = ploopMessage
    }
    // Method 1
    private function capitalize(val: String): String {
        // "if-then-else" statement
        if(val.length &amp;gt;= 1) {
            return val.capitalize()
        }
        else {
            return ""
        }
    }
    // Method 2
    public function salute() {
        // "for" statement        
        for (i in 0..this._loopMessage) {
            print("${this._message} ${this._name}!")
        }
    }
    // Overloaded Method 2.1
    public function salute(pmessage: String, pname: String, ploopMessage: int) {
        // "while" statement
        var i: int = 0
        while (i &amp;lt; ploopMessage) {
            print("${this.capitalize(pmessage)} ${this.capitalize(pname)}!")
            i = i + 1
        }
    }
    // Overloaded Method 2.2    
 public function salute(pname: String) {    
  // "switch/case" statement    
  var dtNow = new GregorianCalendar()
  switch (dtNow.get(Calendar.HOUR_OF_DAY))
  {    
   case 6: case 7: case 8: case 9: case 10: case 11:    
    this._message = "good morning,"
    break
   case 12: case 13: case 14: case 15: case 16: case 17:    
    this._message = "good afternoon,"
    break
   case 18: case 19: case 20: case 21: case 22:    
    this._message = "good evening,"
    break
   case 23: case 0: case 1: case 2: case 3: case 4: case 5:    
    this._message = "good night,"
    break
   default:    
    this._message = "huh?"
  }    
  print("${this.capitalize(this._message)} ${this.capitalize(pname)}!")
 }    
}

// Console Program
// Define variable object of type Greet and Instantiate. Call Constructor        
var g = new Greet()
// Call Set Properties        
g.Message = "hello"            
g.Name = "world"            
g.LoopMessage = 5
// Call Method 2            
g.salute()        
// Call Method 2.1 and Get Properties            
g.salute(g.Message, "gosu", g.LoopMessage)        
// Call Method 2.2            
g.salute("carlos")            
// Stop and exit            
print("Press any key to exit...")
var sin = new Scanner(System.in)
var line = sin.nextLine()
sin.close()
&lt;/pre&gt;&lt;br /&gt;
&lt;b&gt;Greetings Program - Minimal&lt;/b&gt;&lt;br /&gt;
&lt;pre class="java" name="code"&gt;// Gosu Basics
classpath "."
uses java.util.Calendar
uses java.util.GregorianCalendar
uses java.util.Scanner
uses java.lang.System

class Greet {
    // Fields or Attributes
    var _message: String
    var _name: String
    var _loopMessage: int
    // Properties
    property get Message(): String {
        return _message
    }
    property set Message(value: String) {
        _message = capitalize(value)
    }
    property get Name(): String {
        return _name 
    }
    property set Name(value: String) {
        _name = capitalize(value)
    }
    property get LoopMessage(): int {
        return _loopMessage
    }
    property set LoopMessage(value: int) {
        _loopMessage = value
    }
    // Constructor
    construct() {
        _message = ""
        _name = ""
        _loopMessage = 0
    }
    // Overloaded Constructor
    construct(pmessage: String, pname: String, ploopMessage: int) {
        _message = pmessage
        _name = pname
        _loopMessage = ploopMessage
    }
    // Method 1
    private function capitalize(val: String): String {
        // "if-then-else" statement
        if(val.length &amp;gt;= 1) {
            return val.capitalize()
        }
        else {
            return ""
        }
    }
    // Method 2
    function salute() {
        // "for" statement        
        for (i in 0.._loopMessage) {
            print("${_message} ${_name}!")
        }
    }
    // Overloaded Method 2.1
    function salute(pmessage: String, pname: String, ploopMessage: int) {
        // "while" statement
        var i = 0
        while (i &amp;lt; ploopMessage) {
            print("${capitalize(pmessage)} ${capitalize(pname)}!")
            i = i + 1
        }
    }
    // Overloaded Method 2.2    
    function salute(pname: String) {
        // "switch/case" statement    
        var dtNow = new GregorianCalendar()
        switch (dtNow.get(Calendar.HOUR_OF_DAY))
        {    
            case 6: case 7: case 8: case 9: case 10: case 11:    
                _message = "good morning,"
                break
            case 12: case 13: case 14: case 15: case 16: case 17:
                _message = "good afternoon,"
                break
            case 18: case 19: case 20: case 21: case 22:    
                _message = "good evening,"
                break
            case 23: case 0: case 1: case 2: case 3: case 4: case 5:    
                _message = "good night,"
                break    
            default:    
                _message = "huh?"
        }    
        print("${capitalize(_message)} ${capitalize(pname)}!")
    }    
}

// Console Program
// Define variable object of type Greet and Instantiate. Call Constructor        
var g = new Greet()
// Call Set Properties        
g.Message = "hello"            
g.Name = "world"            
g.LoopMessage = 5
// Call Method 2            
g.salute()        
// Call Method 2.1 and Get Properties            
g.salute(g.Message, "gosu", g.LoopMessage)        
// Call Method 2.2            
g.salute("carlos")            
// Stop and exit            
print("Press any key to exit...")
var sin = new Scanner(System.in)
var line = sin.nextLine()
sin.close()
&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
And the Output is: &lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/_0_HCzHGe4_k/TN7ltBDZ4oI/AAAAAAAAFyc/5d0RI15mkto/s1600/gosu_oohello.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="322" src="http://1.bp.blogspot.com/_0_HCzHGe4_k/TN7ltBDZ4oI/AAAAAAAAFyc/5d0RI15mkto/s640/gosu_oohello.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Auto-Implemented Properties in Gosu&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Auto-implemented properties enable you to quickly specify a property of a class without having to write code to Get and Set the property. The following code shows how to use them just like with VB.NET, C#, C++/CLI and so on.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="java" name="code"&gt;// Gosu Basics
class AutoImplementedProperties {
    // Fields + Auto-Implemented Properties
    var _message: String as Message
    var _name: String as Name
    var _loopMessage: int as LoopMessage
    // Methods
    function salute() {
        print("${_message.capitalize()} ${_name.capitalize()} ${_loopMessage}!")
    }
}

var g = new AutoImplementedProperties()
// Call Set Properties
g.Message = "hello"
g.Name = "world"
g.LoopMessage = 5
// print them out
g.salute()
// and print them again using Get Properties
print(g.Message + " " + g.Name + " " + g.LoopMessage + "!")
&lt;/pre&gt;&lt;br /&gt;
And the output is:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/_0_HCzHGe4_k/TN7u1R31yPI/AAAAAAAAFyg/ObZ48Q-fDYY/s1600/gosu_oohello_props.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://3.bp.blogspot.com/_0_HCzHGe4_k/TN7u1R31yPI/AAAAAAAAFyg/ObZ48Q-fDYY/s1600/gosu_oohello_props.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/694679611587040520-8976199915569017850?l=carlosqt.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/mCTbOz3xaFuyD7YHL004C1K0qtk/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/mCTbOz3xaFuyD7YHL004C1K0qtk/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/mCTbOz3xaFuyD7YHL004C1K0qtk/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/mCTbOz3xaFuyD7YHL004C1K0qtk/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/CarlosQuintanillasBlog/~4/qYUDliCDYjQ" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://carlosqt.blogspot.com/feeds/8976199915569017850/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://carlosqt.blogspot.com/2010/11/gosu-basics-by-example.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/694679611587040520/posts/default/8976199915569017850?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/694679611587040520/posts/default/8976199915569017850?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/CarlosQuintanillasBlog/~3/qYUDliCDYjQ/gosu-basics-by-example.html" title="Gosu - Basics by Example" /><author><name>Carlos QT</name><uri>http://www.blogger.com/profile/15415604076909500411</uri><email>carlosqt@gmail.com</email><gd:extendedProperty name="OpenSocialUserId" value="14144067369073378952" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/_0_HCzHGe4_k/TN7ltBDZ4oI/AAAAAAAAFyc/5d0RI15mkto/s72-c/gosu_oohello.png" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://carlosqt.blogspot.com/2010/11/gosu-basics-by-example.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CUUDRng5fCp7ImA9Wx9TFkU.&quot;"><id>tag:blogger.com,1999:blog-694679611587040520.post-9211500439939466781</id><published>2010-11-12T14:48:00.000-08:00</published><updated>2010-11-25T03:07:57.624-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-11-25T03:07:57.624-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="HelloWorld" /><category scheme="http://www.blogger.com/atom/ns#" term="JVM" /><category scheme="http://www.blogger.com/atom/ns#" term="Gosu" /><title>OO Hello World - Gosu</title><content type="html">&lt;a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" data-via="carlosqt"&gt;Tweet&lt;/a&gt;&lt;script type="text/javascript" src="http://platform.twitter.com/widgets.js"&gt;&lt;/script&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;&lt;span style="color: #333333; font-family: &amp;quot;&amp;quot;, serif, &amp;quot;&amp;quot;, &amp;quot;serif&amp;quot;; font-size: 12pt;"&gt;The Hello World version of the program in Gosu! &lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;&lt;span style="color: #333333; font-family: &amp;quot;&amp;quot;, serif, &amp;quot;&amp;quot;, &amp;quot;serif&amp;quot;; font-size: 12pt;"&gt;A new OO programming language targeting the JVM with a Java-like syntax and compatible with java code. This looks like a promising language that deserves to be in the list of the ~20 languages I'm writing on here.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #333333; font-family: &amp;quot;&amp;quot;, serif, &amp;quot;&amp;quot;, &amp;quot;serif&amp;quot;; font-size: 12pt;"&gt;So, let's see how it looks like and how it compares to the other langs in a minimal OO program :D&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
By the way, you can see my previous post here: &lt;a href="http://carlosqt.blogspot.com/2010/06/oo-hello-world.html"&gt;http://carlosqt.blogspot.com/2010/06/oo-hello-world.html&lt;/a&gt;&lt;br /&gt;
where I give some details on WHY these "OO Hello World series" samples.&lt;span style="color: #333333; font-family: &amp;quot;&amp;quot;, serif, &amp;quot;&amp;quot;, &amp;quot;serif&amp;quot;; font-size: 12pt;"&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #333333; font-family: &amp;quot;&amp;quot;, serif, &amp;quot;&amp;quot;, &amp;quot;serif&amp;quot;; font-size: 12pt;"&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;&lt;b&gt;&lt;span style="color: #333333; font-family: &amp;quot;&amp;quot;, serif, &amp;quot;&amp;quot;, &amp;quot;serif&amp;quot;; font-size: 12pt;"&gt;Version 1 (Minimal):&lt;/span&gt;&lt;/b&gt;&lt;span style="color: #333333; font-family: &amp;quot;&amp;quot;, serif, &amp;quot;&amp;quot;, &amp;quot;serif&amp;quot;; font-size: 12pt;"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;&lt;span style="color: #333333; font-family: &amp;quot;&amp;quot;, serif, &amp;quot;&amp;quot;, &amp;quot;serif&amp;quot;; font-size: 12pt;"&gt;The minimum you need to type to get your program compiled and running.&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;pre class="java" name="code"&gt;class Greet {
    var _name: String
    construct(name: String) {
        _name = name.capitalize()  
    }
    function salute() {
        print("Hello ${_name}!")
    }
}

// Greet Program
var g = new Greet("world")
g.salute()
&lt;/pre&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;&lt;b&gt;&lt;span style="color: #333333; font-family: &amp;quot;&amp;quot;, serif, &amp;quot;&amp;quot;, &amp;quot;serif&amp;quot;; font-size: 12pt;"&gt;Version 2 (Verbose):&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;&lt;span style="color: #333333; font-family: &amp;quot;&amp;quot;, serif, &amp;quot;&amp;quot;, &amp;quot;serif&amp;quot;; font-size: 12pt;"&gt;Explicitly adding instructions and keywords that are optional to the compiler.&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;&lt;b&gt;&lt;span style="color: #333333; font-family: &amp;quot;&amp;quot;, serif, &amp;quot;&amp;quot;, &amp;quot;serif&amp;quot;; font-size: 12pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;pre class="java" name="code"&gt;//classpath "."
//package greetprogram
uses java.util.*

public class Greet {
    private var _name: String
    public construct(name: String) {
        this._name = name.capitalize()  
    }
    public function salute() {
        print("Hello ${this._name}!")
    }
}

// Greet Program
var g = new Greet("world")
g.salute()
&lt;/pre&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;&lt;b&gt;&lt;span style="color: #333333; font-family: &amp;quot;&amp;quot;, serif, &amp;quot;&amp;quot;, &amp;quot;serif&amp;quot;; font-size: 12pt;"&gt;The Program Output:&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/_0_HCzHGe4_k/TN3GsGsvfuI/AAAAAAAAFyY/ZdcArZQJOLA/s1600/gosu_oohello_ver.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://4.bp.blogspot.com/_0_HCzHGe4_k/TN3GsGsvfuI/AAAAAAAAFyY/ZdcArZQJOLA/s1600/gosu_oohello_ver.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;&lt;b style="mso-bidi-font-weight: normal;"&gt;&lt;span style="color: #333333; font-family: &amp;quot;&amp;quot;, serif, &amp;quot;&amp;quot;, &amp;quot;serif&amp;quot;; font-size: 12pt;"&gt;Gosu Info:&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;“Gosu is an imperative statically-typed object-oriented programming language that is designed to be expressive, easy-to-read, and reasonably fast. Gosu supports several resource types” Taken from: (&lt;a href="http://gosu-lang.org/intro.shtml"&gt;http://gosu-lang.org/intro.shtml&lt;/a&gt;)&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;table border="1" cellpadding="0" cellspacing="0" class="MsoNormalTable" style="border-collapse: collapse; border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-yfti-tbllook: 1184;"&gt;&lt;tbody&gt;
&lt;tr style="mso-yfti-firstrow: yes; mso-yfti-irow: 0;"&gt;   &lt;td style="border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;" valign="top" width="227"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;&lt;span style="color: #333333; font-family: &amp;quot;&amp;quot;, serif, &amp;quot;&amp;quot;, &amp;quot;serif&amp;quot;; font-size: 12pt;"&gt;Appeared:&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;   &lt;td style="border-left: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;" valign="top" width="468"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;&lt;span style="color: #333333; font-family: &amp;quot;&amp;quot;, serif, &amp;quot;&amp;quot;, &amp;quot;serif&amp;quot;; font-size: 12pt;"&gt;2010&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style="mso-yfti-irow: 1;"&gt;   &lt;td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;" valign="top" width="227"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;&lt;span style="color: #333333; font-family: &amp;quot;&amp;quot;, serif, &amp;quot;&amp;quot;, &amp;quot;serif&amp;quot;; font-size: 12pt;"&gt;Current Version:&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;   &lt;td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;" valign="top" width="468"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;&lt;span style="color: #333333; font-family: &amp;quot;&amp;quot;, serif, &amp;quot;&amp;quot;, &amp;quot;serif&amp;quot;; font-size: 12pt;"&gt;0.7.0&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: &amp;quot;Times New Roman&amp;quot;, &amp;quot;serif&amp;quot;; font-size: 12pt;"&gt; (&lt;a href="http://carlosqt.blogspot.com/p/programming-languages.html"&gt;latest version in "Languages" page&lt;/a&gt;)&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style="mso-yfti-irow: 2;"&gt;   &lt;td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;" valign="top" width="227"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;&lt;span style="color: #333333; font-family: &amp;quot;&amp;quot;, serif, &amp;quot;&amp;quot;, &amp;quot;serif&amp;quot;; font-size: 12pt;"&gt;Developed by:&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;   &lt;td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;" valign="top" width="468"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;&lt;span style="color: #333333; font-family: &amp;quot;&amp;quot;, serif, &amp;quot;&amp;quot;, &amp;quot;serif&amp;quot;; font-size: 12pt;"&gt;Guidewire Software&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style="mso-yfti-irow: 3;"&gt;   &lt;td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;" valign="top" width="227"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;&lt;span style="color: #333333; font-family: &amp;quot;&amp;quot;, serif, &amp;quot;&amp;quot;, &amp;quot;serif&amp;quot;; font-size: 12pt;"&gt;Creator:&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;   &lt;td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;" valign="top" width="468"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;&lt;span style="color: #333333; font-family: &amp;quot;&amp;quot;, serif, &amp;quot;&amp;quot;, &amp;quot;serif&amp;quot;; font-size: 12pt;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style="mso-yfti-irow: 4;"&gt;   &lt;td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;" valign="top" width="227"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;&lt;span style="color: #333333; font-family: &amp;quot;&amp;quot;, serif, &amp;quot;&amp;quot;, &amp;quot;serif&amp;quot;; font-size: 12pt;"&gt;Influenced by:&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;   &lt;td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;" valign="top" width="468"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;&lt;span style="color: #333333; font-family: &amp;quot;&amp;quot;, serif, &amp;quot;&amp;quot;, &amp;quot;serif&amp;quot;; font-size: 12pt;"&gt;Java (&lt;/span&gt;&lt;span style="color: #333333; font-family: &amp;quot;&amp;quot;, serif, &amp;quot;&amp;quot;, &amp;quot;serif&amp;quot;; font-size: 12pt;"&gt;James Gosling&lt;/span&gt;&lt;span style="color: #333333; font-family: &amp;quot;&amp;quot;, serif, &amp;quot;&amp;quot;, &amp;quot;serif&amp;quot;; font-size: 12pt;"&gt;)&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style="mso-yfti-irow: 5;"&gt;   &lt;td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;" valign="top" width="227"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;&lt;span style="color: #333333; font-family: &amp;quot;&amp;quot;, serif, &amp;quot;&amp;quot;, &amp;quot;serif&amp;quot;; font-size: 12pt;"&gt;Predecessor Language&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;   &lt;td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;" valign="top" width="468"&gt;&lt;br /&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style="mso-yfti-irow: 6;"&gt;   &lt;td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;" valign="top" width="227"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;&lt;span style="color: #333333; font-family: &amp;quot;&amp;quot;, serif, &amp;quot;&amp;quot;, &amp;quot;serif&amp;quot;; font-size: 12pt;"&gt;Predecessor Appeared&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;   &lt;td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;" valign="top" width="468"&gt;&lt;br /&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style="mso-yfti-irow: 7;"&gt;   &lt;td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;" valign="top" width="227"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;&lt;span style="color: #333333; font-family: &amp;quot;&amp;quot;, serif, &amp;quot;&amp;quot;, &amp;quot;serif&amp;quot;; font-size: 12pt;"&gt;Predecessor Creator&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;   &lt;td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;" valign="top" width="468"&gt;&lt;br /&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style="mso-yfti-irow: 8;"&gt;   &lt;td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;" valign="top" width="227"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;&lt;span style="color: #333333; font-family: &amp;quot;&amp;quot;, serif, &amp;quot;&amp;quot;, &amp;quot;serif&amp;quot;; font-size: 12pt;"&gt;Runtime Target:&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;   &lt;td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;" valign="top" width="468"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;&lt;span style="color: #333333; font-family: &amp;quot;&amp;quot;, serif, &amp;quot;&amp;quot;, &amp;quot;serif&amp;quot;; font-size: 12pt;"&gt;JVM&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style="mso-yfti-irow: 9;"&gt;   &lt;td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;" valign="top" width="227"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;&lt;span style="color: #333333; font-family: &amp;quot;&amp;quot;, serif, &amp;quot;&amp;quot;, &amp;quot;serif&amp;quot;; font-size: 12pt;"&gt;Latest Framework Target:&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;   &lt;td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;" valign="top" width="468"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;&lt;span style="font-family: &amp;quot;Times New Roman&amp;quot;, &amp;quot;serif&amp;quot;; font-size: 12pt;"&gt;JDK 6&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style="mso-yfti-irow: 10;"&gt;   &lt;td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;" valign="top" width="227"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;&lt;span style="color: #333333; font-family: &amp;quot;&amp;quot;, serif, &amp;quot;&amp;quot;, &amp;quot;serif&amp;quot;; font-size: 12pt;"&gt;Mono Target:&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;   &lt;td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;" valign="top" width="468"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;&lt;span style="color: #333333; font-family: &amp;quot;&amp;quot;, serif, &amp;quot;&amp;quot;, &amp;quot;serif&amp;quot;; font-size: 12pt;"&gt;No&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style="mso-yfti-irow: 11;"&gt;   &lt;td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;" valign="top" width="227"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;&lt;span style="color: #333333; font-family: &amp;quot;&amp;quot;, serif, &amp;quot;&amp;quot;, &amp;quot;serif&amp;quot;; font-size: 12pt;"&gt;Allows Unmanaged Code:&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;   &lt;td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;" valign="top" width="468"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;&lt;span style="color: #333333; font-family: &amp;quot;&amp;quot;, serif, &amp;quot;&amp;quot;, &amp;quot;serif&amp;quot;; font-size: 12pt;"&gt;No&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style="mso-yfti-irow: 12;"&gt;   &lt;td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;" valign="top" width="227"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;&lt;span style="color: #333333; font-family: &amp;quot;&amp;quot;, serif, &amp;quot;&amp;quot;, &amp;quot;serif&amp;quot;; font-size: 12pt;"&gt;Source Code Extension:&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;   &lt;td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;" valign="top" width="468"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;&lt;span style="color: #333333; font-family: &amp;quot;&amp;quot;, serif, &amp;quot;&amp;quot;, &amp;quot;serif&amp;quot;; font-size: 12pt;"&gt;“.gsp”&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style="mso-yfti-irow: 13;"&gt;   &lt;td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;" valign="top" width="227"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;&lt;span style="color: #333333; font-family: &amp;quot;&amp;quot;, serif, &amp;quot;&amp;quot;, &amp;quot;serif&amp;quot;; font-size: 12pt;"&gt;Keywords:&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;   &lt;td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;" valign="top" width="468"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;&lt;span style="font-family: &amp;quot;Times New Roman&amp;quot;, &amp;quot;serif&amp;quot;; font-size: 12pt;"&gt;53&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style="mso-yfti-irow: 14;"&gt;   &lt;td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;" valign="top" width="227"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;&lt;span style="color: #333333; font-family: &amp;quot;&amp;quot;, serif, &amp;quot;&amp;quot;, &amp;quot;serif&amp;quot;; font-size: 12pt;"&gt;Case Sensitive:&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;   &lt;td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;" valign="top" width="468"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;&lt;span style="color: #333333; font-family: &amp;quot;&amp;quot;, serif, &amp;quot;&amp;quot;, &amp;quot;serif&amp;quot;; font-size: 12pt;"&gt;Yes&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style="mso-yfti-irow: 15;"&gt;   &lt;td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;" valign="top" width="227"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;&lt;span style="color: #333333; font-family: &amp;quot;&amp;quot;, serif, &amp;quot;&amp;quot;, &amp;quot;serif&amp;quot;; font-size: 12pt;"&gt;Free Version Available:&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;   &lt;td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;" valign="top" width="468"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;&lt;span style="color: #333333; font-family: &amp;quot;&amp;quot;, serif, &amp;quot;&amp;quot;, &amp;quot;serif&amp;quot;; font-size: 12pt;"&gt;Yes&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style="mso-yfti-irow: 16;"&gt;   &lt;td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;" valign="top" width="227"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;&lt;span style="color: #333333; font-family: &amp;quot;&amp;quot;, serif, &amp;quot;&amp;quot;, &amp;quot;serif&amp;quot;; font-size: 12pt;"&gt;Open Source:&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;   &lt;td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;" valign="top" width="468"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;&lt;span style="color: #333333; font-family: &amp;quot;&amp;quot;, serif, &amp;quot;&amp;quot;, &amp;quot;serif&amp;quot;; font-size: 12pt;"&gt;Yes&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style="mso-yfti-irow: 17;"&gt;   &lt;td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;" valign="top" width="227"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;&lt;span style="color: #333333; font-family: &amp;quot;&amp;quot;, serif, &amp;quot;&amp;quot;, &amp;quot;serif&amp;quot;; font-size: 12pt;"&gt;Standard:&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;   &lt;td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;" valign="top" width="468"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;&lt;span style="color: #333333; font-family: &amp;quot;&amp;quot;, serif, &amp;quot;&amp;quot;, &amp;quot;serif&amp;quot;; font-size: 12pt;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style="mso-yfti-irow: 18;"&gt;   &lt;td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;" valign="top" width="227"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;&lt;span style="color: #333333; font-family: &amp;quot;&amp;quot;, serif, &amp;quot;&amp;quot;, &amp;quot;serif&amp;quot;; font-size: 12pt;"&gt;Latest IDE Support:&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;   &lt;td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;" valign="top" width="468"&gt;&lt;div class="MsoNoSpacing"&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;Eclipse&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;a href="http://www.eclipse.org/downloads/"&gt;http://www.eclipse.org/downloads/&lt;/a&gt;&lt;br /&gt;
&lt;a href="http://gosu-lang.org/eclipse.shtml"&gt;http://gosu-lang.org/eclipse.shtml&lt;/a&gt;&amp;nbsp;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;IntelliJ IDEA&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;a href="http://www.jetbrains.com/idea/download/index.html"&gt;http://www.jetbrains.com/idea/download/index.html&lt;/a&gt;&lt;br /&gt;
&lt;a href="http://gosu-lang.org/editors.shtml"&gt;http://gosu-lang.org/editors.shtml&lt;/a&gt;&amp;nbsp;&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style="mso-yfti-irow: 19;"&gt;   &lt;td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;" valign="top" width="227"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;&lt;span style="color: #333333; font-family: &amp;quot;&amp;quot;, serif, &amp;quot;&amp;quot;, &amp;quot;serif&amp;quot;; font-size: 12pt;"&gt;Language Reference:&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;   &lt;td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;" valign="top" width="468"&gt;&lt;div class="MsoNoSpacing"&gt;&lt;a href="http://gosu-lang.org/doc/index.html"&gt;http://gosu-lang.org/doc/index.html&lt;/a&gt;&lt;/div&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style="mso-yfti-irow: 20; ms
