diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2021-08-04 06:00:40 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-08-04 06:00:40 +0100 |
| commit | 0f55059eb11daf54c0af122d1ffb099443ee3dcb (patch) | |
| tree | 6a7bfc56fadbf8c9bbb69fcc5f1f9c1afd75538a | |
| parent | 07a47a72dc17d1416860fb6f87369358635ceddd (diff) | |
| parent | a136e4532222902b29939c840d98978c3ce9f24f (diff) | |
| download | perlweeklychallenge-club-0f55059eb11daf54c0af122d1ffb099443ee3dcb.tar.gz perlweeklychallenge-club-0f55059eb11daf54c0af122d1ffb099443ee3dcb.tar.bz2 perlweeklychallenge-club-0f55059eb11daf54c0af122d1ffb099443ee3dcb.zip | |
Merge pull request #4656 from stuart-little/stuart-little_124_node
1st commit on 124_node
| -rwxr-xr-x | challenge-124/stuart-little/node/ch-1.js | 23 | ||||
| -rwxr-xr-x | challenge-124/stuart-little/node/ch-2.js | 15 |
2 files changed, 38 insertions, 0 deletions
diff --git a/challenge-124/stuart-little/node/ch-1.js b/challenge-124/stuart-little/node/ch-1.js new file mode 100755 index 0000000000..3a5c70ff8f --- /dev/null +++ b/challenge-124/stuart-little/node/ch-1.js @@ -0,0 +1,23 @@ +#!/usr/bin/env node + +// run <script> + +console.log(` + ^^^^^ + ^ ^ + ^ ^ + ^ ^ + ^ ^ + ^ ^ + ^ ^ + ^ ^ + ^ ^ + ^ ^ + ^^^^^ + ^ + ^ + ^ + ^^^^^ + ^ + ^ +`) diff --git a/challenge-124/stuart-little/node/ch-2.js b/challenge-124/stuart-little/node/ch-2.js new file mode 100755 index 0000000000..70aaa0deeb --- /dev/null +++ b/challenge-124/stuart-little/node/ch-2.js @@ -0,0 +1,15 @@ +#!/usr/bin/env node + +// run <script> <space-separated numbers> + +const { minBy, sum } = require('lodash') +const { difference } = require('set-operations') +const ps = require('power-set-x').default + +function splt(nums) { + return minBy(ps(nums).filter(x => x.length === Math.floor(nums.length/2)).map(x => [x, Array.from(difference(nums,x))]), x => Math.abs(sum(x[0])-sum(x[1]))) +} + +const [l,r] = splt(process.argv.slice(2).map(x => parseInt(x))) +console.log(l) +console.log(r) |
