🌍 Become a marimo ambassador!

Apply
78 / 103
Beyond Rock, Paper, Scissors

Beyond Rock, Paper, Scissors

by marimo team

Explore why fair games require an odd number of elements through interactive game theory math.

About this notebook

This notebook studies fair variants of Rock-Paper-Scissors. Rock-Paper- Scissors has 3 elements. Rock-Paper-Scissors-Lizard-Spock has 5. The notebook asks if a fair game can use 4 or 6 elements. A game is fair when every element beats the same number of others. With n elements, each element must beat k equal to (n minus 1) divided by 2 others. That value is a whole number only when n is odd. The notebook uses marimo, a custom RpslsWidget built with anywidget, and the KeystrokeWidget from wigglystuff.

The RpslsWidget draws the elements as nodes in a diagram. A KeystrokeWidget reads your keyboard input. Click in the keyboard widget area first. The right and left arrow keys animate a node forward or backward. The up and down arrow keys move a highlight around the elements. The "q" key clears the highlight. The notebook stores the highlight index with marimo state, so the diagram updates as you press keys.

The RpslsWidget is set to n equal to 3 at the start. Each keypress calls a method on the widget, such as animate_node or animate_highlight. The notebook reads the last key from the KeystrokeWidget and maps it to one of these actions. Letters A to Z label the highlighted elements.

Related notebooks