diff --git a/README.md b/README.md
index f88a49ea1..1fca7fa00 100644
--- a/README.md
+++ b/README.md
@@ -92,10 +92,10 @@ Read our [Contribution Guidelines](CONTRIBUTING.md) before you contribute.
1. [`BitCounter`](./math/binary/bitcounter.go#L11): BitCounter - The function returns the number of set bits for an unsigned integer number
2. [`IsPowerOfTwo`](./math/binary/checkisnumberpoweroftwo.go#L19): IsPowerOfTwo This function uses the fact that powers of 2 are represented like 10...0 in binary, and numbers one less than the power of 2 are represented like 11...1. Therefore, using the and function: 10...0 & 01...1 00...0 -> 0 This is also true for 0, which is not a power of 2, for which we have to add and extra condition.
3. [`IsPowerOfTwoLeftShift`](./math/binary/checkisnumberpoweroftwo.go#L26): IsPowerOfTwoLeftShift This function takes advantage of the fact that left shifting a number by 1 is equivalent to multiplying by 2. For example, binary 00000001 when shifted by 3 becomes 00001000, which in decimal system is 8 or = 2 * 2 * 2
-4. [`MeanUsingAndXor`](./math/binary/arithmeticmean.go#L11): No description provided.
-5. [`MeanUsingRightShift`](./math/binary/arithmeticmean.go#L15): No description provided.
+4. [`MeanUsingAndXor`](./math/binary/arithmeticmean.go#L12): MeanUsingAndXor This function finds arithmetic mean using "AND" and "XOR" operations
+5. [`MeanUsingRightShift`](./math/binary/arithmeticmean.go#L17): MeanUsingRightShift This function finds arithmetic mean using right shift
6. [`ReverseBits`](./math/binary/reversebits.go#L14): ReverseBits This function initialized the result by 0 (all bits 0) and process the given number starting from its least significant bit. If the current bit is 1, set the corresponding most significant bit in the result and finally move on to the next bit in the input number. Repeat this till all its bits are processed.
-7. [`XorSearchMissingNumber`](./math/binary/xorsearch.go#L10): No description provided.
+7. [`XorSearchMissingNumber`](./math/binary/xorsearch.go#L11): XorSearchMissingNumber This function finds a missing number in a sequence
---
@@ -146,7 +146,7 @@ Read our [Contribution Guidelines](CONTRIBUTING.md) before you contribute.
##### Functions:
-1. [`CatalanNumber`](./math/catalan/catalannumber.go#L15): No description provided.
+1. [`CatalanNumber`](./math/catalan/catalannumber.go#L16): CatalanNumber This function returns the `nth` Catalan number
---
@@ -197,13 +197,15 @@ Read our [Contribution Guidelines](CONTRIBUTING.md) before you contribute.
---
##### Functions:
-1. [`BinaryToDecimal`](./conversion/binarytodecimal.go#L25): BinaryToDecimal() function that will take Binary number as string, and return it's Decimal equivalent as integer.
-2. [`DecimalToBinary`](./conversion/decimaltobinary.go#L32): DecimalToBinary() function that will take Decimal number as int, and return it's Binary equivalent as string.
-3. [`HEXToRGB`](./conversion/rgbhex.go#L10): HEXToRGB splits an RGB input (e.g. a color in hex format; 0x) into the individual components: red, green and blue
-4. [`IntToRoman`](./conversion/integertoroman.go#L17): IntToRoman converts an integer value to a roman numeral string. An error is returned if the integer is not between 1 and 3999.
-5. [`RGBToHEX`](./conversion/rgbhex.go#L41): RGBToHEX does exactly the opposite of HEXToRGB: it combines the three components red, green and blue to an RGB value, which can be converted to e.g. Hex
-6. [`Reverse`](./conversion/decimaltobinary.go#L22): Reverse() function that will take string, and returns the reverse of that string.
-7. [`RomanToInteger`](./conversion/romantointeger.go#L40): RomanToInteger converts a roman numeral string to an integer. Roman numerals for numbers outside the range 1 to 3,999 will return an error. Nil or empty string return 0 with no error thrown.
+1. [`Base64Decode`](./conversion/base64.go#L57): Base64Decode decodes the received input base64 string into a byte slice. The implementation follows the RFC4648 standard, which is documented at https://datatracker.ietf.org/doc/html/rfc4648#section-4
+2. [`Base64Encode`](./conversion/base64.go#L19): Base64Encode encodes the received input bytes slice into a base64 string. The implementation follows the RFC4648 standard, which is documented at https://datatracker.ietf.org/doc/html/rfc4648#section-4
+3. [`BinaryToDecimal`](./conversion/binarytodecimal.go#L25): BinaryToDecimal() function that will take Binary number as string, and return it's Decimal equivalent as integer.
+4. [`DecimalToBinary`](./conversion/decimaltobinary.go#L32): DecimalToBinary() function that will take Decimal number as int, and return it's Binary equivalent as string.
+5. [`HEXToRGB`](./conversion/rgbhex.go#L10): HEXToRGB splits an RGB input (e.g. a color in hex format; 0x) into the individual components: red, green and blue
+6. [`IntToRoman`](./conversion/integertoroman.go#L17): IntToRoman converts an integer value to a roman numeral string. An error is returned if the integer is not between 1 and 3999.
+7. [`RGBToHEX`](./conversion/rgbhex.go#L41): RGBToHEX does exactly the opposite of HEXToRGB: it combines the three components red, green and blue to an RGB value, which can be converted to e.g. Hex
+8. [`Reverse`](./conversion/decimaltobinary.go#L22): Reverse() function that will take string, and returns the reverse of that string.
+9. [`RomanToInteger`](./conversion/romantointeger.go#L40): RomanToInteger converts a roman numeral string to an integer. Roman numerals for numbers outside the range 1 to 3,999 will return an error. Nil or empty string return 0 with no error thrown.
---
@@ -272,9 +274,9 @@ Read our [Contribution Guidelines](CONTRIBUTING.md) before you contribute.
---
##### Functions:
-1. [`BruteForceFactorial`](./math/factorial/factorial.go#L11): No description provided.
-2. [`CalculateFactorialUseTree`](./math/factorial/factorial.go#L27): No description provided.
-3. [`RecursiveFactorial`](./math/factorial/factorial.go#L19): No description provided.
+1. [`Iterative`](./math/factorial/factorial.go#L12): Iterative returns the iteratively brute forced factorial of n
+2. [`Recursive`](./math/factorial/factorial.go#L21): Recursive This function recursively computes the factorial of a number
+3. [`UsingTree`](./math/factorial/factorial.go#L30): UsingTree This function finds the factorial of a number using a binary tree
---
@@ -505,7 +507,7 @@ Read our [Contribution Guidelines](CONTRIBUTING.md) before you contribute.
##### Functions:
-1. [`BitwiseMax`](./math/max/bitwisemax.go#L10): No description provided.
+1. [`Bitwise`](./math/max/bitwisemax.go#L11): Bitwise computes using bitwise operator the maximum of all the integer input and returns it
2. [`Int`](./math/max/max.go#L4): Int is a function which returns the maximum of all the integers provided as arguments.
---
@@ -529,7 +531,7 @@ Read our [Contribution Guidelines](CONTRIBUTING.md) before you contribute.
##### Functions:
-1. [`Bitwise`](./math/min/bitwisemin.go#L10): No description provided.
+1. [`Bitwise`](./math/min/bitwisemin.go#L11): Bitwise This function returns the minimum integer using bit operations
2. [`Int`](./math/min/min.go#L4): Int is a function which returns the minimum of all the integers provided as arguments.
---
diff --git a/math/binary/arithmeticmean.go b/math/binary/arithmeticmean.go
index 3fbce0631..9fa56560e 100644
--- a/math/binary/arithmeticmean.go
+++ b/math/binary/arithmeticmean.go
@@ -8,10 +8,12 @@
// Package binary describes algorithms that use binary operations for different calculations.
package binary
+// MeanUsingAndXor This function finds arithmetic mean using "AND" and "XOR" operations
func MeanUsingAndXor(a int, b int) int {
return ((a ^ b) >> 1) + (a & b)
}
+// MeanUsingRightShift This function finds arithmetic mean using right shift
func MeanUsingRightShift(a int, b int) int {
return (a + b) >> 1
}
diff --git a/math/binary/xorsearch.go b/math/binary/xorsearch.go
index cdd4e09c8..b16b7846b 100644
--- a/math/binary/xorsearch.go
+++ b/math/binary/xorsearch.go
@@ -7,6 +7,7 @@
package binary
+// XorSearchMissingNumber This function finds a missing number in a sequence
func XorSearchMissingNumber(a []int) int {
n := len(a)
result := len(a)
diff --git a/math/catalan/catalannumber.go b/math/catalan/catalannumber.go
index b899d2569..31a424347 100644
--- a/math/catalan/catalannumber.go
+++ b/math/catalan/catalannumber.go
@@ -12,6 +12,7 @@ import (
f "github.com/TheAlgorithms/Go/math/factorial"
)
+// CatalanNumber This function returns the `nth` Catalan number
func CatalanNumber(n int) int {
- return f.BruteForceFactorial(n*2) / (f.BruteForceFactorial(n) * f.BruteForceFactorial(n+1))
+ return f.Iterative(n*2) / (f.Iterative(n) * f.Iterative(n+1))
}
diff --git a/math/factorial/factorial.go b/math/factorial/factorial.go
index 2d376a87b..6b7f5f516 100644
--- a/math/factorial/factorial.go
+++ b/math/factorial/factorial.go
@@ -8,7 +8,8 @@
// Package factorial describes algorithms Factorials calculations.
package factorial
-func BruteForceFactorial(n int) int {
+// Iterative returns the iteratively brute forced factorial of n
+func Iterative(n int) int {
result := 1
for i := 2; i <= n; i++ {
result *= i
@@ -16,15 +17,17 @@ func BruteForceFactorial(n int) int {
return result
}
-func RecursiveFactorial(n int) int {
+// Recursive This function recursively computes the factorial of a number
+func Recursive(n int) int {
if n == 1 {
return 1
} else {
- return n * RecursiveFactorial(n-1)
+ return n * Recursive(n-1)
}
}
-func CalculateFactorialUseTree(n int) int {
+// UsingTree This function finds the factorial of a number using a binary tree
+func UsingTree(n int) int {
if n < 0 {
return 0
}
diff --git a/math/factorial/factorial_test.go b/math/factorial/factorial_test.go
index 9a083441d..04eceb973 100644
--- a/math/factorial/factorial_test.go
+++ b/math/factorial/factorial_test.go
@@ -30,7 +30,7 @@ func TestBruteForceFactorial(t *testing.T) {
tests := getTests()
for _, tv := range tests {
t.Run(tv.name, func(t *testing.T) {
- result := BruteForceFactorial(tv.n)
+ result := Iterative(tv.n)
if result != tv.result {
t.Errorf("Wrong result! Expected:%d, returned:%d ", tv.result, result)
}
@@ -42,7 +42,7 @@ func TestRecursiveFactorial(t *testing.T) {
tests := getTests()
for _, tv := range tests {
t.Run(tv.name, func(t *testing.T) {
- result := RecursiveFactorial(tv.n)
+ result := Recursive(tv.n)
if result != tv.result {
t.Errorf("Wrong result! Expected:%d, returned:%d ", tv.result, result)
}
@@ -54,7 +54,7 @@ func TestCalculateFactorialUseTree(t *testing.T) {
tests := getTests()
for _, tv := range tests {
t.Run(tv.name, func(t *testing.T) {
- result := CalculateFactorialUseTree(tv.n)
+ result := UsingTree(tv.n)
if result != tv.result {
t.Errorf("Wrong result! Expected:%d, returned:%d ", tv.result, result)
}
@@ -64,18 +64,18 @@ func TestCalculateFactorialUseTree(t *testing.T) {
func BenchmarkBruteForceFactorial(b *testing.B) {
for i := 0; i < b.N; i++ {
- BruteForceFactorial(10)
+ Iterative(10)
}
}
func BenchmarkRecursiveFactorial(b *testing.B) {
for i := 0; i < b.N; i++ {
- RecursiveFactorial(10)
+ Recursive(10)
}
}
func BenchmarkCalculateFactorialUseTree(b *testing.B) {
for i := 0; i < b.N; i++ {
- RecursiveFactorial(10)
+ Recursive(10)
}
}
diff --git a/math/max/bitwisemax.go b/math/max/bitwisemax.go
index ece9c4dbe..b6c3a4623 100644
--- a/math/max/bitwisemax.go
+++ b/math/max/bitwisemax.go
@@ -7,7 +7,8 @@
package max
-func BitwiseMax(a int, b int, base int) int {
+// Bitwise computes using bitwise operator the maximum of all the integer input and returns it
+func Bitwise(a int, b int, base int) int {
z := a - b
i := (z >> base) & 1
return a - (i * z)
diff --git a/math/max/bitwisemax_test.go b/math/max/bitwisemax_test.go
index addf45733..c28bb1cf6 100644
--- a/math/max/bitwisemax_test.go
+++ b/math/max/bitwisemax_test.go
@@ -1,5 +1,5 @@
// bitwiseMax_test.go
-// description: Test for BitwiseMax
+// description: Test for Bitwise
// author(s) [red_byte](https://github.com/i-redbyte)
// see bitwiseMax.go
@@ -11,67 +11,67 @@ func TestBitwiseMax(t *testing.T) {
base32 := 31
t.Run("Testing(32bit) a = 32 and m = 64: ", func(t *testing.T) {
- max := BitwiseMax(32, 64, base32)
+ max := Bitwise(32, 64, base32)
if max != 64 {
- t.Fatalf("Error: BitwiseMax returned bad value")
+ t.Fatalf("Error: Bitwise returned bad value")
}
})
t.Run("Testing(32bit) a = 1024 and m = -9: ", func(t *testing.T) {
- max := BitwiseMax(1024, -9, base32)
+ max := Bitwise(1024, -9, base32)
if max != 1024 {
- t.Fatalf("Error: BitwiseMax returned bad value")
+ t.Fatalf("Error: Bitwise returned bad value")
}
})
t.Run("Testing(32bit) a = -6 and m = -6: ", func(t *testing.T) {
- max := BitwiseMax(-6, -6, base32)
+ max := Bitwise(-6, -6, base32)
if max != -6 {
- t.Fatalf("Error: BitwiseMax returned bad value")
+ t.Fatalf("Error: Bitwise returned bad value")
}
})
t.Run("Testing(32bit) a = -72 and m = -73: ", func(t *testing.T) {
- max := BitwiseMax(-72, -73, base32)
+ max := Bitwise(-72, -73, base32)
if max != -72 {
- t.Fatalf("Error: BitwiseMax returned bad value")
+ t.Fatalf("Error: Bitwise returned bad value")
}
})
base64 := 63
t.Run("Testing(64bit) a = 32 and m = 9223372036854775807: ", func(t *testing.T) {
- max := BitwiseMax(32, 9223372036854775807, base64)
+ max := Bitwise(32, 9223372036854775807, base64)
if max != 9223372036854775807 {
- t.Fatalf("Error: BitwiseMax returned bad value")
+ t.Fatalf("Error: Bitwise returned bad value")
}
})
t.Run("Testing(64bit) a = 1024 and m = -9223372036854770001: ", func(t *testing.T) {
- max := BitwiseMax(1024, -9223372036854770001, base64)
+ max := Bitwise(1024, -9223372036854770001, base64)
if max != 1024 {
- t.Fatalf("Error: BitwiseMax returned bad value")
+ t.Fatalf("Error: Bitwise returned bad value")
}
})
t.Run("Testing(64bit) a = -6 and m = -6: ", func(t *testing.T) {
- max := BitwiseMax(-6, -6, base64)
+ max := Bitwise(-6, -6, base64)
if max != -6 {
- t.Fatalf("Error: BitwiseMax returned bad value")
+ t.Fatalf("Error: Bitwise returned bad value")
}
})
t.Run("Testing(64bit) a = -4223372036854775809 and m = -4223372036854775808: ", func(t *testing.T) {
- max := BitwiseMax(-4223372036854775809, -4223372036854775808, base64)
+ max := Bitwise(-4223372036854775809, -4223372036854775808, base64)
if max != -4223372036854775808 {
- t.Fatalf("Error: BitwiseMax returned bad value")
+ t.Fatalf("Error: Bitwise returned bad value")
}
})
base8 := 7
t.Run("Testing(8bit) a = 257 and m = 256: ", func(t *testing.T) {
- max := BitwiseMax(8, 16, base8)
+ max := Bitwise(8, 16, base8)
if max != 16 {
- t.Fatalf("Error: BitwiseMax returned bad value")
+ t.Fatalf("Error: Bitwise returned bad value")
}
})
}
diff --git a/math/min/bitwisemin.go b/math/min/bitwisemin.go
index 9710910aa..679d95840 100644
--- a/math/min/bitwisemin.go
+++ b/math/min/bitwisemin.go
@@ -7,6 +7,7 @@
package min
+// Bitwise This function returns the minimum integer using bit operations
func Bitwise(base int, value int, values ...int) int {
min := value
for _, val := range values {