From 58f94c2a73bc4890486ff74a74f77615829560d4 Mon Sep 17 00:00:00 2001 From: Pablo Trinidad Date: Tue, 2 Oct 2018 00:01:24 -0500 Subject: [PATCH 1/2] Add collatz sequence --- math/Collatz Conjeture/README.md | 9 +++++++++ math/Collatz Conjeture/collatz.py | 20 ++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 math/Collatz Conjeture/README.md create mode 100644 math/Collatz Conjeture/collatz.py diff --git a/math/Collatz Conjeture/README.md b/math/Collatz Conjeture/README.md new file mode 100644 index 0000000..87d7df8 --- /dev/null +++ b/math/Collatz Conjeture/README.md @@ -0,0 +1,9 @@ +# Collatz conjecture + +The Collatz conjecture is a conjecture in mathematics that concerns a sequence defined as follows: + * Start with any positive integer n. + * Then each term is obtained from the previous term as follows: + * if the previous term is even, the next term is one half the previous term. + * If the previous term is odd, the next term is 3 times the previous term plus 1. + +The conjecture is that no matter what value of n, the sequence will always reach 1. diff --git a/math/Collatz Conjeture/collatz.py b/math/Collatz Conjeture/collatz.py new file mode 100644 index 0000000..b167456 --- /dev/null +++ b/math/Collatz Conjeture/collatz.py @@ -0,0 +1,20 @@ +"""Collatz sequence. + +@author: Pablo Trinidad +""" + + +def collatz(n): + """Sequence generation.""" + l = [] + while n > 1: + l.append(n) + if n % 2 == 0: + n = n / 2 + else: + n = (3 * n) + 1 + l.append(n) + return l + +n = int(input("Enter an integer n to compute the Collatz sequence: ")) +print(collatz(n)) From f192430ebe0b67dc8a1ead0dc06f0e9a1516339d Mon Sep 17 00:00:00 2001 From: Pablo Trinidad Date: Tue, 2 Oct 2018 11:51:27 -0500 Subject: [PATCH 2/2] Removed collatz docs --- math/Collatz Conjeture/README.md | 9 --------- math/{Collatz Conjeture => }/collatz.py | 0 2 files changed, 9 deletions(-) delete mode 100644 math/Collatz Conjeture/README.md rename math/{Collatz Conjeture => }/collatz.py (100%) diff --git a/math/Collatz Conjeture/README.md b/math/Collatz Conjeture/README.md deleted file mode 100644 index 87d7df8..0000000 --- a/math/Collatz Conjeture/README.md +++ /dev/null @@ -1,9 +0,0 @@ -# Collatz conjecture - -The Collatz conjecture is a conjecture in mathematics that concerns a sequence defined as follows: - * Start with any positive integer n. - * Then each term is obtained from the previous term as follows: - * if the previous term is even, the next term is one half the previous term. - * If the previous term is odd, the next term is 3 times the previous term plus 1. - -The conjecture is that no matter what value of n, the sequence will always reach 1. diff --git a/math/Collatz Conjeture/collatz.py b/math/collatz.py similarity index 100% rename from math/Collatz Conjeture/collatz.py rename to math/collatz.py