diff --git a/doitchuu/MakeMinimumValue.js b/doitchuu/MakeMinimumValue.js new file mode 100644 index 0000000..7dbc112 --- /dev/null +++ b/doitchuu/MakeMinimumValue.js @@ -0,0 +1,6 @@ +function solution(A, B) { + const sortedA = A.sort((a, b) => a - b); + const sortedB = B.sort((a, b) => b - a); + + return sortedA.reduce((acc, cur, index) => acc + (cur * sortedB[index]), 0); +} diff --git a/doitchuu/RepeatBinaryTransformation.js b/doitchuu/RepeatBinaryTransformation.js new file mode 100644 index 0000000..9cbedaf --- /dev/null +++ b/doitchuu/RepeatBinaryTransformation.js @@ -0,0 +1,17 @@ +function solution(s) { + if (s === "1") { + return [0, 0]; + } + + let count = 0; + let zeroCount = 0; + + while (s !== "1") { + const length = s.replaceAll("0", "").length; + zeroCount += s.length - length; + s = length.toString(2); + count++; + } + + return [count, zeroCount]; +}