Beta

Collatz Conjecture of Congruent Modulo M

Description:

Collatz Conjecture Explained

The Collatz Conjecture is a mathematical hypothesis that applies to positive integers. It states that if you start with any positive integer n, the following sequence will always eventually reach 1:

  1. If n is even, divide it by 2.
  2. If n is odd, multiply it by 3 and add 1.

This process is repeated iteratively, with each number in the sequence being halved if even or tripled and incremented by 1 if odd, until the sequence eventually reaches 1. See the wiki page.

Collatz Sequence of Congruent Modulo M.

We can apply this same proccess for integers of Modulo M, there is the formula for Collatz Sequence of Modulo M that will be applied repeatealy:

f(n)={(n/2)modmif n is even(3n+1)modmif n is odd f(n)= \begin{cases} (n/2)\mod{m} && \text{if n is even} \\ (3n+1)\mod{m} && \text{if n is odd} \end{cases}

Your objective is create a function collatz_module(m) that will return tuple with two values (value_verification_array, is_conjecture_true_at_M) where value_verification_array is a array of 0 to m-1 which the element of value_verification_array[n] is true if n eventually reaches 1 and false if it loops or go to 0.

The is_conjecture_true_at_M is a boolean, true if every n bigger than 0 in the value_verification_array[n] is true otherwise is false.

Function Signature:

def collatz_module(m):
    """
    Generates a tuple containing Analysis of Collatz Conjecture of Congruent Modulo M.

    Parameters:
      m (int): Number which the sequence will be congruent.

    Returns:
      tuple: A tuple containing two values:
          - value_verification_array (list)
          - is_conjecture_true_at_M (bool)

    """
    return ([], False)

Input:

'm' (2 ≤ m ≤ 80000) - Number which the sequence will be congruent.

Output:

Must return tuple with two values (value_verification_array, is_conjecture_true_at_M).

Example:

print(collatz_module(4)) # M=4, Outputs: ([False,  True,  True,  True], True)
print(collatz_module(5)) # M=5, Outputs: ([False,  True,  True, False,  True], False)
print(collatz_module(6)) # M=6, Outputs: ([False,  True,  True,  True,  True,  True], True)
print(collatz_module(7)) # M=7, Outputs: ([False,  True,  True, False,  True,  True, False], False)

Notes

  • The n=0 will be always false and n=1 will be always true by the definitions, so you must ignore in the is_conjecture_true_at_M verification.
Performance
Algorithms
Mathematics

More By Author:

Check out these other kata created by Angel !

Stats:

CreatedMay 12, 2024
PublishedMay 12, 2024
Warriors Trained98
Total Skips43
Total Code Submissions110
Total Times Completed18
Python Completions18
Total Stars4
% of votes with a positive feedback rating73% of 11
Total "Very Satisfied" Votes6
Total "Somewhat Satisfied" Votes4
Total "Not Satisfied" Votes1
Total Rank Assessments11
Average Assessed Rank
5 kyu
Highest Assessed Rank
4 kyu
Lowest Assessed Rank
6 kyu
Ad
Contributors
  • Angel ! Avatar
  • mauro-1 Avatar
Ad