22
1
In this challenge, you receive a string as input containing a string of X's, Y's and Z's eg. "XYZZ". X, Y and Z represent a particular character. This pattern is then compared with a second string input. If the pattern exists as a substring in the second input, return True
, otherwise, return False
. Once a pattern is found in the word, the program stops searching and returns True
.
Examples
Pattern: "XXYY"
succeed ---> True (pattern found: ccee)
success ---> False (pattern not matched)
balloon ---> True (pattern found: lloo)
Pattern: "XYXYZ"
bananas ---> True (pattern found: nanas)
banana ---> False (pattern not found)
- Note: This is not the actual input. This is an example of how the program should work. Your program should output
True
orFalse
, or other Truthy/Falsy values.
Other important/useful information
- The pattern does not need to contain an X, Y and a Z, it could contain X's and Y's or even (although somewhat pointless) just X's.
- The pattern cannot be empty, but this will not be used as a test case.
- The search string will not be empty, and will be lowercase.
- The alphabetic order of X, Y and Z in the pattern does not matter.
- X, Y and Z must be unique characters.
- You may use any library you wish.
- The score is determined by the code size, in bytes. Lowest score wins.
Good luck!
The pattern can be anything. I probably should have mentioned that the pattern doesn't have to have an X, Y, and a Z, it could have just an X and a Y. Those patterns are just examples, though, so feel free to come up with your own examples with those patterns. – notHalfBad – 2017-03-14T09:09:14.157
What do you mean "the pattern exists"? As a contiguous chunk? As a substring? Can, say, X and Y stand for the same thing? – xnor – 2017-03-14T09:09:18.093
@xnor X and Y must be independent of eachother, and what I mean by the pattern existing is that anywhere in the string there is a substring that matches the pattern. I will add these to my challenge description to clarify. – notHalfBad – 2017-03-14T09:11:00.027
3Related. (Same thing, but asks for exact matches of the pattern, not for substrings.) – Martin Ender – 2017-03-14T09:14:32.910
4More details: Can the pattern be empty? The search string? Will the search string only use lowercase letters? Will the pattern be alphabetically first among equivalent patterns, i.e. use X first then Y then Z? – xnor – 2017-03-14T09:14:53.943
@xnor Description updated – notHalfBad – 2017-03-14T09:21:01.957
Can either string be longer in length than the other. For example could one input be "XYZ" and the other "ab" while in another case the input "XYZ" and "abcdef" – Golden Ratio – 2017-03-14T09:44:51.113
@GoldenRatio So long as the length of the pattern and the string is not zero, the only real rule to follow regarding length is whether the string follows the pattern. In the first case, "ab" would not follow the pattern "XYZ" because there would be nothing to represent "Z". Regarding the second example, the pattern immediately finds a match in "abc" which follows "XYZ". – notHalfBad – 2017-03-14T09:50:57.763
Can we use a function to return the value? – Mr. Xcoder – 2017-03-14T17:08:57.477
@Mr.Xcoder sure! – notHalfBad – 2017-03-14T19:13:44.567
Can I have my program print the letters that XYZ represent? For instance for
f(banana,XYXY)
it would return['nab','anb']
, whereX=n, Y=a, Z=b
and an empty set when the pattern is not found? Not sure how but this cuts like ~3 bytes off my code haha. – Magic Octopus Urn – 2017-03-14T20:08:57.993The characters matching X,Y,Z have do be different? Example: pattern
XXYY
, stringaaaa
– edc65 – 2017-03-15T08:13:06.730Read the description. "X, Y and Z must be unique characters." – notHalfBad – 2017-03-15T08:31:18.977
Can the pattern be assumed to be all uppercase? – Titus – 2017-03-15T14:17:10.020
Are X,Y,Z just characters, or can they be character groups? (XYX == aabbaa) – Delioth – 2017-03-15T15:00:49.167