SpinalHDL
1 / 1
View past submissionsLeaderboard

Description

Roulette

You walk into a high-stakes casino with one goal: break the house.

The roulette wheel has 100 pockets numbered 0 through 99. The ball starts at pocket 50. A sequence of spins determines where it lands next.

Each spin is a signed integer: positive spins toward higher numbers, negative spins toward lower numbers. The wheel wraps around: spinning past 99 continues from 0, spinning past 0 continues from 99.

You've been counting. You know the house bleeds money every time the ball crosses zero—not just when it lands there, but every single time it passes through.

Given the spin sequence, count the total number of times the ball lands on or passes through pocket 0.

Example: Starting at 50 with spins [55, -10, 60, -110]:

  • 55 → 5 (crosses 0 once)
  • -10 → 95 (crosses 0 once)
  • 60 → 55 (crosses 0 once)
  • -110 → 45 (crosses 0 once)

Answer: 4

Input

spins

Stream of 16-bit Signed Integer
Spin sequence (positive=right, negative=left).

Output

16-bit Unsigned Integer
Total times ball lands on or passes through pocket 0.