I've been solving this problem for 2 hours now and can't seem to figure out how to count by the pattern.
Pattern:
1-1-1
1-1-2
1-2-1
1-2-2
2-1-1
2-1-2
2-2-1
2-2-2
And so on...
The easiest way I think is to use that pattern as a two demonsional array, make a function that just loops over each number and just add the desired number, note that the pattern then should start with 0, here is a live example
let myPattern = [
[0,0,0], [0,0,1], [0,1,0], [0,1,1],
[1,0,0], [1,0,1], [1,1,0], [1,1,1]
];
function generateGroupPattern(pattern, n) {
return pattern.map(p => p.map(sp => sp + n - 1));
}
console.log(generateGroupPattern(myPattern, 1).join("\n"));
console.log(generateGroupPattern(myPattern, 5).join("\n"));
console.log(generateGroupPattern(myPattern, 6).join("\n"));
// use a loop for example
for(let i = 1; i < 5; i++) {
console.log(generateGroupPattern(myPattern, i).join("\n"));
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With