diff --git a/Algorithms/Recursive Algorithms/Go/factorial.go b/Algorithms/Recursive Algorithms/Go/factorial.go new file mode 100644 index 0000000..cab4d08 --- /dev/null +++ b/Algorithms/Recursive Algorithms/Go/factorial.go @@ -0,0 +1,21 @@ +package main + +import "fmt" + +func factorial(num int) int { + if num == 0 || num == 1 { + return 1 + } + return num * factorial(num-1) +} + +func main() { + + var num int + + fmt.Print("Enter the number : ") + fmt.Scanln(&num) + fmt.Print("Factorial of given number : ") + fmt.Print(factorial(num)) + +} diff --git a/Algorithms/Recursive Algorithms/Go/tower_of_hanoi.go b/Algorithms/Recursive Algorithms/Go/tower_of_hanoi.go new file mode 100644 index 0000000..b81b0eb --- /dev/null +++ b/Algorithms/Recursive Algorithms/Go/tower_of_hanoi.go @@ -0,0 +1,26 @@ +package main + +import ( + "fmt" + "strconv" +) + +func TOH_moves(num int, start, inter, end string) { + if num == 1 { + fmt.Println("Move disk 1 from " + start + " to " + end) + return + } + TOH_moves(num-1, start, end, inter) + fmt.Println("Move disk " + strconv.Itoa(num) + " from " + start + " to " + end) //strconv.Itoa() used for type casting int to string + TOH_moves(num-1, inter, end, start) + +} + +func main() { + + var num int + + fmt.Print("Enter the number of disk : ") + fmt.Scanln(&num) + TOH_moves(num, "A", "B", "C") +} diff --git a/README.md b/README.md index 82fc52f..e4baf88 100644 --- a/README.md +++ b/README.md @@ -81,8 +81,8 @@ Binary Search | |✔️| ✔️| ✔️ | | |✔ Section/Language | C | C++ | Java | Python | Javascript | Scala | Go | -----------------|----|-----|------|--------|------------|-------| -- | Fibonacci |✔️ | | |✔️ | | | -Factorial |✔️ | | | ✔️ | | | -Tower of Hanoi |✔️ | | | | | | +Factorial |✔️ | | | ✔️ | | | | ✔️ | +Tower of Hanoi |✔️ | | | | | | | ✔️ | GCD |✔️ | | | | | | | ✔️ | LCM | | | | | | Pacal Traingle |✔️ | | | | |