SpinalHDL
Description
The Occupation Lottery
Japan, 1947. The Allied occupation authority has a problem. Pachinko parlors are spreading across the country, operating in a legal grey area between gambling and "amusement." General MacArthur's economic advisors worry that rigged machines could be used for black market currency manipulation.
Your unit has been tasked with developing a certification system. A machine is considered "fair" if it has sufficient outcome diversity - that is, if a ball dropped from the top can take many different paths to the bottom.
A pachinko board is a vertical grid. A ball enters from the top at a given column position and falls downward due to gravity. The board contains pegs (marked ^). When a ball strikes a peg, it deflects either left or right, then continues falling. Empty spaces (.) offer no resistance - the ball passes straight through.
Consider this simple board where the ball starts at column 4:
....S....
.........
....^....
.........
...^.^...
.........
The ball falls straight down until it hits the first peg:
....S....
....|....
....^....
.........
...^.^...
.........
At the peg, the ball must go either left OR right. This creates two possible paths:
Path A (left): Path B (right):
....S.... ....S....
....|.... ....|....
...|^.... ....^|...
...|..... .....|...
...^.^... ...^.^...
......... .........
Each path then continues down and hits another peg, splitting again:
From Path A: From Path B:
...|^.... ....^|...
...|..... .....|...
..|^|^... ...^|^|..
..|.|.... ....|.|..
The four final paths exit at columns 2, 4, 4, and 6. Note that two paths converge at column 4, but they count separately because they took different routes to get there.
Outcome diversity is the total number of distinct paths from entry to exit. In this example, the answer is 4.
Given a pachinko board schematic (max 128x128), calculate the outcome diversity.