diff options
| author | chirvasitua <stuart-little@users.noreply.github.com> | 2021-05-31 11:48:14 -0400 |
|---|---|---|
| committer | chirvasitua <stuart-little@users.noreply.github.com> | 2021-05-31 11:48:14 -0400 |
| commit | 955e8e03d21b1d4d71ede93b4c7678c012973e09 (patch) | |
| tree | 097799a93f044e649583055538a2fab35eb13e5f | |
| parent | 4d46176ccf4080081fde9a1a4aa3ec2f6feb52f8 (diff) | |
| download | perlweeklychallenge-club-955e8e03d21b1d4d71ede93b4c7678c012973e09.tar.gz perlweeklychallenge-club-955e8e03d21b1d4d71ede93b4c7678c012973e09.tar.bz2 perlweeklychallenge-club-955e8e03d21b1d4d71ede93b4c7678c012973e09.zip | |
1st commit on 115_node
| -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..") ); |
