Permalink
Browse files

adding code to calculate fibnonci for /poll url 🍰

  • Loading branch information...
prashanthmadi committed Jun 8, 2017
1 parent 576fd28 commit 7654e83b659b11deb62fdce536bbe5c3009399b5
Showing with 17 additions and 1 deletion.
  1. +17 −1 polls/views.py
View
@@ -1,8 +1,24 @@
from math import sqrt
from django.shortcuts import render
# Create your views here.
from django.http import HttpResponse
def index(request):
return HttpResponse("Hello, world. You're at the polls index.")
n = int(request.GET.get('n', 15))
return HttpResponse("Fibnonci of " + str(n) + " using <br> Normal Approach:" + str(fibnonci_normal(n)) + " <br> Easy Formula Approach" + str(fibnonci_easy(n)))
def fibnonci_normal(n):
if n == 0:
return 0
elif n == 1:
return 1
else:
return fibnonci_normal(n - 1) + fibnonci_normal(n - 2)
def fibnonci_easy(n):
return ((1 + sqrt(5))**n - (1 - sqrt(5))**n) / (2**n * sqrt(5))

0 comments on commit 7654e83

Please sign in to comment.