forked from CodeMaster7000/Number-Rotations
-
Notifications
You must be signed in to change notification settings - Fork 0
/
K-Cycles.html
35 lines (35 loc) · 1.47 KB
/
K-Cycles.html
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
30
31
32
33
34
35
<!DOCTYPE html>
<html>
<head>
<title>K-Cycles Checker</title>
</head>
<body>
<script>
function CheckKCycles(n, s) {
var ff = true;
var x = 0;
document.write("All K-shifts:<br>");
for (var i = 0; i < n; i++) {
// Splitting the number at index i, and adding to the front
var shifted = s.substring(i) + s.substring(0, i);
x = shifted.length;
document.write(shifted + "<br>");
// Checking if the outputted is greater than or equal to the element itself.
if (x >= s.length) {
continue;
}
ff = false;
break;
}
if (ff) {
document.write("<br>K-cycle shifts are larger than the element.");
} else {
document.write("<br>K-cycle shifts are not larger than the element.");
}
}
var s = prompt("Enter the number string (s):");
var n = parseInt(prompt("Enter the number of digits (n):"));
CheckKCycles(n, s);
</script>
</body>
</html>