Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Zeller's Congruence Algorithm and Lucas Sequence using Recursion in Python #224

Merged
merged 3 commits into from
Oct 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions python/maths/lucas_sequence.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# -*- coding: utf-8 -*-
"""
Created on Mon Oct 5 15:50:11 2020

@author: Vijay
"""

# Lucas Number using Recursion.

# Approach 1 ->

def lucas(num):

# Base Cases ->
if (num == 0) :
return 2

if (num == 1) :
return 1

# Recurrence Relation
return lucas(num - 1) + lucas(num - 2)

num = int(input('Enter the Number -> '))

print("Lucas number is -> ", lucas(num) )

# Approach 2 ->

'''
def lucas(num , num_1 = 2, num_2 = 1):
if num :
return lucas(num - 1, num_2 ,num_1 + num_2)

else:
return num_1


num = int(input('Enter Number -> '))

print("Lucas Number is -> ", lucas(num))
'''

41 changes: 41 additions & 0 deletions python/maths/zellers_congruence.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Zeller's Congruence Rule


def day_of_date(d) :
day_dict = {
0 : 'Sunday',
1 : 'Monday',
2 : 'Tuesday',
3 : 'Wednesday',
4 : 'Thursday',
5 : 'Friday',
6 : 'Saturday'}
return day_dict[d]

def month_shift(month, year):
if month == 1 or month == 2:
month += 10
year -= 1
return month , year

else:
month -= 2
return month ,year

def ZellersCongruence(day, month, year):
month , year = month_shift(month, year)
k = day
m = month
d = year % 100
c = year // 100
f = (k + ((13 * m -1) // 5) + d + (d // 4) + (c // 4) - 2 * c)
f = (f % 7)
return day_of_date(f)



day = int(input('Enter Day -> '))
month = int(input('Enter Month -> '))
year = int(input('Enter Year -> '))

print("The Day of the Given Date is -> ", ZellersCongruence(day, month, year))