From fc7412cd77112dc2b66dad47d326306e31d08971 Mon Sep 17 00:00:00 2001 From: rajithr Date: Wed, 5 Aug 2026 09:25:19 +0530 Subject: [PATCH 1/3] Fix import statement for List in DiceThrower.java --- src/main/java/com/thealgorithms/recursion/DiceThrower.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/thealgorithms/recursion/DiceThrower.java b/src/main/java/com/thealgorithms/recursion/DiceThrower.java index f46d82213aaa..c7822aa9780e 100644 --- a/src/main/java/com/thealgorithms/recursion/DiceThrower.java +++ b/src/main/java/com/thealgorithms/recursion/DiceThrower.java @@ -1,7 +1,7 @@ package com.thealgorithms.recursion; import java.util.ArrayList; -import java.util.List; +import java.util.List /** * DiceThrower - Generates all possible dice roll combinations that sum to a target From ebca695cb382ffa74eba3713e0e88aeab6ef70d7 Mon Sep 17 00:00:00 2001 From: rajithr Date: Wed, 5 Aug 2026 09:30:15 +0530 Subject: [PATCH 2/3] fix: add missing semicolon in DiceThrower import --- src/main/java/com/thealgorithms/recursion/DiceThrower.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/thealgorithms/recursion/DiceThrower.java b/src/main/java/com/thealgorithms/recursion/DiceThrower.java index c7822aa9780e..f46d82213aaa 100644 --- a/src/main/java/com/thealgorithms/recursion/DiceThrower.java +++ b/src/main/java/com/thealgorithms/recursion/DiceThrower.java @@ -1,7 +1,7 @@ package com.thealgorithms.recursion; import java.util.ArrayList; -import java.util.List +import java.util.List; /** * DiceThrower - Generates all possible dice roll combinations that sum to a target From dacd1b7c6af4d0b76fc54d0d88a097fc36996b00 Mon Sep 17 00:00:00 2001 From: rajithr Date: Sat, 8 Aug 2026 16:31:52 +0530 Subject: [PATCH 3/3] Add EulerHCF class implementing Eulers HCF algorithm in maths package --- .../com/thealgorithms/maths/EulerHCF.java | 86 +++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 src/main/java/com/thealgorithms/maths/EulerHCF.java diff --git a/src/main/java/com/thealgorithms/maths/EulerHCF.java b/src/main/java/com/thealgorithms/maths/EulerHCF.java new file mode 100644 index 000000000000..6ac59ba8b2c3 --- /dev/null +++ b/src/main/java/com/thealgorithms/maths/EulerHCF.java @@ -0,0 +1,86 @@ +package com.thealgorithms.maths; + +/** + * Eulers HCF (Highest Common Factor) Algorithm + * Also known as Euclid's algorithm for finding the Greatest Common Divisor (GCD) + */ +public final class EulerHCF { + private EulerHCF() { + } + + /** + * String of IllegalArgumentException for positive numbers + */ + private static final String POSITIVE_NUMBERS = "Both numbers must be greater than 0"; + + /** + * Calculate the Highest Common Factor (HCF) of two numbers using Eulers algorithm. + * This is also known as the Greatest Common Divisor (GCD). + * + * @param num1 first number + * @param num2 second number + * @return the highest common factor of the two given numbers + */ + public static int eulerHCF(final int num1, final int num2) { + if (num1 <= 0 || num2 <= 0) { + throw new IllegalArgumentException(POSITIVE_NUMBERS); + } + return eulerHCFHelper(num1, num2); + } + + /** + * Helper method to recursively calculate HCF using Eulers algorithm. + * + * @param num1 first number + * @param num2 second number + * @return the highest common factor of the two given numbers + */ + private static int eulerHCFHelper(final int num1, final int num2) { + if (num2 == 0) { + return num1; + } + return eulerHCFHelper(num2, num1 % num2); + } + + /** + * Calculate the Highest Common Factor (HCF) of two numbers using Eulers algorithm (iterative approach). + * + * @param num1 first number + * @param num2 second number + * @return the highest common factor of the two given numbers + */ + public static int eulerHCFIterative(final int num1, final int num2) { + if (num1 <= 0 || num2 <= 0) { + throw new IllegalArgumentException(POSITIVE_NUMBERS); + } + int a = num1; + int b = num2; + while (b != 0) { + int temp = b; + b = a % b; + a = temp; + } + return a; + } + + /** + * Calculate the Highest Common Factor (HCF) of two long numbers using Eulers algorithm. + * + * @param num1 first long number + * @param num2 second long number + * @return the highest common factor of the two given numbers + */ + public static long eulerHCF(final long num1, final long num2) { + if (num1 <= 0 || num2 <= 0) { + throw new IllegalArgumentException(POSITIVE_NUMBERS); + } + long a = num1; + long b = num2; + while (b != 0) { + long temp = b; + b = a % b; + a = temp; + } + return a; + } +}