# Ad Hoc Problems

Ad Hoc problems are those require specific solutions.

# Exercises

# LC330 - Patching Array (opens new window)

# Kattis - Juggling Patterns (opens new window)

Hint

See this section (opens new window) of Siteswap's Wiki.

Code (Python 3)
import sys

for raw_line in sys.stdin:
    line = raw_line.strip()
    tot = sum([int(i) for i in line])
    n = len(line)
    if tot % n != 0:
        print('{}: invalid # of balls'.format(line))
        continue
    balls = tot // n
    s = set()
    ok = True
    for i, c in enumerate(line):
        s.add((i + int(c)) % n)
    if len(s) == n:
        print('{}: valid with {} balls'.format(line, balls))
    else:
        print('{}: invalid pattern'.format(line))
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18