diff --git a/polls/views.py b/polls/views.py index 769a8a0..c3a405b 100644 --- a/polls/views.py +++ b/polls/views.py @@ -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
Normal Approach:" + str(fibnonci_normal(n)) + "
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))