Skip to content

Commit cf6aef5

Browse files
authored
Merge pull request #83 from pratham0402/pratham
Factorial and Tower of hanoi
2 parents 38cf72f + f305ba3 commit cf6aef5

File tree

3 files changed

+49
-2
lines changed

3 files changed

+49
-2
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package main
2+
3+
import "fmt"
4+
5+
func factorial(num int) int {
6+
if num == 0 || num == 1 {
7+
return 1
8+
}
9+
return num * factorial(num-1)
10+
}
11+
12+
func main() {
13+
14+
var num int
15+
16+
fmt.Print("Enter the number : ")
17+
fmt.Scanln(&num)
18+
fmt.Print("Factorial of given number : ")
19+
fmt.Print(factorial(num))
20+
21+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"strconv"
6+
)
7+
8+
func TOH_moves(num int, start, inter, end string) {
9+
if num == 1 {
10+
fmt.Println("Move disk 1 from " + start + " to " + end)
11+
return
12+
}
13+
TOH_moves(num-1, start, end, inter)
14+
fmt.Println("Move disk " + strconv.Itoa(num) + " from " + start + " to " + end) //strconv.Itoa() used for type casting int to string
15+
TOH_moves(num-1, inter, end, start)
16+
17+
}
18+
19+
func main() {
20+
21+
var num int
22+
23+
fmt.Print("Enter the number of disk : ")
24+
fmt.Scanln(&num)
25+
TOH_moves(num, "A", "B", "C")
26+
}

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ Binary Search | |✔️| ✔️| ✔️ | | |✔
8181
Section/Language | C | C++ | Java | Python | Javascript | Scala | Go |
8282
-----------------|----|-----|------|--------|------------|-------| -- |
8383
Fibonacci |✔️ | | |✔️ | | |
84-
Factorial |✔️ | | | ✔️ | | |
85-
Tower of Hanoi |✔️ | | | | | |
84+
Factorial |✔️ | | | ✔️ | | | | ✔️ |
85+
Tower of Hanoi |✔️ | | | | | | | ✔️ |
8686
GCD |✔️ | | | | | | | ✔️ |
8787
LCM | | | | | |
8888
Pacal Traingle |✔️ | | | | |

0 commit comments

Comments
 (0)