The Goobles Challenge - Part 2
Description:
This is part 2 of a multi-part series of katas. Although not strictly necessary it is advised to complete the katas in order as they are designed to become increasingly difficult.
Story
Despite your much celebrated work as town elder to provide each Gooble with an efficient schedule each day, the Gooble town council wants some changes. Until now, it was allowed for each Gooble to carry more sand than was strictly needed for their daily sand sculpture. This results in a lot of excess sand all over town each day and the council has had enough. As a result, a new law is added to the town laws that requires each Gooble to carry exactly the amount of sand they need for their sculpture.
Problem
After the newly added law the total law book for the Goobles now consists of the following laws :
- Every Gooble must attempt to make a sand sculpture each day.
- Each Gooble gets assigned a square spot with sides of D meters on the town square to build their sculpture (so the area of the spot is D x D or D² square meters).
- Each sand sculpture must use exactly 100 kilograms of sand for every square meter of building space the Gooble was assigned. Building a sculpture always takes exactly one hour.
- (NEW) Goobles are not allowed to bring more sand into town than they strictly need to finish their sculpture. The total amount of sand they can carry back and forth to town that day must be exactly equal to the amount of sand they need to use for their sculpture.
- Each Gooble must carry their own sand from the sand mine back to town. The run to the mine, loading the sand and carry the sand back takes exactly one hour in total.
- Goobles must finish their sculpture before the day ends. On the planet Gooble each day has an arbitrary amount of hours that only you, the town elder, knows exactly. Each Gooble is told at the start of the day how many hours they have to work with.
Each Gooble wakes up with a random amount of strength, expressed in the amount of kilograms S of sand they can and will carry per trip. A Gooble can double their strength S for each full hour they spend training in town. If a Gooble does not train for exactly the full hour their strength is not increased. A Gooble will always carry exactly the amount of sand their strength allows them to.
Your challenge is to provide each Gooble with the shortest possible schedule of instructions that allows them to build a sculpture without breaking any of the Gooble laws.
The schedule is a string of capital letters, each letter instructing the Gooble how to spend their time that hour. The allowed instructions are :
T : Spend the hour training, doubling Gooble strength.
C : Carry sand back and forth to town. A Gooble will always bring exactly the amount of sand they can carry.
B : Build the sculpture. This must be the last instruction on the schedule.
Note that your schedule must be such that the Gooble carries exactly the required amount of sand to town. For example, for D=2 the amount of kilograms that need to be transported is 2 x 2 x 100 = 400 kilograms
of sand. If a Gooble starts with a strength S of 50 the following schedules would be valid (but not the shortest possible) since they all move exactly 400 kilograms :
CCCCCCCCB (Carry 50 kilograms 8 times)
TCCCCB (Train one hour, then carry 100 kilograms 4 times)
CCCCTTCB (Carry 50 kilograms 4 times, train twice, carry another 200 kilograms)
If there is no possible schedule where the Gooble can construct the sculpture before the day ends or if no schedule is possible that results in exactly the correct amount of sand being carried your schedule should just read TBCB
(Too Big, Can't Build). Note that due to there being two B
instructions in this schedule this schedule is not valid, despite all letters corresponding to individual instructions.
Input
You are tasked to implement the function instruct
that has the following inputs :
S : The strength S with which the Gooble wakes up this day.
D : The length of each side D of the square spot on the town square assigned to the Gooble.
hoursInTheDay : The amount of hours that make up this day on the planet Gooble
You can assume the values for S
, D
and hoursInTheDay
will be in the range of 0 to 1000. The following situations must result in a TBCB
schedule :
- If there are not enough hours in the day to construct the sculpture according to Gooble law
- If there is no schedule possible that results in carrying exactly the correct amount of sand
- If there are zero (0) hours in the day
- If a Gooble wakes up with 0 strength
- If a Gooble gets assigned a spot with D = 0
Output
As output your instruct
function must return a string with the schedule for the Gooble. All instructions must be uppercase letters as described in the problem section. The output must either be a valid schedule or TBCB
if no such schedule exists. Multiple correct, minimum solutions can exist for a specific input.
Similar Kata:
Stats:
Created | Jan 21, 2019 |
Published | Jan 21, 2019 |
Warriors Trained | 55 |
Total Skips | 0 |
Total Code Submissions | 42 |
Total Times Completed | 7 |
Java Completions | 7 |
Total Stars | 3 |
% of votes with a positive feedback rating | 100% of 1 |
Total "Very Satisfied" Votes | 1 |
Total "Somewhat Satisfied" Votes | 0 |
Total "Not Satisfied" Votes | 0 |
Total Rank Assessments | 1 |
Average Assessed Rank | 8 kyu |
Highest Assessed Rank | 8 kyu |
Lowest Assessed Rank | 8 kyu |