Anonymous user
Nonoblock: Difference between revisions
m
Handle the case where there is a full line.
m (Handle the case where there is a full line.) |
|||
Line 907:
=={{header|JavaScript}}==
<lang javascript>const
const inv = b => !b;
const arrJoin = str => arr => arr.join(str);
const mkArr = (l, f) => Array(l).fill(f);
const sumArr = arr => arr.reduce((a, b) => a + b, 0);
const sumsTo = val => arr => sumArr(arr) === val;
Line 914 ⟶ 917:
const zipArr = arr => a => zip(a, arr);
const hasInner = v => arr => arr.slice(1, -1).indexOf(v) >= 0;
const noInnerZero = e => !hasInner(0)(e);▼
const choose = (even, odd) => n => n % 2 === 0 ? even : odd;
const toBin = f => arr => arr.reduce(
Line 931 ⟶ 933:
};
const permutations = (grpSize,
const maxVal =
const sumsToTrg = sumsTo(numGaps);
const hasInnerZero = hasInner(0);
return maxVal <= 0 ? [] : (looper(mkArr(grpSize, minVal), maxVal)[1])
.filter(
.filter(
}
Line 941 ⟶ 946:
console.log(`\n${cells} cells. Blocks: ${blocks}`);
const grpSize = blocks.length + 1;
const
const
const combine = zipArr([...blocks]);
.map(combine)▼
const output = compose(console.log, arrJoin(''));
▲ .map(toBin(choose(0,1)))
const res = fullLine ? [[0, cells]].map(choices)
: permutations(grpSize, numGaps).map(compose(choices, combine));
};
test(5, 2, 1);
test(5);
test(5, 5);
test(5, 1, 1, 1);
test(10, 8);
Line 959 ⟶ 966:
</lang>
{{out}}
<pre>5 cells. Blocks: 2,1▼
▲5 cells. Blocks: 2,1
11010
11001
Line 967 ⟶ 973:
5 cells. Blocks:
00000
5 cells. Blocks: 5
11111
5 cells. Blocks: 1,1,1
Line 1,002 ⟶ 1,011:
5 cells. Blocks: 2,3
</pre>
|