Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Coprime ¶
Coprime test whether `a` and `b` are relatively prime integers.
Example ¶
package main import ( "fmt" algorithms "github.com/yefremov/algorithms-with-go" ) func main() { fmt.Println(algorithms.Coprime(1, 1)) fmt.Println(algorithms.Coprime(2, 2)) fmt.Println(algorithms.Coprime(13, 27)) fmt.Println(algorithms.Coprime(20536, 7826)) }
Output: true false true false
func Fac ¶
Fac gets factorial value of `n`.
Example ¶
package main import ( "fmt" algorithms "github.com/yefremov/algorithms-with-go" ) func main() { for i := 0; i < 6; i++ { fmt.Println(algorithms.Fac(i)) } }
Output: 1 1 2 6 24 120
func Fib ¶
Fib gets fibonacci value of `n`.
Example ¶
package main import ( "fmt" algorithms "github.com/yefremov/algorithms-with-go" ) func main() { for i := 0; i < 6; i++ { fmt.Println(algorithms.Fib(i)) } }
Output: 1 1 2 3 5 8
func Gcd ¶
Gcd gets greatest common divisor of `a` and `b`.
Example ¶
package main import ( "fmt" algorithms "github.com/yefremov/algorithms-with-go" ) func main() { fmt.Println(algorithms.Gcd(468, 24)) fmt.Println(algorithms.Gcd(135, 19)) fmt.Println(algorithms.Gcd(19, 2)) fmt.Println(algorithms.Gcd(20536, 7826)) }
Output: 12 1 1 2
func MaxSub ¶
MaxSub Finds the maximum sum of the elements of a subarray in a given `array`.
Example ¶
package main import ( "fmt" algorithms "github.com/yefremov/algorithms-with-go" ) func main() { fmt.Println(algorithms.MaxSub([]int{-2, 1, -3, 4, -1, 2, 1, -5, 4})) }
Output: 6
func SearchBinary ¶
SearchBinary searches for a `needle` in `haystack`.
Example ¶
package main import ( "fmt" algorithms "github.com/yefremov/algorithms-with-go" ) func main() { fmt.Println(algorithms.SearchBinary([]int{1, 2, 3}, 2)) fmt.Println(algorithms.SearchBinary([]int{1, 2, 3}, 4)) }
Output: true false
func SearchLinear ¶
SearchLinear searches for a `needle` in a `haystack`.
Example ¶
package main import ( "fmt" algorithms "github.com/yefremov/algorithms-with-go" ) func main() { fmt.Println(algorithms.SearchLinear([]int{1, 2, 3}, 2)) fmt.Println(algorithms.SearchLinear([]int{1, 2, 3}, 4)) }
Output: true false
func SortBubble ¶
SortBubble sorts numbers array in ascending order.
Example ¶
package main import ( "fmt" algorithms "github.com/yefremov/algorithms-with-go" ) func main() { fmt.Println(algorithms.SortBubble([]int{3, 3, 7, 1})) }
Output: [1 3 3 7]
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.