Pascal's Bagatelle Beginner Coder Challenge
Well i quite liked this one, i saw a maths demo on TV the other day, and thought it would be neat to write, then saw it actually makes for a good little programming problem for beginners methinks.
As I say, I am aiming it at beginners to have a go at. it is probably trivial for more advanced coders, but might provide some interest, I dont really consider myself advanced, but i know this has thrown up some wider project ideas for me at least.
Am keeping open for two weeks, winner is first correct working code sent to me by PM. That satisfies the requirements.
Output validation will be based on the expected distribution for the given parameters.
Sorry i can only accept win console.
Limit of 100 lines actual code, which should be plenty.
C or C++
It is worked around Pascal's triangle but as if it were set in a Bagatelle board where you ping a ball up like pinball and then it drops down into a field of pins and you win money depending where it lands.
This problem requires you to model the outcome of such a game in terms of the landing position of the ball.
As each new ball is dropped into the field then it will bounce off the pins and enventually end up in one of the columns at the bottom, see image:
In the image shown there are 4 columns for this size 'pin field', the arrow shows where a ball is dropped in, then it hits the first pin, and so on, until it finally lands in one of the four possible columns.
Your challenge is to write a program that can simulate this game and show the expected distribution of balls across the columns.
Your program must accept input for the base triangle size, (in the example this would be 3, ie three pins) and successfully show the outcome for the resulting number of columns required for the given base size.
That is to say your program must be able to scale its operation to any size field..
I am not asking for input validation as such, but it should be obvious that the minimum input has to be two.
set number of balls as twenty times your base input, this is just to keep the distribution values up.
Your output must be stored in an array, vector, or other container,number of elements equal to the columns required. - no bigger.
Display output will be:
A simple win console
request input triangle base size
display the value.
display the ball count
//start working part of program..
The final display should just be a loop outputting each value in the container.with a pipe seperator
follwed by a sum of the column values which should be equal to the amount of balls used.
so it might look like:
for(int i = 0; i < columns; i++)
//print columns[i] and seperator
//add columns[i] to check_total
//print check_total =
input base: 5
ball count 100
| 2 | 16 | 27 | 36 | 14 | 5 |
check total balls distributed: 100