-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
144 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
""" | ||
https://www.codewars.com/kumite/5b748f34b1181438060005ae | ||
Your code should return a Boolean of true if the provided password meets the following conditions | ||
password must be no less than 8 characters long | ||
password must have at least 1 capital letter | ||
password must have at least 1 number | ||
password must have at least 1 special character | ||
for this Kata special characters are considered ( ! " # $ % & ' ( ) * + ' - . / ; : < > = or ?) | ||
if the password doesn't meet these requirements return false. | ||
>>> validate_min_chars("thiago") | ||
False | ||
>>> validate_min_chars("thiago12345") | ||
True | ||
>>> validate_at_least_one_capital_letter("thiago") | ||
False | ||
>>> validate_at_least_one_capital_letter("thiagoC") | ||
True | ||
>>> validate_at_least_one_capital_letter("thiagoC123") | ||
True | ||
>>> validate_at_least_one_capital_letter("thiagoC#!@#1") | ||
True | ||
>>> validate_at_least_one_number("thiagoC") | ||
False | ||
>>> validate_at_least_one_number("thiago11C") | ||
True | ||
>>> validate_at_least_one_special("thiagoC") | ||
False | ||
>>> validate_at_least_one_special("thiagoC*") | ||
True | ||
>>> validate_password("Thiago123#") | ||
True | ||
>>> validate_password("thiago123#") | ||
False | ||
>>> validate_password("Thiago123") | ||
False | ||
>>> validate_password("Thiago#####") | ||
False | ||
>>> validate_password("Thiag@") | ||
False | ||
>>> validate_password("!T13132312!") | ||
True | ||
>>> validate_password("!t13132312!") | ||
False | ||
""" | ||
def validate_min_chars(password): | ||
min_chars = 8 | ||
return len(password) >= min_chars | ||
|
||
def validate_at_least_one_capital_letter(password): | ||
return password.lower() != password | ||
|
||
def validate_at_least_one_number(password): | ||
for char in password: | ||
if char.isnumeric(): | ||
return True | ||
return False | ||
|
||
def validate_at_least_one_special(password): | ||
special_chars = set("""!"#$%&'()*+'-./;:<>=?""") | ||
password_set = set(password) | ||
return bool(special_chars & password_set) | ||
|
||
def validate_password(password): | ||
validators = [ | ||
validate_min_chars, | ||
validate_at_least_one_capital_letter, | ||
validate_at_least_one_number, | ||
validate_at_least_one_special | ||
] | ||
for validator in validators: | ||
if not validator(password): | ||
return False | ||
|
||
return True |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
""" | ||
https://www.codewars.com/kata/56684677dc75e3de2500002b/python | ||
A comfortable word is a word which you can type always alternating the hand you type with (assuming you type using a QWERTY keyboard and use fingers as shown in the image below). | ||
That being said, complete the function which receives a word and returns true if it's a comfortable word and false otherwise. | ||
The word will always be a string consisting of only ascii letters from a to z. | ||
To avoid problems with image availability, here's the lists of letters for each hand: | ||
Left: q, w, e, r, t, a, s, d, f, g, z, x, c, v, b | ||
Right: y, u, i, o, p, h, j, k, l, n, m | ||
Examples: | ||
"yams" --> true | ||
"test" --> false | ||
>>> is_comfortable("test") | ||
False | ||
>>> is_comfortable("yams") | ||
True | ||
>>> is_comfortable("qyw") | ||
True | ||
>>> is_comfortable("q") | ||
True | ||
>>> is_comfortable("qyww") | ||
False | ||
>>> is_comfortable("yuiop") | ||
False | ||
>>> is_comfortable("qwert") | ||
False | ||
>>> is_comfortable("aaaaa") | ||
False | ||
""" | ||
|
||
|
||
def is_comfortable(word): | ||
is_left = 1 | ||
is_right = 2 | ||
left = set(['q', 'w', 'e', 'r', 't', 'a', 's', 'd', | ||
'f', 'g', 'z', 'x', 'c', 'v', 'b']) | ||
|
||
previous_position = is_left if word[0] in left else is_right | ||
for char in word[1:]: | ||
current_position = is_left if char in left else is_right | ||
if current_position == previous_position: | ||
return False | ||
previous_position = current_position | ||
|
||
return True |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# O que foi bom | ||
- Novas pessoas! | ||
- Exercícios previamente escolhidos e bons | ||
- Split de palavra de 2 a 2 | ||
|
||
# O que podemos melhorar | ||
|
||
# O que aprendemos | ||
- Sets e suas mágicas | ||
- Busca mágica do google para devs | ||
- Não substimar o for |
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