From fe7f9748c67f2345cc11be15e68e60a965512fab Mon Sep 17 00:00:00 2001 From: Diogenis15 <148352448+Diogenis15@users.noreply.github.com> Date: Fri, 30 Jan 2026 22:01:04 +0200 Subject: [PATCH 1/5] Add implementation for Trimorphic Number An algorithm that checks if a number is trimorphic, which is a number whose cube ends with the same digits as the number itself --- trimorphic_number.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 trimorphic_number.py diff --git a/trimorphic_number.py b/trimorphic_number.py new file mode 100644 index 000000000000..c667b6ab67b5 --- /dev/null +++ b/trimorphic_number.py @@ -0,0 +1,26 @@ +""" +A Trimorphic Number is a number whose cube ends in the same digits as the number itself. +For example, 4^3 = 64, which ends in 4. + +Reference: https://en.wikipedia.org/wiki/Automorphic_number#Trimorphic_numbers +""" + + +def is_trimorphic(number: int) -> bool: + """ + Checks if a number is a Trimorphic number. + """ + if number < 0: + raise ValueError("Input must be a non-negative integer") + + if number == 0: + return True + + cube = number**3 + return str(cube).endswith(str(number)) + + +if __name__ == "__main__": + import doctest + + doctest.testmod() From 13378ddba3949fbd5fc907e1244e5d57fde36e05 Mon Sep 17 00:00:00 2001 From: Diogenis15 <148352448+Diogenis15@users.noreply.github.com> Date: Fri, 30 Jan 2026 22:29:45 +0200 Subject: [PATCH 2/5] Add doctests for is_trimorphic function Added doctests for the is_trimorphic function to validate its behavior with various inputs, including edge cases. --- trimorphic_number.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/trimorphic_number.py b/trimorphic_number.py index c667b6ab67b5..a3e71aef5cc3 100644 --- a/trimorphic_number.py +++ b/trimorphic_number.py @@ -9,6 +9,29 @@ def is_trimorphic(number: int) -> bool: """ Checks if a number is a Trimorphic number. + + >>> is_trimorphic(0) + True + >>> is_trimorphic(1) + True + >>> is_trimorphic(4) + True + >>> is_trimorphic(5) + True + >>> is_trimorphic(24) + True + >>> is_trimorphic(249) + True + >>> is_trimorphic(2) + False + >>> is_trimorphic(7) + False + >>> is_trimorphic(10) + False + >>> is_trimorphic(-1) + Traceback (most recent call last): + ... + ValueError: Input must be a non-negative integer """ if number < 0: raise ValueError("Input must be a non-negative integer") From 4b371c9c216a2380022474c34add2afbd1047a27 Mon Sep 17 00:00:00 2001 From: Diogenis15 <148352448+Diogenis15@users.noreply.github.com> Date: Fri, 30 Jan 2026 22:36:00 +0200 Subject: [PATCH 3/5] Enhance docstring for is_trimorphic function Added parameter and return type documentation to is_trimorphic function. --- trimorphic_number.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/trimorphic_number.py b/trimorphic_number.py index a3e71aef5cc3..08a21c99be4e 100644 --- a/trimorphic_number.py +++ b/trimorphic_number.py @@ -10,6 +10,10 @@ def is_trimorphic(number: int) -> bool: """ Checks if a number is a Trimorphic number. + :param number: The number to check + :return: True if the number is trimorphic, False otherwise + :raises ValueError: If the input number is negative + >>> is_trimorphic(0) True >>> is_trimorphic(1) From 9a094cdcc2313629c0bcb6e65f9978515dbff9f7 Mon Sep 17 00:00:00 2001 From: Diogenis15 <148352448+Diogenis15@users.noreply.github.com> Date: Fri, 30 Jan 2026 22:49:31 +0200 Subject: [PATCH 4/5] Rename trimorphic_number.py to maths/special_numbers/trimorphic_number.py --- .../special_numbers/trimorphic_number.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename trimorphic_number.py => maths/special_numbers/trimorphic_number.py (100%) diff --git a/trimorphic_number.py b/maths/special_numbers/trimorphic_number.py similarity index 100% rename from trimorphic_number.py rename to maths/special_numbers/trimorphic_number.py From dbdf22b5f8f909b4af72f53301492040d5b34126 Mon Sep 17 00:00:00 2001 From: cclauss Date: Mon, 14 Sep 2026 04:39:31 +0000 Subject: [PATCH 5/5] updating DIRECTORY.md --- DIRECTORY.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/DIRECTORY.md b/DIRECTORY.md index 29183f42a94e..311a7c7c9de8 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -695,6 +695,7 @@ * Forecasting * [Run](machine_learning/forecasting/run.py) * [Frequent Pattern Growth](machine_learning/frequent_pattern_growth.py) + * [Gaussian Mixture Model](machine_learning/gaussian_mixture_model.py) * [Gaussian Naive Bayes](machine_learning/gaussian_naive_bayes.py) * [Gradient Boosting Classifier](machine_learning/gradient_boosting_classifier.py) * [Gradient Boosting Regressor](machine_learning/gradient_boosting_regressor.py) @@ -742,6 +743,7 @@ * [Bailey Borwein Plouffe](maths/bailey_borwein_plouffe.py) * [Base Neg2 Conversion](maths/base_neg2_conversion.py) * [Basic Maths](maths/basic_maths.py) + * [Bearing](maths/bearing.py) * [Binary Exponentiation](maths/binary_exponentiation.py) * [Binary Multiplication](maths/binary_multiplication.py) * [Binomial Coefficient](maths/binomial_coefficient.py) @@ -878,6 +880,7 @@ * [Hexagonal Numbers](maths/series/hexagonal_numbers.py) * [Logarithmic Series](maths/series/logarithmic_series.py) * [P Series](maths/series/p_series.py) + * [Shoelace Area](maths/shoelace_area.py) * [Sieve Of Atkin](maths/sieve_of_atkin.py) * [Sieve Of Eratosthenes](maths/sieve_of_eratosthenes.py) * [Sigmoid](maths/sigmoid.py) @@ -909,6 +912,7 @@ * [Pronic Number](maths/special_numbers/pronic_number.py) * [Proth Number](maths/special_numbers/proth_number.py) * [Triangular Numbers](maths/special_numbers/triangular_numbers.py) + * [Trimorphic Number](maths/special_numbers/trimorphic_number.py) * [Ugly Numbers](maths/special_numbers/ugly_numbers.py) * [Weird Number](maths/special_numbers/weird_number.py) * [Sum Of Arithmetic Series](maths/sum_of_arithmetic_series.py)