We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 8e4f8ef commit 3f11705Copy full SHA for 3f11705
Medium Difficulty/stringReduction2.js
@@ -0,0 +1,29 @@
1
+// coderbyte solution for string reduction
2
+// splashinn
3
+
4
+function reduce(str){
5
+ str = str.replace(/ab/, "c")
6
+ .replace(/ba/, "c")
7
+ .replace(/ac/, "b")
8
+ .replace(/ca/, "b")
9
+ .replace(/bc/, "a")
10
+ .replace(/cb/, "a");
11
+ return str;
12
+}
13
14
+function irreducible(str) {
15
+ var str = str.split("");
16
+ for (var i = 1; i < str.length; i++) {
17
+ if (str[i] != str[i-1]) return false;
18
+ }
19
+ return true;
20
21
22
+function StringReduction(str) {
23
+ do {
24
+ str = reduce(str);
25
+ } while (str != reduce(str));
26
27
+ return str.length;
28
29
0 commit comments