5 kyu

Letterss of Natac

114 of 139mentalplex

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")
play_if_enough("ooooogggssbbb", "ooogg")
[[1]] 
[1] TRUE 

[[2]]
[1] "oogssbbb"

play_if_enough("oogssbbb", "bwsg")
[[1]] 
[1] FALSE 

[[2]]
[1] "oogssbbb"

play_if_enough("", "bw")
[[1]]
[1] FALSE

[[2]]
[1] ""

play_if_enough("abcdefghij", "aa")
[[1]]
[1] FALSE

[[2]]
[1] "abcdefghij"

Notes:

  1. 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.
  2. 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.
  3. A valid play is a string of any number of lower case letters.
  4. You do not have to test for whether a hand or play is valid.
  5. 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.
  6. Tests include hand sizes of up to 150000 elements and play sizes up to 10000 elements.
Fundamentals

Stats:

CreatedOct 13, 2017
PublishedOct 13, 2017
Warriors Trained474
Total Skips137
Total Code Submissions835
Total Times Completed139
Python Completions114
R Completions27
Total Stars10
% of votes with a positive feedback rating92% of 55
Total "Very Satisfied" Votes47
Total "Somewhat Satisfied" Votes7
Total "Not Satisfied" Votes1
Total Rank Assessments7
Average Assessed Rank
5 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
6 kyu
Ad
Contributors
  • mentalplex Avatar
  • Voile Avatar
  • FArekkusu Avatar
Ad