Browse Source

Moved Fibonacci algorithms in to separate namespace for
organization reasons.

Bryan Allred 14 years ago
parent
commit
d174507a7d

+ 26 - 26
src/Main.py

@ -5,14 +5,14 @@ Created on Jun 10, 2011
5 5
@author: BMAllred
6 6
'''
7 7

8
import FibonacciBinet
9
import FibonacciDjikstra
10
import FibonacciGenerator
11
import FibonacciIteration
12
import FibonacciLucas
13
import FibonacciMatrix
14
import FibonacciMemory
15
import FibonacciRecursive
8
import mathex.fibonacci.Binet as Binet
9
import mathex.fibonacci.Djikstra as Djikstra
10
import mathex.fibonacci.Generator as Generator
11
import mathex.fibonacci.Iteration as Iteration
12
import mathex.fibonacci.Lucas as Lucas
13
import mathex.fibonacci.Matrix as Matrix
14
import mathex.fibonacci.Memory as Memory
15
import mathex.fibonacci.Recursive as Recursive
16 16
from StopWatch import StopWatch
17 17

18 18
def displayMenu():
@ -36,9 +36,9 @@ def displayMenu():
36 36
            break
37 37
        
38 38
        if choice == "1":
39
            SingleTest()
39
            singleTest()
40 40
        elif choice == "2":
41
            Benchmark()
41
            benchmark()
42 42
        else:
43 43
            print "Incorrect selection."
44 44
        
@ -48,7 +48,7 @@ def displayMenu():
48 48
    print "Hope you had as much as I did!"
49 49
    print
50 50

51
def Benchmark():
51
def benchmark():
52 52
    print
53 53
    print "Select your poison:"
54 54
    print
@ -81,7 +81,7 @@ def Benchmark():
81 81
            print "Binet's formula"
82 82
            
83 83
            while completed < n:
84
                FibonacciBinet.fib(completed)
84
                Binet.fib(completed)
85 85
                completed += 1
86 86
        except:
87 87
            pass
@ -98,7 +98,7 @@ def Benchmark():
98 98
            print "Djikstra's method"
99 99
            
100 100
            while completed < n:
101
                FibonacciDjikstra.fib(completed)
101
                Djikstra.fib(completed)
102 102
                completed += 1
103 103
        except:
104 104
            pass
@ -115,7 +115,7 @@ def Benchmark():
115 115
            print "Iteration"
116 116
            
117 117
            while completed < n:
118
                FibonacciIteration.fib(n)
118
                Iteration.fib(n)
119 119
                completed += 1
120 120
        except:
121 121
            pass
@ -132,7 +132,7 @@ def Benchmark():
132 132
            print "Lucas' numbers"
133 133
            
134 134
            while completed < n:
135
                FibonacciLucas.fib(n)
135
                Lucas.fib(n)
136 136
                completed += 1
137 137
        except:
138 138
            pass
@ -149,7 +149,7 @@ def Benchmark():
149 149
            print "Matrix"
150 150
            
151 151
            while completed < n:
152
                FibonacciMatrix.fib(n)
152
                Matrix.fib(n)
153 153
                completed += 1
154 154
        except:
155 155
            pass
@ -166,7 +166,7 @@ def Benchmark():
166 166
            print "Memory"
167 167
            
168 168
            while completed < n:
169
                FibonacciMemory.fib(n)
169
                Memory.fib(n)
170 170
                completed += 1
171 171
        except:
172 172
            pass
@ -183,7 +183,7 @@ def Benchmark():
183 183
            print "Recursive (intensive)"
184 184
            
185 185
            while completed < n:
186
                FibonacciRecursive.fib(n)
186
                Recursive.fib(n)
187 187
                completed += 1
188 188
        except:
189 189
            pass
@ -191,7 +191,7 @@ def Benchmark():
191 191
            print "\tCompleted: {0}% in {1} ms".format((1.0 * completed / n) * 100, stopWatch.TotalMilliseconds())
192 192
            print
193 193

194
def SingleTest():
194
def singleTest():
195 195
    print
196 196
    print "Select your poison:"
197 197
    print
@ -220,19 +220,19 @@ def SingleTest():
220 220
    try:
221 221
        # Perform the necessary method.
222 222
        if choice == "1":
223
            answer = FibonacciBinet.fib(n)
223
            answer = Binet.fib(n)
224 224
        elif choice == "2":
225
            answer = FibonacciDjikstra.fib(n)
225
            answer = Djikstra.fib(n)
226 226
        elif choice == "3":
227
            answer = FibonacciIteration.fib(n)
227
            answer = Iteration.fib(n)
228 228
        elif choice == "4":
229
            answer = FibonacciLucas.fib(n)
229
            answer = Lucas.fib(n)
230 230
        elif choice == "5":
231
            answer = FibonacciMatrix.fib(n)
231
            answer = Matrix.fib(n)
232 232
        elif choice == "6":
233
            answer = FibonacciMemory.fib(n)
233
            answer = Memory.fib(n)
234 234
        elif choice == "7":
235
            answer = FibonacciRecursive.fib(n)
235
            answer = Recursive.fib(n)
236 236
    except:
237 237
        pass
238 238
    

+ 0 - 0
src/mathex/__init__.py


src/FibonacciBinet.py → src/mathex/fibonacci/Binet.py


src/FibonacciDjikstra.py → src/mathex/fibonacci/Djikstra.py


src/FibonacciGenerator.py → src/mathex/fibonacci/Generator.py


src/FibonacciIteration.py → src/mathex/fibonacci/Iteration.py


src/FibonacciLucas.py → src/mathex/fibonacci/Lucas.py


src/FibonacciMatrix.py → src/mathex/fibonacci/Matrix.py


src/FibonacciMemory.py → src/mathex/fibonacci/Memory.py


src/FibonacciRecursive.py → src/mathex/fibonacci/Recursive.py


+ 0 - 0
src/mathex/fibonacci/__init__.py