The first document has parts redacted, and the other one doesn't. But the clean document might be a fake! You need to compare the two documents and decide if it is possible they are the same or not. Return true
if the two documents are possibly the same. Return false
otherwise.
Rules
- Each document is made of any visible characters, spaces, punctuation, and newlines \n
- Any character might be redacted (except
\n
) - The redaction character is
X
- The redacted document is always the first one
Example
doc1 = "TOP SECRET:\nThe missile launch code for Sunday XXXXXXXXXX is:\nXXXXXXXXXXXXXXXXX"
doc2 = "TOP SECRET:\nThe missile launch code for Sunday 5th August is:\n7-ZERO-8X-ALPHA-1"
Documents look the same, therefore true
.
Tests
doc1 = "The name of the mole is Professor XXXXX"
doc2 = "The name of the mole is Professor Dinglemouse"
doc1 = "XXXXXXXX XXXXXXX XXXXXXXXXXXXXXXXXXX\nXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXX XXXXXXXXXXXXX XXXXX"
doc2 = "Area-51. Medical Report. 23/Oct/1969\nE.T. subject 4 was given an asprin after reporting sick for duty today"
Good luck!
This challenge comes from dinglemouse on CodeWars. Thank you to CodeWars, who has licensed redistribution of this challenge under the 2-Clause BSD License!
Want to propose a challenge idea for a future post? Email yo+challenge@dev.to with your suggestions!
Top comments (7)
Rust
Assuming that replacement with
X
is per character.yay, a oneliner
With nightly feature
When you're a caveman and reimplement
all
:When you're a caveman and reimplement
.zip()
(none of the latter ones give better performance, only worse)
Here is a C++ solution,
A javascript way. Although I think this could be done with regex...
This one can be slightly optimised to return early on failure and not go through the whole string:
Implementation in Frink
Dart, bit longer, but it's fine lol. I still abide by the rule that not everything needs to be creative. Readability is my philosophy. If you can read the code and understand what's happening, the better for everything reading the code. Personally.
Python 3, using regex'es:
Try it online!