-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhanoi.html
More file actions
29 lines (26 loc) · 956 Bytes
/
Copy pathhanoi.html
File metadata and controls
29 lines (26 loc) · 956 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<!DOCTYPE html>
<html>
<head>
<title>Customized Tower of Hanoi</title>
</head>
<body>
<div id="steps"></div>
<div id="count"></div>
<script>
let count = 0;
function solveTowerOfHanoi(n, source, auxiliary, destination) {
if (n === 1) {
count++;
document.getElementById('steps').innerHTML += 'Move disk 1 from ' + source + ' to ' + destination + '<br>';
return;
}
solveTowerOfHanoi(n - 1, source, destination, auxiliary);
count++;
document.getElementById('steps').innerHTML += 'Move disk ' + n + ' from ' + source + ' to ' + destination + '<br>';
solveTowerOfHanoi(n - 1, auxiliary, source, destination);
}
solveTowerOfHanoi(7, 'A', 'B', 'C');
document.getElementById('count').innerHTML = 'Total moves: ' + count;
</script>
</body>
</html>