Skip to content

Instantly share code, notes, and snippets.

@garyshort
Last active July 12, 2020 14:19
Show Gist options
  • Save garyshort/259feb55840b5f9c17021d60f5c0bd17 to your computer and use it in GitHub Desktop.
Save garyshort/259feb55840b5f9c17021d60f5c0bd17 to your computer and use it in GitHub Desktop.
Demo of NationWord Test
def number_of_a_additions(aString):
# Fail fast
if 'aaa' in aString:
return -1
if aString == 'aa':
return 0
# For any string of n chars long, return
# (2(number of chars that aren't 'a') +2) - count('a')
not_as = [c for c in aString if c != 'a']
return ((len(not_as) * 2) + 2) - aString.count('a')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment