diff options
| author | Nuno Vieira <nunovieira220@gmail.com> | 2020-10-16 21:28:23 +0100 |
|---|---|---|
| committer | Nuno Vieira <nunovieira220@gmail.com> | 2020-10-16 21:28:23 +0100 |
| commit | c75b8f6de3623c7263cc44b26786873da78747bd (patch) | |
| tree | 0274979d6c3c279173611644e802b87a643d40a6 | |
| parent | 6c79809ecc52ebb517c521d9095ae5785e9c1862 (diff) | |
| download | perlweeklychallenge-club-c75b8f6de3623c7263cc44b26786873da78747bd.tar.gz perlweeklychallenge-club-c75b8f6de3623c7263cc44b26786873da78747bd.tar.bz2 perlweeklychallenge-club-c75b8f6de3623c7263cc44b26786873da78747bd.zip | |
Add nunovieira220 js solution to challenge 082
| -rw-r--r-- | challenge-082/nunovieira220/js/ch-1.js | 13 | ||||
| -rw-r--r-- | challenge-082/nunovieira220/js/ch-2.js | 38 |
2 files changed, 51 insertions, 0 deletions
diff --git a/challenge-082/nunovieira220/js/ch-1.js b/challenge-082/nunovieira220/js/ch-1.js new file mode 100644 index 0000000000..6e5b2ef1cf --- /dev/null +++ b/challenge-082/nunovieira220/js/ch-1.js @@ -0,0 +1,13 @@ +// Input +const M = 12; +const N = 18; + +// Common Base String +const res = []; + +for (let i = 1; i < Math.min(M, N); i++) { + if(M % i === 0 && N % i == 0) res.push(i); +} + +// Output +console.log(res);
\ No newline at end of file diff --git a/challenge-082/nunovieira220/js/ch-2.js b/challenge-082/nunovieira220/js/ch-2.js new file mode 100644 index 0000000000..67c8bf2f59 --- /dev/null +++ b/challenge-082/nunovieira220/js/ch-2.js @@ -0,0 +1,38 @@ +// Interleave +const interleave = (A, B, C) => { + if(A.length + B.length !== C.length) { + return 0; + } + + return interleaveChecker(A, B, C); +} + +// Interleave checker +const interleaveChecker = (A, B, C) => { + if(!C) return 1; + + const a = A.charAt(0); + const b = B.charAt(0); + const c = C.charAt(0); + let firstTree = 0; + let secondTree = 0; + + if(a === c) { + firstTree = interleaveChecker(A.substring(1), B, C.substring(1)); + } + + if(b === c) { + secondTree = interleaveChecker(A, B.substring(1), C.substring(1)) + } + + return firstTree + secondTree > 0 | 0; +} + +// Input +const A = 'XXY'; +const B = 'XXZ'; +const C = 'XXXXZY'; + +// Output +console.log(interleave(A, B, C)); + |
