1.2 KiB
Raw Blame History

id, title, challengeType, videoUrl
id title challengeType videoUrl
59f40b17e79dbf1ab720ed7a 部门编号 5

--description--

有一个高度组织化的城市决定为每个部门分配一个号码:

警察局环卫部门消防部门

每个部门的数字可以在1到7之间

这三个部门编号应该是唯一的彼此不同并且必须加起来为12。

警察局长不喜欢奇怪的号码,并希望他的部门有一个偶数。

任务:

编写一个输出所有有效组合的程序:

[2,3,7]

[2,4,6]

[2,6,4]

[2,7,3]

[4,1,7]

[4,2,6]

[4,3,5]

[4,5,3]

[4,6,2]

[4,7,1]

[6,1,5]

[6,2,4]

[6,4,2]

[6,5,1]

--hints--

combinations应该是一个功能。

assert(typeof combinations === 'function');

combinations([1, 2, 3], 6)应该返回一个数组。

assert(Array.isArray(combinations([1, 2, 3], 6)));

combinations([1, 2, 3, 4, 5, 6, 7], 12)应返回长度为14的数组。

assert(combinations(nums, total).length === len);

combinations([1, 2, 3, 4, 5, 6, 7], 12)应返回所有有效组合。

assert.deepEqual(combinations(nums, total), result);

--solutions--