Problem 2562. Juggling
There is a notation system for jugglers called siteswap
Let consider the simplest version called vanilla siteswap.
A siteswap pattern consist of a list of nonnegative integers being instructions for a juggler.
While juggling, he throws up maximum one ball at the time at given by the pattern height (and then catches it after given periods). 0 means "missing", 1 is passing ball between hands, 2 is keeping ball for a moment (no toss), 3 is cascade toss, etc. (see Wikipedia)
After one full cycle pattern is looped and can be performed continuously. This allows simple patterns to be very short, i.e. classical pattern for three balls noted as 333333... is written by only one 3.
For example pattern 51 uses three balls like that:
and pattern 3 looks like this:
In this problem we will consider such defined patterns. Catching and throwing up to one ball at a time is allowed. Given a vector of integers, determine if it is a valid pattern and return number of balls required (it's an average of pattern) or NaN instead.
Input: [3] Output:[3]
Input: [441] Output:[3]
Input: [521] Output:[NaN] (average is not an integer)
Input: [321] Output:[NaN] (proper average, but balls meet together)
(All illustrations courtesy of Wikipedia)
Solution Stats
Problem Comments
Solution Comments
Show commentsProblem Recent Solvers16
Suggested Problems
-
Calculate the Levenshtein distance between two strings
1445 Solvers
-
130 Solvers
-
The Answer to Life, the Universe, and Everything
536 Solvers
-
Not square-free number sequence
65 Solvers
-
638 Solvers
More from this Author40
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!