Skip to content

Commit 385fe84

Browse files
i-redbyteraklaptudirmgithub-action
authored
fix: docs (#445)
Co-authored-by: Rak Laptudirm <[email protected]> Co-authored-by: github-action <${GITHUB_ACTOR}@users.noreply.github.com>
1 parent 6fd8a07 commit 385fe84

File tree

9 files changed

+58
-47
lines changed

9 files changed

+58
-47
lines changed

README.md

+18-16
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,10 @@ Read our [Contribution Guidelines](CONTRIBUTING.md) before you contribute.
9292
1. [`BitCounter`](./math/binary/bitcounter.go#L11): BitCounter - The function returns the number of set bits for an unsigned integer number
9393
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.
9494
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
95-
4. [`MeanUsingAndXor`](./math/binary/arithmeticmean.go#L11): No description provided.
96-
5. [`MeanUsingRightShift`](./math/binary/arithmeticmean.go#L15): No description provided.
95+
4. [`MeanUsingAndXor`](./math/binary/arithmeticmean.go#L12): MeanUsingAndXor This function finds arithmetic mean using "AND" and "XOR" operations
96+
5. [`MeanUsingRightShift`](./math/binary/arithmeticmean.go#L17): MeanUsingRightShift This function finds arithmetic mean using right shift
9797
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.
98-
7. [`XorSearchMissingNumber`](./math/binary/xorsearch.go#L10): No description provided.
98+
7. [`XorSearchMissingNumber`](./math/binary/xorsearch.go#L11): XorSearchMissingNumber This function finds a missing number in a sequence
9999

100100
---
101101
</details><details>
@@ -146,7 +146,7 @@ Read our [Contribution Guidelines](CONTRIBUTING.md) before you contribute.
146146

147147
##### Functions:
148148

149-
1. [`CatalanNumber`](./math/catalan/catalannumber.go#L15): No description provided.
149+
1. [`CatalanNumber`](./math/catalan/catalannumber.go#L16): CatalanNumber This function returns the `nth` Catalan number
150150

151151
---
152152
</details><details>
@@ -197,13 +197,15 @@ Read our [Contribution Guidelines](CONTRIBUTING.md) before you contribute.
197197
---
198198
##### Functions:
199199

200-
1. [`BinaryToDecimal`](./conversion/binarytodecimal.go#L25): BinaryToDecimal() function that will take Binary number as string, and return it's Decimal equivalent as integer.
201-
2. [`DecimalToBinary`](./conversion/decimaltobinary.go#L32): DecimalToBinary() function that will take Decimal number as int, and return it's Binary equivalent as string.
202-
3. [`HEXToRGB`](./conversion/rgbhex.go#L10): HEXToRGB splits an RGB input (e.g. a color in hex format; 0x<color-code>) into the individual components: red, green and blue
203-
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.
204-
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
205-
6. [`Reverse`](./conversion/decimaltobinary.go#L22): Reverse() function that will take string, and returns the reverse of that string.
206-
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.
200+
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
201+
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
202+
3. [`BinaryToDecimal`](./conversion/binarytodecimal.go#L25): BinaryToDecimal() function that will take Binary number as string, and return it's Decimal equivalent as integer.
203+
4. [`DecimalToBinary`](./conversion/decimaltobinary.go#L32): DecimalToBinary() function that will take Decimal number as int, and return it's Binary equivalent as string.
204+
5. [`HEXToRGB`](./conversion/rgbhex.go#L10): HEXToRGB splits an RGB input (e.g. a color in hex format; 0x<color-code>) into the individual components: red, green and blue
205+
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.
206+
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
207+
8. [`Reverse`](./conversion/decimaltobinary.go#L22): Reverse() function that will take string, and returns the reverse of that string.
208+
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.
207209

208210
---
209211
</details><details>
@@ -272,9 +274,9 @@ Read our [Contribution Guidelines](CONTRIBUTING.md) before you contribute.
272274
---
273275
##### Functions:
274276

275-
1. [`BruteForceFactorial`](./math/factorial/factorial.go#L11): No description provided.
276-
2. [`CalculateFactorialUseTree`](./math/factorial/factorial.go#L27): No description provided.
277-
3. [`RecursiveFactorial`](./math/factorial/factorial.go#L19): No description provided.
277+
1. [`Iterative`](./math/factorial/factorial.go#L12): Iterative returns the iteratively brute forced factorial of n
278+
2. [`Recursive`](./math/factorial/factorial.go#L21): Recursive This function recursively computes the factorial of a number
279+
3. [`UsingTree`](./math/factorial/factorial.go#L30): UsingTree This function finds the factorial of a number using a binary tree
278280

279281
---
280282
</details><details>
@@ -505,7 +507,7 @@ Read our [Contribution Guidelines](CONTRIBUTING.md) before you contribute.
505507

506508
##### Functions:
507509

508-
1. [`BitwiseMax`](./math/max/bitwisemax.go#L10): No description provided.
510+
1. [`Bitwise`](./math/max/bitwisemax.go#L11): Bitwise computes using bitwise operator the maximum of all the integer input and returns it
509511
2. [`Int`](./math/max/max.go#L4): Int is a function which returns the maximum of all the integers provided as arguments.
510512

511513
---
@@ -529,7 +531,7 @@ Read our [Contribution Guidelines](CONTRIBUTING.md) before you contribute.
529531

530532
##### Functions:
531533

532-
1. [`Bitwise`](./math/min/bitwisemin.go#L10): No description provided.
534+
1. [`Bitwise`](./math/min/bitwisemin.go#L11): Bitwise This function returns the minimum integer using bit operations
533535
2. [`Int`](./math/min/min.go#L4): Int is a function which returns the minimum of all the integers provided as arguments.
534536

535537
---

math/binary/arithmeticmean.go

+2
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
88
// Package binary describes algorithms that use binary operations for different calculations.
99
package binary
1010

11+
// MeanUsingAndXor This function finds arithmetic mean using "AND" and "XOR" operations
1112
func MeanUsingAndXor(a int, b int) int {
1213
return ((a ^ b) >> 1) + (a & b)
1314
}
1415

16+
// MeanUsingRightShift This function finds arithmetic mean using right shift
1517
func MeanUsingRightShift(a int, b int) int {
1618
return (a + b) >> 1
1719
}

math/binary/xorsearch.go

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
package binary
99

10+
// XorSearchMissingNumber This function finds a missing number in a sequence
1011
func XorSearchMissingNumber(a []int) int {
1112
n := len(a)
1213
result := len(a)

math/catalan/catalannumber.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
f "github.com/TheAlgorithms/Go/math/factorial"
1313
)
1414

15+
// CatalanNumber This function returns the `nth` Catalan number
1516
func CatalanNumber(n int) int {
16-
return f.BruteForceFactorial(n*2) / (f.BruteForceFactorial(n) * f.BruteForceFactorial(n+1))
17+
return f.Iterative(n*2) / (f.Iterative(n) * f.Iterative(n+1))
1718
}

math/factorial/factorial.go

+7-4
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,26 @@
88
// Package factorial describes algorithms Factorials calculations.
99
package factorial
1010

11-
func BruteForceFactorial(n int) int {
11+
// Iterative returns the iteratively brute forced factorial of n
12+
func Iterative(n int) int {
1213
result := 1
1314
for i := 2; i <= n; i++ {
1415
result *= i
1516
}
1617
return result
1718
}
1819

19-
func RecursiveFactorial(n int) int {
20+
// Recursive This function recursively computes the factorial of a number
21+
func Recursive(n int) int {
2022
if n == 1 {
2123
return 1
2224
} else {
23-
return n * RecursiveFactorial(n-1)
25+
return n * Recursive(n-1)
2426
}
2527
}
2628

27-
func CalculateFactorialUseTree(n int) int {
29+
// UsingTree This function finds the factorial of a number using a binary tree
30+
func UsingTree(n int) int {
2831
if n < 0 {
2932
return 0
3033
}

math/factorial/factorial_test.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func TestBruteForceFactorial(t *testing.T) {
3030
tests := getTests()
3131
for _, tv := range tests {
3232
t.Run(tv.name, func(t *testing.T) {
33-
result := BruteForceFactorial(tv.n)
33+
result := Iterative(tv.n)
3434
if result != tv.result {
3535
t.Errorf("Wrong result! Expected:%d, returned:%d ", tv.result, result)
3636
}
@@ -42,7 +42,7 @@ func TestRecursiveFactorial(t *testing.T) {
4242
tests := getTests()
4343
for _, tv := range tests {
4444
t.Run(tv.name, func(t *testing.T) {
45-
result := RecursiveFactorial(tv.n)
45+
result := Recursive(tv.n)
4646
if result != tv.result {
4747
t.Errorf("Wrong result! Expected:%d, returned:%d ", tv.result, result)
4848
}
@@ -54,7 +54,7 @@ func TestCalculateFactorialUseTree(t *testing.T) {
5454
tests := getTests()
5555
for _, tv := range tests {
5656
t.Run(tv.name, func(t *testing.T) {
57-
result := CalculateFactorialUseTree(tv.n)
57+
result := UsingTree(tv.n)
5858
if result != tv.result {
5959
t.Errorf("Wrong result! Expected:%d, returned:%d ", tv.result, result)
6060
}
@@ -64,18 +64,18 @@ func TestCalculateFactorialUseTree(t *testing.T) {
6464

6565
func BenchmarkBruteForceFactorial(b *testing.B) {
6666
for i := 0; i < b.N; i++ {
67-
BruteForceFactorial(10)
67+
Iterative(10)
6868
}
6969
}
7070

7171
func BenchmarkRecursiveFactorial(b *testing.B) {
7272
for i := 0; i < b.N; i++ {
73-
RecursiveFactorial(10)
73+
Recursive(10)
7474
}
7575
}
7676

7777
func BenchmarkCalculateFactorialUseTree(b *testing.B) {
7878
for i := 0; i < b.N; i++ {
79-
RecursiveFactorial(10)
79+
Recursive(10)
8080
}
8181
}

math/max/bitwisemax.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77

88
package max
99

10-
func BitwiseMax(a int, b int, base int) int {
10+
// Bitwise computes using bitwise operator the maximum of all the integer input and returns it
11+
func Bitwise(a int, b int, base int) int {
1112
z := a - b
1213
i := (z >> base) & 1
1314
return a - (i * z)

math/max/bitwisemax_test.go

+19-19
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// bitwiseMax_test.go
2-
// description: Test for BitwiseMax
2+
// description: Test for Bitwise
33
// author(s) [red_byte](https://github.com/i-redbyte)
44
// see bitwiseMax.go
55

@@ -11,67 +11,67 @@ func TestBitwiseMax(t *testing.T) {
1111
base32 := 31
1212

1313
t.Run("Testing(32bit) a = 32 and m = 64: ", func(t *testing.T) {
14-
max := BitwiseMax(32, 64, base32)
14+
max := Bitwise(32, 64, base32)
1515
if max != 64 {
16-
t.Fatalf("Error: BitwiseMax returned bad value")
16+
t.Fatalf("Error: Bitwise returned bad value")
1717
}
1818
})
1919

2020
t.Run("Testing(32bit) a = 1024 and m = -9: ", func(t *testing.T) {
21-
max := BitwiseMax(1024, -9, base32)
21+
max := Bitwise(1024, -9, base32)
2222
if max != 1024 {
23-
t.Fatalf("Error: BitwiseMax returned bad value")
23+
t.Fatalf("Error: Bitwise returned bad value")
2424
}
2525
})
2626

2727
t.Run("Testing(32bit) a = -6 and m = -6: ", func(t *testing.T) {
28-
max := BitwiseMax(-6, -6, base32)
28+
max := Bitwise(-6, -6, base32)
2929
if max != -6 {
30-
t.Fatalf("Error: BitwiseMax returned bad value")
30+
t.Fatalf("Error: Bitwise returned bad value")
3131
}
3232
})
3333

3434
t.Run("Testing(32bit) a = -72 and m = -73: ", func(t *testing.T) {
35-
max := BitwiseMax(-72, -73, base32)
35+
max := Bitwise(-72, -73, base32)
3636
if max != -72 {
37-
t.Fatalf("Error: BitwiseMax returned bad value")
37+
t.Fatalf("Error: Bitwise returned bad value")
3838
}
3939
})
4040

4141
base64 := 63
4242
t.Run("Testing(64bit) a = 32 and m = 9223372036854775807: ", func(t *testing.T) {
43-
max := BitwiseMax(32, 9223372036854775807, base64)
43+
max := Bitwise(32, 9223372036854775807, base64)
4444
if max != 9223372036854775807 {
45-
t.Fatalf("Error: BitwiseMax returned bad value")
45+
t.Fatalf("Error: Bitwise returned bad value")
4646
}
4747
})
4848

4949
t.Run("Testing(64bit) a = 1024 and m = -9223372036854770001: ", func(t *testing.T) {
50-
max := BitwiseMax(1024, -9223372036854770001, base64)
50+
max := Bitwise(1024, -9223372036854770001, base64)
5151
if max != 1024 {
52-
t.Fatalf("Error: BitwiseMax returned bad value")
52+
t.Fatalf("Error: Bitwise returned bad value")
5353
}
5454
})
5555

5656
t.Run("Testing(64bit) a = -6 and m = -6: ", func(t *testing.T) {
57-
max := BitwiseMax(-6, -6, base64)
57+
max := Bitwise(-6, -6, base64)
5858
if max != -6 {
59-
t.Fatalf("Error: BitwiseMax returned bad value")
59+
t.Fatalf("Error: Bitwise returned bad value")
6060
}
6161
})
6262

6363
t.Run("Testing(64bit) a = -4223372036854775809 and m = -4223372036854775808: ", func(t *testing.T) {
64-
max := BitwiseMax(-4223372036854775809, -4223372036854775808, base64)
64+
max := Bitwise(-4223372036854775809, -4223372036854775808, base64)
6565
if max != -4223372036854775808 {
66-
t.Fatalf("Error: BitwiseMax returned bad value")
66+
t.Fatalf("Error: Bitwise returned bad value")
6767
}
6868
})
6969

7070
base8 := 7
7171
t.Run("Testing(8bit) a = 257 and m = 256: ", func(t *testing.T) {
72-
max := BitwiseMax(8, 16, base8)
72+
max := Bitwise(8, 16, base8)
7373
if max != 16 {
74-
t.Fatalf("Error: BitwiseMax returned bad value")
74+
t.Fatalf("Error: Bitwise returned bad value")
7575
}
7676
})
7777
}

math/min/bitwisemin.go

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
package min
99

10+
// Bitwise This function returns the minimum integer using bit operations
1011
func Bitwise(base int, value int, values ...int) int {
1112
min := value
1213
for _, val := range values {

0 commit comments

Comments
 (0)