Skip to main content
1 of 4
Armand
  • 519
  • 2
  • 7

Groovy

Easy: 26 characters

c={(it=~/[\W|^_]/).size()}

assert c("abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ 0123456789")== 2
assert c("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")==0
assert c("a-b-7*NNuah ~#77%")==7
assert c('_') == 1
Armand
  • 519
  • 2
  • 7