Public
Edited
Dec 27, 2021
Insert cell
Insert cell
viewof n = Inputs.number({value: 4, label: "Enter the number:"})
Insert cell
steps = []
Insert cell
{
hanoi(n, "One", "Three", "Two")
return steps
}
Insert cell
function hanoi(n, from, to, spare) {
steps.length = 0;
move(n, from, to, spare)
}
Insert cell
function move(n, from, to, spare){
if (n > 0) {
move(n-1, from, spare, to, steps);
steps.push("Move " + n + " from " + from + " to " + to)
move(n-1, spare, to, from, steps);
}
}
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