Created
June 1, 2017 20:03
-
-
Save danielborowski/9bb9ac70e8522cb97cff1c9532e1162b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def QuestionsMarks(s): | |
qnum = 0 | |
dig = 0 | |
has_10 = False | |
for ch in s: | |
if ch.isdigit(): | |
if int(ch) + dig == 10: | |
if qnum != 3: | |
return 'false' | |
has_10 = True | |
dig = int(ch) | |
qnum = 0 | |
elif ch == '?': | |
qnum += 1 | |
return 'true' if has_10 else 'false' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This code fails the following assertion:
assert(QuestionsMarks("7?6??3?4") == 'true')
If that is what was intended by the question, then I think the challenge question needs to be rewritten. The way I read the question, I thought that we needed to check every sub-string between any pair of numbers in the entire string that could add up to 10.
In fact, I just realized that the test case in the challenge
"5??aaaaaaaaaaaaaaaaaaa?5?a??5" == true
would be false under my reading of the question, so your code does seem to fit what the challenge had in mind, but I will stand by my assertion that the question is unclear.