From eb3d472e68df502c1e4002109ec4cd353520a56c Mon Sep 17 00:00:00 2001 From: mrvnmchm Date: Wed, 10 Oct 2018 23:21:54 -0400 Subject: [PATCH 1/4] Added Zeller's congruence algorithm --- Maths/ZellersCongruence.py | 45 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 Maths/ZellersCongruence.py diff --git a/Maths/ZellersCongruence.py b/Maths/ZellersCongruence.py new file mode 100644 index 000000000000..1a665a6b67c7 --- /dev/null +++ b/Maths/ZellersCongruence.py @@ -0,0 +1,45 @@ +import argparse +"""Zellers Congruence Birthday Algorithm + Find out what day of the week you were born on, or any other date. +""" + +def zeller(date_input): + + weekdays = { + '0': 'Sunday', + '1': 'Monday', + '2': 'Tuesday', + '3': 'Wednesday', + '4': 'Thursday', + '5': 'Friday', + '6': 'Saturday' + } + + m = int(date_input[0] + date_input[1]) + d = int(date_input[3] + date_input[4]) + y = int(date_input[6] + date_input[7] + date_input[8] + date_input[9]) + + if m <= 2: + y = y - 1 + m = m + 12 + c = int(str(y)[:2]) + k = int(str(y)[2:]) + + t = int(2.6*m - 5.39) + u = int(c / 4) + v = int(k / 4) + x = d + k + z = t + u + v + x + w = z - (2 * c) + + f = round(w%7) + + for day in weekdays: + if f == int(day): + print("The date " + date_input + ", is a " + weekdays[day] + ".") + +if __name__ == '__main__': + parser = argparse.ArgumentParser(description='Find out what day of the week you were born on Accepts birthday as a string in mm-dd-yyyy or mm/dd/yyyy format') + parser.add_argument('date_input', type=str, help='Date as a string (mm-dd-yyyy or mm/dd/yyyy)') + args = parser.parse_args() + zeller(args.date_input) \ No newline at end of file From e9083b84d3db517ff1ac482086821fcc5b9c0ff9 Mon Sep 17 00:00:00 2001 From: mrvnmchm Date: Wed, 10 Oct 2018 23:28:17 -0400 Subject: [PATCH 2/4] Update args help --- Maths/ZellersCongruence.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Maths/ZellersCongruence.py b/Maths/ZellersCongruence.py index 1a665a6b67c7..1f06635dd795 100644 --- a/Maths/ZellersCongruence.py +++ b/Maths/ZellersCongruence.py @@ -39,7 +39,7 @@ def zeller(date_input): print("The date " + date_input + ", is a " + weekdays[day] + ".") if __name__ == '__main__': - parser = argparse.ArgumentParser(description='Find out what day of the week you were born on Accepts birthday as a string in mm-dd-yyyy or mm/dd/yyyy format') + parser = argparse.ArgumentParser(description='Find out what day of the week you were born on, or any other date. Accepts birthday as a string in mm-dd-yyyy or mm/dd/yyyy format.') parser.add_argument('date_input', type=str, help='Date as a string (mm-dd-yyyy or mm/dd/yyyy)') args = parser.parse_args() zeller(args.date_input) \ No newline at end of file From 4d78d6293f8fdea05ac4ee983abe582e3a19b980 Mon Sep 17 00:00:00 2001 From: "Marvin M. Michum" Date: Sun, 4 Aug 2019 23:15:34 -0400 Subject: [PATCH 3/4] add a few doctests --- boolean_algebra/quine_mc_cluskey.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/boolean_algebra/quine_mc_cluskey.py b/boolean_algebra/quine_mc_cluskey.py index db4d153cbfd7..94319ca45482 100644 --- a/boolean_algebra/quine_mc_cluskey.py +++ b/boolean_algebra/quine_mc_cluskey.py @@ -1,3 +1,18 @@ +""" + doctests + + >>> decimal_to_binary(3,[1.5]) + ['0.00.01.5'] + + >>> check(['0.00.01.5']) + ['0.00.01.5'] + + >>> prime_implicant_chart(['0.00.01.5'],['0.00.01.5']) + [[1]] + + >>> selection([[1]],['0.00.01.5']) + ['0.00.01.5'] +""" def compare_string(string1, string2): l1 = list(string1); l2 = list(string2) count = 0 @@ -113,4 +128,6 @@ def main(): print(essential_prime_implicants) if __name__ == '__main__': + import doctest + doctest.testmod() main() From 15aa3dfabe69b22283c69668aea0fe80aceacd51 Mon Sep 17 00:00:00 2001 From: "Marvin M. Michum" Date: Sun, 4 Aug 2019 23:35:24 -0400 Subject: [PATCH 4/4] remove old file --- Maths/ZellersCongruence.py | 45 -------------------------------------- 1 file changed, 45 deletions(-) delete mode 100644 Maths/ZellersCongruence.py diff --git a/Maths/ZellersCongruence.py b/Maths/ZellersCongruence.py deleted file mode 100644 index 1f06635dd795..000000000000 --- a/Maths/ZellersCongruence.py +++ /dev/null @@ -1,45 +0,0 @@ -import argparse -"""Zellers Congruence Birthday Algorithm - Find out what day of the week you were born on, or any other date. -""" - -def zeller(date_input): - - weekdays = { - '0': 'Sunday', - '1': 'Monday', - '2': 'Tuesday', - '3': 'Wednesday', - '4': 'Thursday', - '5': 'Friday', - '6': 'Saturday' - } - - m = int(date_input[0] + date_input[1]) - d = int(date_input[3] + date_input[4]) - y = int(date_input[6] + date_input[7] + date_input[8] + date_input[9]) - - if m <= 2: - y = y - 1 - m = m + 12 - c = int(str(y)[:2]) - k = int(str(y)[2:]) - - t = int(2.6*m - 5.39) - u = int(c / 4) - v = int(k / 4) - x = d + k - z = t + u + v + x - w = z - (2 * c) - - f = round(w%7) - - for day in weekdays: - if f == int(day): - print("The date " + date_input + ", is a " + weekdays[day] + ".") - -if __name__ == '__main__': - parser = argparse.ArgumentParser(description='Find out what day of the week you were born on, or any other date. Accepts birthday as a string in mm-dd-yyyy or mm/dd/yyyy format.') - parser.add_argument('date_input', type=str, help='Date as a string (mm-dd-yyyy or mm/dd/yyyy)') - args = parser.parse_args() - zeller(args.date_input) \ No newline at end of file