A long time ago, in a city far, far away...I was a junior developer with big ambitions. I applied for a development role a bit out of my league but I thought I could pull it off. Unfortunately, the very simple coding test I was presented in teh on-site interview completely stumped me.
I have relieved the horror of this day over and over in my dreams. The failure completely haunts me. And so, I have made it my personal goal to solve this coding problem in every new language I pick up.
The problem was simple, and i'm still amazed that it stumped me at that point in my career: Build a bowling calcluator.
A frame's score is the sum of all throws in the frame.
A spare is 10 + the next throw
A strike is 10 + the next two throws.
On the 10th frame, if the player gets a spare or a strike, they get a third throw.
[
[ 10 ], // 30
[ 10 ], // 30
[ 10 ], // 30
[ 10 ], // 30
[ 10 ], // 30
[ 10 ], // 30
[ 10 ], // 30
[ 10 ], // 30
[ 10 ], // 30
[ 10, 10, 10 ] // 30
]
Score: 300
[
[8, 2], // 15
[5, 5], // 12
[2, 8], // 11
[1, 9], // 19
[9, 1], // 13
[3, 7], // 16
[6, 4], // 14
[4, 6], // 11
[1,9], // 19
[9, 1, 5] // 15
]
Score: 146
[
[1, 4], // 5
[2, 6], // 8
[8, 0], // 8
[9, 0], // 9
[10], // 13
[1, 2], // 3
[10], // 28
[10], // 20
[8, 2], // 15
[5, 5, 2] // 12
]
Score: 121
If you click the link you can see my solution in PHP, and I'll update the description here shortly to include some explanations on what I chose to do.