diff options
| author | Nuno Vieira <nunovieira220@gmail.com> | 2020-12-15 01:18:16 +0000 |
|---|---|---|
| committer | Nuno Vieira <nunovieira220@gmail.com> | 2020-12-15 01:18:16 +0000 |
| commit | 8c297853bfe508c51a73b6ab2ea41dc5ff547edf (patch) | |
| tree | 5aa6a75ec8f23383976001e7202fa53c079a2f84 | |
| parent | cb26c8fcfd81f7a07676c40e39b14d04fb43c118 (diff) | |
| download | perlweeklychallenge-club-8c297853bfe508c51a73b6ab2ea41dc5ff547edf.tar.gz perlweeklychallenge-club-8c297853bfe508c51a73b6ab2ea41dc5ff547edf.tar.bz2 perlweeklychallenge-club-8c297853bfe508c51a73b6ab2ea41dc5ff547edf.zip | |
Add nunovieira220 js solution to challenge 091
| -rw-r--r-- | challenge-091/nunovieira220/js/ch-1.js | 21 | ||||
| -rw-r--r-- | challenge-091/nunovieira220/js/ch-2.js | 24 |
2 files changed, 45 insertions, 0 deletions
diff --git a/challenge-091/nunovieira220/js/ch-1.js b/challenge-091/nunovieira220/js/ch-1.js new file mode 100644 index 0000000000..eda923eea7 --- /dev/null +++ b/challenge-091/nunovieira220/js/ch-1.js @@ -0,0 +1,21 @@ +// Input +const N = 2333445; + +// Count Number +const S = N.toString(); +let res = ""; +let last = S.substring(0, 1); +let counter = 1; + +for (const C of S.substring(1, S.length)) { + if(C != last) { + res += counter+last; + counter = 0; + last = C; + } + + counter++; +} + +// Output +console.log(res + counter + last);
\ No newline at end of file diff --git a/challenge-091/nunovieira220/js/ch-2.js b/challenge-091/nunovieira220/js/ch-2.js new file mode 100644 index 0000000000..a0bb175f1b --- /dev/null +++ b/challenge-091/nunovieira220/js/ch-2.js @@ -0,0 +1,24 @@ +// Input +const A = [2, 1, 3, 0, 3, 1, 5, 0, 0, 0, 0, 2]; + +// Jump Game +if (A.length <= 1) { + console.log(1); + exit(0); +} + +const targets = {}; +targets[A.length - 1] = 1; + +for(let i = A.length - 2; i > 0; i--) { + const jump = i + A[i]; + + if (targets[jump]) { + targets[i] = 1; + } +} + +const res = targets[A[0]] ? 1 : 0; + +// Output +console.log(res);
\ No newline at end of file |
