Why a Simulator?
Kids these days don't have the time nor the ambition to actually go and stack boxes on the see-saw or play around with balancing physical objects. This leaves lots of room in the software market for a Lever Simulator which will, according to my models, sell like mad!
Programming Help Wanted
I've filed the patent for such a game (pending), but need an expert programmer to write the game-logic for me. From my understanding, it is standard practice to compensate programmers based on the size in bytes of the final program. As such I will be awarding this lucrative contract to the lowest bidder.
Specification
A lever is a series of boxes or empty spaces that is balanced by a fulcrum. Each box has a particular weight one through nine and spaces have no weight. As you know, a box's weight on the lever is directly proportional to how far that box is from the fulcrum. A box of weight 4
that is on the third space from the fulcrum will contribute 12
effective units of force to that side of the lever.
I need a program that, given an input lever, will output whether the lever will skew toward the left, the right, or be perfectly balanced.
I/O Guidelines
- You will write for me a program.
- The input will contain one line of text.
- The input will come from
stdin
or as one command-line string. - Boxes will represented by the characters '
1
' through '9
'. These characters represent their respective weights. An empty space will be represented by a space '^
'.
A sample input lever could look like: 8 2^ 941
This lever is perfectly balanced: (4*8) + 0 + 0 + (1*2) == 0 + (2*9) + (3*4) + (4*1) == 34
- There will be no leading nor trailing spaces. There will be no trailing newline.
- No need to handle malformed input, input will always have exactly one fulcrum, and only numbers and spaces.
- The output will indicate whether the lever is left-heavy, right-heavy, or balanced.
- Your program must have exactly 3 possible outputs that could result from a well-formed input. You can choose what these are.
- The output must either be print to
stdout
or be the return code of the program.
Test cases
Here I use L
,R
,B
to mean left-heavy, right-heavy, balanced:
Input:
11 ^9
Output:B
Input:
321^ 12
Output:L
Input:
9^ 1
Output:R
(If anyone has some "trickier" test cases, feel free to edit them in).
Bibliography
Not-necessarily-inspired-by, but related to Balance a set of weights on a seesaw
The output must either be print to stdout or be the return code of the program.
Well, now you're asking me to make a distribution of Linux which uses seesaw-notation for exit codes. \$\endgroup\$^16
,16^
or^
? (Assume it can) \$\endgroup\$