What programming language you start with really all depends on where you want to go with programming/coding. The great thing about this field is that there are an absolute abundance of smaller fields that you can go into, all using programming in their own unique ways. For web applications, a good start would be with HTML and later moving your way through CSS, JavaScript, JQuery, PHP, SQL, and any of the JavaScript libraries. Ruby is also a popular choice, so I would recommend checking that out too. For more scientific fields or areas with more machine learning and A.I., Python is generally a great place to start as it is widely used in that field of study. C++ is also a very useful language to know for that, but it can be a little more challenging for beginners. For game and application design, languages such as C#, C, Swift, Kotlin, and Java are most often used for that.
Description
Today's challenge will be a variation on a popular introductory programming task, scoring a game of bowling. However, in this challenge, we won't even actually have to calculate the score. Today's challenge is to produce the display for the individual frames, given a list of the number of pins knocked down on each frame.
The basic rules are as follows:
The game of bowling consists of 10 frames, where a player gets 2 attempts to knock down 10 pins.
If the player knocks down all 10 pins on the first roll, that should be displayed as X, and the next number will be the first roll of the next frame.
If the player doesn't knock down any pins, that should be displayed as -
If the player gets a spare (knocks down the remaining pins on the second roll of the frame, that should be displayed as /
If you want more details about the rules, see: Challenge #235 [Intermediate] Scoring a Bowling Game
Input Description
You will be given a list of integers that represent the number of pins knocked down on each roll. Not that this list is not a fixed size, as bowling a perfect game requires only 12 rolls, while most games would use more rolls.
Example:
6 4 5 3 10 10 8 1 8 0 10 6 3 7 3 5 3
Output Description
Your program should output the bowling frames including strikes and spares. The total score is not necessary.
Example:
6/ 53 X X 81 8- X 63 7/ 53
Challenge Inputs
9 0 9 0 9 0 9 0 9 0 9 0 9 0 9 0 9 0 9 0
10 10 10 10 10 10 10 10 10 10 10 10
5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5
10 3 7 6 1 10 10 10 2 8 9 0 7 3 10 10 10
9 0 3 7 6 1 3 7 8 1 5 5 0 10 8 0 7 3 8 2 8
Challenge Outputs
9- 9- 9- 9- 9- 9- 9- 9- 9- 9-
X X X X X X X X X XXX
5/ 5/ 5/ 5/ 5/ 5/ 5/ 5/ 5/ 5/5
X 3/ 61 X X X 2/ 9- 7/ XXX
9- 3/ 61 3/ 81 5/ -/ 8- 7/ 8/8
Solution
USING: arrays combinators formatting io kernel math math.parser pair-rocket
prettyprint sequences splitting.extras ;
IN: dailyprogrammer.bowling-display
: input ( -- x ) lines [ " " split-harvest [ string>number ] map ] map ;
: frame ( x -- x x ) dup first 10 = 1 2 ? cut swap ;
: zeros ( x -- x ) [ dup 0 = [ drop "-" ] [ number>string ] if ] map ;
: spare ( x -- x ) zeros first "/" append ;
: normal ( x -- x ) zeros "" join ;
: type ( x -- x ) { { [ dup length 1 = ] [ drop "X" ] }
{ [ dup sum 10 = ] [ spare ] }
{ [ dup sum 0 = ] [ drop "-" ] }
[ normal ] } cond ;
: .next ( x -- x ) frame type "%-3s" printf ;
: first9 ( x -- x ) 9 [ .next ] times ;
: thrice ( x -- ) frame dup length 2 =
[ type write first . ] [ 2drop "XXX" print ] if ;
: tenth ( x -- ) dup length 2 = [ .next nl ] [ thrice t ] if drop ;
: main ( -- ) input [ first9 tenth ] each ;
Today's challenge will be a variation on a popular introductory programming task, scoring a game of bowling. However, in this challenge, we won't even actually have to calculate the score. Today's challenge is to produce the display for the individual frames, given a list of the number of pins knocked down on each frame.
The basic rules are as follows:
The game of bowling consists of 10 frames, where a player gets 2 attempts to knock down 10 pins.
If the player knocks down all 10 pins on the first roll, that should be displayed as X, and the next number will be the first roll of the next frame.
If the player doesn't knock down any pins, that should be displayed as -
If the player gets a spare (knocks down the remaining pins on the second roll of the frame, that should be displayed as /
If you want more details about the rules, see: Challenge #235 [Intermediate] Scoring a Bowling Game
Input Description
You will be given a list of integers that represent the number of pins knocked down on each roll. Not that this list is not a fixed size, as bowling a perfect game requires only 12 rolls, while most games would use more rolls.
Example:
6 4 5 3 10 10 8 1 8 0 10 6 3 7 3 5 3
Output Description
Your program should output the bowling frames including strikes and spares. The total score is not necessary.
Example:
6/ 53 X X 81 8- X 63 7/ 53
Challenge Inputs
9 0 9 0 9 0 9 0 9 0 9 0 9 0 9 0 9 0 9 0
10 10 10 10 10 10 10 10 10 10 10 10
5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5
10 3 7 6 1 10 10 10 2 8 9 0 7 3 10 10 10
9 0 3 7 6 1 3 7 8 1 5 5 0 10 8 0 7 3 8 2 8
Challenge Outputs
9- 9- 9- 9- 9- 9- 9- 9- 9- 9-
X X X X X X X X X XXX
5/ 5/ 5/ 5/ 5/ 5/ 5/ 5/ 5/ 5/5
X 3/ 61 X X X 2/ 9- 7/ XXX
9- 3/ 61 3/ 81 5/ -/ 8- 7/ 8/8
Solution
USING: arrays combinators formatting io kernel math math.parser pair-rocket
prettyprint sequences splitting.extras ;
IN: dailyprogrammer.bowling-display
: input ( -- x ) lines [ " " split-harvest [ string>number ] map ] map ;
: frame ( x -- x x ) dup first 10 = 1 2 ? cut swap ;
: zeros ( x -- x ) [ dup 0 = [ drop "-" ] [ number>string ] if ] map ;
: spare ( x -- x ) zeros first "/" append ;
: normal ( x -- x ) zeros "" join ;
: type ( x -- x ) { { [ dup length 1 = ] [ drop "X" ] }
{ [ dup sum 10 = ] [ spare ] }
{ [ dup sum 0 = ] [ drop "-" ] }
[ normal ] } cond ;
: .next ( x -- x ) frame type "%-3s" printf ;
: first9 ( x -- x ) 9 [ .next ] times ;
: thrice ( x -- ) frame dup length 2 =
[ type write first . ] [ 2drop "XXX" print ] if ;
: tenth ( x -- ) dup length 2 = [ .next nl ] [ thrice t ] if drop ;
: main ( -- ) input [ first9 tenth ] each ;
Comments
Post a Comment