Skip to content

Commit

Permalink
adding code to calculate fibnonci for /poll url 🍰
Browse files Browse the repository at this point in the history
  • Loading branch information
prashanthmadi committed Jun 8, 2017
1 parent 576fd28 commit 7654e83
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion polls/views.py
Original file line number Diff line number Diff line change
@@ -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.