Skip to content

Commit

Permalink
day 16 (#159)
Browse files Browse the repository at this point in the history
  • Loading branch information
Spreeha authored and MadhavBahl committed Jan 12, 2019
1 parent 2740368 commit 60ab08d
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
36 changes: 36 additions & 0 deletions day16/Java/towersOfHanoi.java
@@ -0,0 +1,36 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package recursion;

/**
* @date 10/01/19
* @author SPREEHA DUTTA
*/
import java.util.*;
public class towersOfHanoi {
public static void move(int n,char s,char d,char c)
{
if(n==1)
{
System.out.println("Move disk "+n+" from "+s+" to "+d);
return;
}
else
{
move(n-1,s,c,d);
System.out.println("Move disk "+n+" from "+s+" to "+d);
move(n-1,c,d,s);
}
}
public static void main(String []args)
{
Scanner sc=new Scanner(System.in);
int n; char start='S';char center='C'; char destination='D';
System.out.println("Enter number of disks");
n=sc.nextInt();
move(n,start,destination,center);
}
}
38 changes: 38 additions & 0 deletions day16/README.md
Expand Up @@ -46,6 +46,44 @@ console.log ('\n/* ===== for 3 disks ===== */');
towerOfHanoi (3, 'A', 'C', 'B');
```

## Java Implementation

### [Solution](./Java/towersOfHanoi.java)

```java
/**
* @date 10/01/19
* @author SPREEHA DUTTA
*/
import java.util.*;
public class towersOfHanoi
{
public static void move(int n,char s,char d,char c)
{
if(n==1)
{
System.out.println("Move disk "+n+" from "+s+" to "+d);
return;
}
else
{
move(n-1,s,c,d);
System.out.println("Move disk "+n+" from "+s+" to "+d);
move(n-1,c,d,s);
}
}
public static void main(String []args)
{
Scanner sc=new Scanner(System.in);
int n; char start='S';char center='C'; char destination='D';
System.out.println("Enter number of disks");
n=sc.nextInt();
move(n,start,destination,center);
}
}
}
```

## Ruby Implementation

### [Solution](./Ruby/hanoi.rb)
Expand Down

0 comments on commit 60ab08d

Please sign in to comment.