Skip to content

Count the smiley faces!

Given an array (arr) as an argument complete the function countSmileys that should return the total number of smiling faces.


  • Each smiley face must contain a valid pair of eyes. Eyes can be marked as : or ;
  • A smiley face can have a nose but it does not have to. Valid characters for a nose are - or ~
  • Every smiling face must have a smiling mouth that should be marked with either ) or D
  • No additional characters are allowed except for those mentioned.


Valid smiley face examples: :) :D ;-D :~)

Invalid smiley faces: ;( :> :} :]


count_the_smiley_faces([':)', ';(', ';}', ':-D']);       // should return 2;
count_the_smiley_faces([';D', ':-(', ':-)', ';~)']);     // should return 3;
count_the_smiley_faces([';]', ':[', ';*', ':$', ';-D']); // should return 1;


In case of an empty array return 0. You will not be tested with invalid input (input will always be an array). Order of the face (eyes, nose, mouth) elements will always be the same.


def count_the_smiley_faces(x, y):
    x_total, y_total = 0, 0

    x_total = sum(ord(x[i]) - 64 for i in range(len(x)))
    y_total = sum(ord(y[i]) - 64 for i in range(len(y)))

    return x if x_total > y_total else y if x_total < y_total else 'Tie!'

print(count_the_smiley_faces("AAA", "Z"))

my thoughts are neither my employer's nor my wife's