Letterss of Natac
Description:
Letterss of Natac
In a game I just made up that doesn’t have anything to do with any other game that you may or may not have played, you collect resources on each turn and then use those resources to build things like roads, settlements and cities. If you would like to try other kata about this game, they can be found here
Task
This kata asks you to implement a time efficient version of the function play_if_enough(hand, play)
, which takes as input a hand
, the resources you have (a string of letters representing the resources you have), and a play
, (a string of letters representing the resources required to build a certain game object), and returns a tuple (list in r) of a boolean value, corresponding to whether you have enough resources, and your hand. If you had enough to build the object, the returned hand is your resources minus those you used to build the object. If not, it is your original hand (the one passed to the function).
For example, if it takes 3 ore and 2 grain to build a city, play
is ”ooogg”
. If hand
is ”ooooogggssbbb”
, then play_if_enough(hand, play)
returns (True, “oogssbbb”)
.
Examples
play_if_enough("ooooogggssbbb", "ooogg") => (True, "oogssbbb")
play_if_enough("oogssbbb", "bwsg") => (False, "oogssbbb")
play_if_enough("", "bw") => (False, "")
play_if_enough("abcdefghij", "aa") => (False, "abcdefghij")
Notes:
- The order of resources in your hand (or play) is not relevant. You can shuffle your hand any way you'd like, so long as you have the same number of each resource.
- There are 26 different resources, each represented by a lower case letter a-z, so a valid hand is a string of lower case letters.
- A valid play is a string of any number of lower case letters.
- You do not have to test for whether a hand or play is valid.
- A hand can be empty, but a play can't. In the event a hand is empty, you don't have the cards to play, so return
(False, "")
, in the correct data structure for your language, see example 4 above. - Tests include hand sizes of up to 150000 elements and play sizes up to 10000 elements.
Similar Kata:
Stats:
Created | Oct 13, 2017 |
Published | Oct 13, 2017 |
Warriors Trained | 474 |
Total Skips | 137 |
Total Code Submissions | 835 |
Total Times Completed | 139 |
Python Completions | 114 |
R Completions | 27 |
Total Stars | 10 |
% of votes with a positive feedback rating | 92% of 55 |
Total "Very Satisfied" Votes | 47 |
Total "Somewhat Satisfied" Votes | 7 |
Total "Not Satisfied" Votes | 1 |
Total Rank Assessments | 7 |
Average Assessed Rank | 5 kyu |
Highest Assessed Rank | 5 kyu |
Lowest Assessed Rank | 6 kyu |