Skip to content

Instantly share code, notes, and snippets.

@titanew
Last active December 17, 2015 14:29
Show Gist options
  • Save titanew/5624727 to your computer and use it in GitHub Desktop.
Save titanew/5624727 to your computer and use it in GitHub Desktop.
将1-9共9个数字分成三组,分别组成3个三位数,使这三个三位数构成1:2:3
//1-9组成的三个三位数最小是123,最大是987。
//因为第三个是第一个的三倍,所以第一个数的最大值不可能大于329。
for (var j = 123; j < 330; j++) {
(function(e) {
var f = e * 2,
g = e * 3,
t = e.toString() + f + g,
rg = /0/g,
reg = /(?:^|)(\w{1}).*\1/g;
if (!t.match(rg) && !reg.test(t)) {//去掉含有0的的字符串,去掉还有重复数字的字符串
console.log(e)//输出最小值为e
};
})(j)
};
// 可以得到结果为:
// 192,384,576
// 219,438,657
// 273,546,819
// 327,654,981
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment