Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

ACSL Tiles is a one - person game played with rectangular tiles. Each tile has a single - digit number between 1 and 9 inclusive

ACSL Tiles is a one-person game played with rectangular tiles. Each tile has a single-digit number between 1 and 9 inclusive at each end. At the start of the game, there are 4 rows, each with a number. The goal of the game is to build rows by placing a tile at the right end of a row whose last number matches a number on the tile. Tiles can be re-oriented; thus, the tiles 34 and 43 are the same tile. If a tile cannot be placed on any row, it is placed in the discard pile. When all tiles have been played or discarded, find the sum of the single-digit numbers on all of the tiles in this discard pile.
At each turn, try the next tile in your hand to see if it can be added to one of the rows, starting with the row after the one where the last tile was placed, rotating back to Row 1 if necessary. Start looking at Row 1 when the game starts. However, if the last tile placed was a double (i.e., both numbers are the same), another tile must be placed on that row before any other match can be considered. If the tile cannot be placed, add it to the discard pile.
Input:
5923
5627733499453219645718
Output:
21
Explanation:
The game starts with 4 rows having numbers 5,9,2,3.
The tile 56 is placed on Row 1; the tile 27 is placed on Row 3; the tile 73 is placed on Row 4 as 37 because Row 4 is checked first after a tile is placed on Row 3; the tile 34 is placed on the discard pile; the tile 99 is placed on Row 2
The 45 and the 32 tiles are placed in the discard pile because they don't match the 99 tile; the tile 19 is placed on Row 2 as 91; the tile 64 is placed on Row 1; the 57 is placed on Row 3 as 75; and the 18 is placed on Row 2.
The final outcome is shown below:
The sum of the single-digit numbers on the tiles in the
discard pile is 3+4+4+5+3+2=21.
TASK:
Complete the function findDiscardSum
The function has two parameters: a 4-digit integer, originalRows, representing the initial numbers from Row 1 to Row 4 and a string of 2-digit numbers, tiles, each separated by a single space. Each 2-digit number represents the two numbers on each tile, both between 1 and 9, inclusive.
The function returns an integer representing the sum of all of the single-digit numbers on the tiles in the discard pile.
You may create additional functions that are called from findDiscardSum if needed in solving the problem.
Please write a solution in C++, Python, or Java for this problem that also accounts for many test cases

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional Microsoft SQL Server 2014 Integration Services

Authors: Brian Knight, Devin Knight

1st Edition

1118850904, 9781118850909

More Books

Students also viewed these Databases questions

Question

Learn about HRM development in Poland in recent years.

Answered: 1 week ago