Skip to content

Commit

Permalink
Merge pull request #83 from pratham0402/pratham
Browse files Browse the repository at this point in the history
Factorial and Tower of hanoi
  • Loading branch information
SahanDisa authored Oct 14, 2021
2 parents 38cf72f + f305ba3 commit cf6aef5
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
21 changes: 21 additions & 0 deletions Algorithms/Recursive Algorithms/Go/factorial.go
Original file line number Diff line number Diff line change
@@ -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))

}
26 changes: 26 additions & 0 deletions Algorithms/Recursive Algorithms/Go/tower_of_hanoi.go
Original file line number Diff line number Diff line change
@@ -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")
}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |✔️ | | | | |
Expand Down

0 comments on commit cf6aef5

Please sign in to comment.