23
3
In The Settlers of Catan board game, there are five resource types: Brick, Log, Ore, Wheat, and Sheep. Building a settlement costs a Brick, a Log, a Wheat, and a Sheep. However, you can also trade in four identical resources to get a resource of a different type. For instance, if you had four ores in your hand, you could trade all of them in and get one sheep.
Your job is to determine whether or not I can build a settlement, given my hand.
Your Task
Input will be a sequence of the letters B
, L
, O
, W
, and S
, taken in any reasonable format. These letters correspond to the five resource types given above. You should output whether or not I have the resources necessary to build a settlement, taking into account the possibility of trading four of a kind.
This is code-golf, so shortest code in bytes wins.
Notes
- You do not have to output what trades I need to perform or how many settlements I could build. A simple "yes" or "no" will do.
- You may not assume that the input is in any specific order. In particular, you may not assume that resources of the same type are grouped together, so
OBLSO
is a valid input. - This is decision-problem, so you may use any value you want to mean "yes" and "no", as long as the two chosen values are distinct and consistent.
- The only rules we're concerned with here are the ones listed above. More complicated Settlers of Catan rules like trading with other players or at harbours are not relevant here.
- The input characters (
B
,L
,O
,W
,S
) can be substituted with other values if it is easier for your particular language of choice, so long as there are five distinct inputs. If you use other input values, please specify them in your answer.
Examples
BLWS -> Yes
OOOOWLB -> Yes (trade four O for a S)
OOW -> No
BBBO -> No
(empty input) -> No
BBBBLW -> No
BBBBBLW -> Yes (trade four B for a S)
OOOOOOOOOOOOOOOO -> Yes (sixteen O; trade for B, L, W, S)
BLBLBLBLBL -> Yes (trade L for W and B for S)
BLSWBLSWBLSW -> Yes (extra, unused resources are ignored)
13"Building a settlement costs a Brick, a Log, a Wheat, and a Sheep". Yes, to perform the ritual of building a settlement, you need one sheep. Wonder why there aren't any vegetarians? – Okx – 2017-09-04T16:33:50.587
5@Okx , the sheep gives the milk that goes with the bread from the wheat to feed the builders while they build (they take the sheep with them at the end as payment). No animals were hurt in the building of the settlement – Aganju – 2017-09-04T21:33:58.003
Is it OK for the program to require the input to be sorted? – NieDzejkob – 2017-09-05T14:58:25.060
@NieDzejkob No, requiring an ordering is specifically disallowed. Your program must be prepared to handle any sequence of the five resources. – Silvio Mayolo – 2017-09-05T16:39:40.477
@SilvioMayolo sorry, I don't know how I missed that – NieDzejkob – 2017-09-05T16:43:40.123
@Aganju Butter comes from milk which comes from sheep. Cheese also comes from milk. Warm clothing comes from wool which comes from sheep (though not in cold weather when you need said warm clothing). Butter makes bread more palatable and cheese also helps to do the same. Sheep can also pull on pulleys to lift up large heavy things (assuming a strong sheep and some rope). – wizzwizz4 – 2017-09-05T17:32:36.513