diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2021-05-31 21:33:39 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-05-31 21:33:39 +0100 |
| commit | 153cc91a07a10ef9c76f2103434f60695877957f (patch) | |
| tree | eceeb1388403ff04db71d1c916bd296aa4d5c2b3 /challenge-115 | |
| parent | 4945e504efdcde92d9df7153a7a4abcc2a916527 (diff) | |
| parent | 955e8e03d21b1d4d71ede93b4c7678c012973e09 (diff) | |
| download | perlweeklychallenge-club-153cc91a07a10ef9c76f2103434f60695877957f.tar.gz perlweeklychallenge-club-153cc91a07a10ef9c76f2103434f60695877957f.tar.bz2 perlweeklychallenge-club-153cc91a07a10ef9c76f2103434f60695877957f.zip | |
Merge pull request #4180 from stuart-little/stuart-little_115_node
1st commit on 115_node
Diffstat (limited to 'challenge-115')
| -rwxr-xr-x | challenge-115/stuart-little/node/ch-1.js | 14 | ||||
| -rwxr-xr-x | challenge-115/stuart-little/node/ch-2.js | 6 |
2 files changed, 20 insertions, 0 deletions
diff --git a/challenge-115/stuart-little/node/ch-1.js b/challenge-115/stuart-little/node/ch-1.js new file mode 100755 index 0000000000..f7dcc6e5b1 --- /dev/null +++ b/challenge-115/stuart-little/node/ch-1.js @@ -0,0 +1,14 @@ +#!/usr/bin/env node + +// run <script> <space-separated strings> + +function canChain(words,start,end) { + if (words.length === 0) {return 0} + if (words.length === 1) { + return 0+(words[0].slice(0,1) === start && words[0].slice(-1) === end) + } + const startIdxs = words.map((el,ix) => ix).filter(ix => words[ix].slice(0,1) === start) + return 0+( startIdxs.map(ix => canChain(words.map((el,ix) => ix).filter(x => x !== ix).map( ix => words[ix] ), words[ix].slice(-1), end)).some(x => x) ) +} + +console.log((process.argv.length < 4) ? (0) : (canChain(process.argv.slice(3), process.argv[2].slice(-1), process.argv[2].slice(0,1)))) diff --git a/challenge-115/stuart-little/node/ch-2.js b/challenge-115/stuart-little/node/ch-2.js new file mode 100755 index 0000000000..27c7a98cb4 --- /dev/null +++ b/challenge-115/stuart-little/node/ch-2.js @@ -0,0 +1,6 @@ +#!/usr/bin/env node + +// run <script> <space-separated digits> + +attemptedOut = process.argv.slice(2).sort().reverse().join("").replace(/(.)([13579]*)$/, '$2$1'); +console.log( (parseInt(attemptedOut) % 2 == 0) ? (attemptedOut) : ("No even digits..") ); |
