We’ve built a tool that uses AI to automatically create unit tests for any Java code entered into it. A little known capability of this tool is that it can do more than help you juggle writing tests and developing new code; we have discovered that it can also be used to create brand new juggling tricks.
The Math of Juggling
It might not be obvious that juggling tricks can be described mathematically, but that’s exactly what the siteswap notation does. Siteswap is a way of writing down juggling tricks as a sequence of numbers, like 531 or 552. Different numbers correspond to throwing the juggling balls to different heights: higher numbers represent higher throws. The number of balls needed for the trick is the average of the numbers, so 531 is a 3-ball trick and 552 is a 4-ball trick.
A fun aspect of this method is that it can also be used to invent new tricks: come up with a sequence of numbers and then try to juggle it. This always works as long as the numbers satisfy the condition “two balls don’t land in the same hand at the same time.” Lots of new juggling tricks that are now totally standard were originally invented by coming up with a valid siteswap and trying to juggle it.
Can AI generate valid siteswaps?
As it turns out, our tool (Diffblue Cover) can come up with new tricks using a Java function that takes an array of integers, checks that they aren’t negative, and asserts that they satisfy the condition for a valid trick. This generates a unit test that involves feeding a valid siteswap into the function:
The first time it came up with 31411. An attempt at this with juggling balls showed that it’s a nice little two-ball trick. In fact, it was a much nicer trick than someone might typically make up. Here is a visualization courtesy of this siteswap animator, which illustrates any trick you enter:
By slightly changing the input for the Java function to make Diffblue Cover choose different random guesses, it produced more juggling tricks: 124245 (3 balls, a trick we’d never seen before) and 51 (a 3-ball shower, one of the oldest juggling tricks around). The difficulty varies, but all of the tricks produced are physically possible to do.
Get a free trial and come up with new tricks yourself! You can use the above animator to see how they look, and give it a go with a few juggling balls. We’re curious to see the hardest AI-generated trick someone can perform—share it with us on Twitter!