Public
Edited
Oct 17, 2022
1 star
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
viewof noOfCombinations1 = Inputs.range([1, combinationValues.length], {label: "Number of combinations", value: 2, step: 1})
Insert cell
Insert cell
Insert cell
function getCombinationsInRange(values, first, select) {
const last = values.length - select
let solutions = []
for (let i = first; i <= last; ++i) {
if (select === 1) {
solutions.push([values[i]])
} else {
for (let combo of getCombinationsInRange(values, i + 1, select - 1)) {
solutions.push([ values[i], ...combo ])
}
}
}

return solutions
}
Insert cell
getCombinationsInRange(combinationValues, 0, noOfCombinations1)
Insert cell
Insert cell
function permutationsWithRepetition(values, occurrences) {
if (occurrences == 1) {
return values
}

const others = permutationsWithRepetition(values, occurrences - 1)
const final = []
for (let value of values) {
for (let other of others) {
if (other.length) {
final.push([value, ...other ])
} else {
final.push([ value, other ])
}
}
}
return final
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
permutationsWithRepetition(getInterval(digitInterval), noDigits)
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more