Optimizing for readability

I’m trying to write a notebook for two purposes - to teach a little probability theory and to show how kids (middle school) should/could use Observable. I don’t love the viewof/generator stuff in this simple example, but I get the purpose. I’m wondering if folks can see a way to make the bulk flow of the notebook more readable, perhaps hiding more stuff down “at the bottom”?

Then I know I have lots of work to do on pretty pictures and graphs to show them convergence. Maybe I can even throw in some simple ML. :slight_smile:

Not sure how much this helps, but here’s my take on the simulation:

The main difference is that I pinned the cells that perform the simulation so that I can explain how they work. I also refactored it so that the code for running a single simulation is independent of the animation/iteration. Then I used a generator at the end to show how the values converge.

Definitely helped. I’ve restructured more like yours:

But, few more mundane questions now:

  1. Is there a way to detect the strategy checkbox changing and reset the counts?
  2. Is there a way to put a label on that checkbox? If I surround it in label, it blows up the viewof value handling.
  3. Is there a way to only do the runs AFTER the button is clicked? Right now it runs 100 times on load, which makes it less interactive.

Thanks, this is fun!

1. It’s easier if you avoid mutable state… In mine, the cells rerun from scratch whenever something they reference changes, so I don’t have to remember to reset.

2. You can import checkbox from Jeremy’s inputs bazaar for a nice labeled checkbox:

3. Yes, you can define a view that waits for you to click a button. Here is an example: