The challenge
Given a bagatelle board like the one below:
| |
| /\ / |
| \ /|
| \ \ /\ \ |
| \ / \ |
|\ / / \ |
| \ / \ |
| \ |
| \ / \ /\ \ |
|\ / / \ /|
| / |
| /\ / / |
| / |
|\ / / / |
| |
----------------------
your task is to turn a list of 'throws' into a score.
The board will always be 20 characters (plus 2 edges) wide, but of variable height. Each 'throw' is a number representing where the ball falls into the board, starting at 0 for the far left up to 19 for the far right. Each ball will fall straight down unless it encounters a /
or a \
. Encountering a /
shifts the ball one column to the left, and a \
shifts the ball one column to the right. After being shifted, the ball continues straight down as before. The score for a throw is dependant on where the ball hits the bottom of the board.
The scores for each finishing position are as follows:
| |
----------------------
01234567899876543210
and are the same for all boards. The first and last rows will always be empty. The ball is guaranteed to reach the bottom regardless of where it is dropped from, so there will be no boards where it can get trapped by \/
,\|
or |/
combinations.
Input
Input will be on STDIN, and will consist of the board followed by a blank line followed by a space separated list of numbers representing the throws.
Output
Ouput should be the total score for the given game.
A couple of examples
Input
| |
| \ |
| \ |
| \ |
| \ |
| \ |
| \ |
| \ |
| \ |
| \ |
| \ |
| \ |
| \ |
| \ |
| \ |
| \ |
| \ |
| \ |
| |
| |
----------------------
1 4 2 19 0 2 4 3 17 13 16
Output
9
Input
| |
| \ / |
| \ / |
| \ / |
| \ / |
| \ / |
| \ / |
| \ / |
| \ / |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
----------------------
15 10 3 8 18 19 0 6 7 10
Output
72
Input
| |
| ////////////////// |
| \\\\\\\\\\\\\\\\\\ |
| ////////////////// |
| \\\\\\\\\\\\\\\\\\ |
| ////////////////// |
| \\\\\\\\\\\\\\\\\\ |
| ////////////////// |
| \\\\\\\\\\\\\\\\\\ |
| ////////////////// |
| \\\\\\\\\\\\\\\\\\ |
| |
----------------------
1 4 18 17 14 2 0 19 15
Output
18
Test scripts
I've used some test scripts written by Joey and Ventero (I hope they don't mind...) to create some tests for this task:-
Usage: ./test [your program and its arguments]
This is codegolf - shortest solution wins.