Created
February 12, 2016 20:14
-
-
Save jjst/8235de7c1aa0ad2668e1 to your computer and use it in GitHub Desktop.
nicestrings
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
#!/usr/bin/env python | |
import re | |
def is_nice(s): | |
return (len(re.findall(r"[aeiou]", s)) >= 3 and | |
bool(re.search(r"(\w)\1+", s)) and not | |
bool(re.search(r"ab|cd|pq|xy", s))) | |
if __name__ == "__main__": | |
with open('input1.txt', 'r') as f: | |
print sum(is_nice(s) for s in f.readlines()) |
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
from nicestrings import is_nice | |
def test_is_nice_nice_string(): | |
# req 1: 3 vowels | |
# req 2: 2 consecutive letters | |
# req 3: no ab, cd, pq, xy | |
assert(is_nice("aeibb") == True) | |
def test_is_nice_fails_req_1(): | |
# not enough vowels | |
assert(is_nice("aaxx") == False) | |
def test_is_nice_fails_req_2(): | |
assert(is_nice("aei") == False) | |
def test_is_nice_fails_req_3(): | |
assert(is_nice("aabbccdd") == False) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment