# 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

37.5% Correct | 62.5% Incorrect
Last Solution submitted on Feb 04, 2024

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!