Sha256: 772d4c2b23f85a898605dfe21f659b385f47dce3045b6e00612518d1c2266397

Contents?: true

Size: 1.14 KB

Versions: 17

Compression:

Stored size: 1.14 KB

Contents

from strutils import endsWith, strip
from unicode import isLower, isUpper, isWhiteSpace, runes

proc isSilence(s: string): bool =
  for r in runes(s):
    if not isWhiteSpace(r):
      return false
  return true

proc isYelling(s: string): bool =
  var nUpperRunes = 0
  for r in runes(s):
    if isLower(r):
      return false
    elif isUpper(r):
      inc(nUpperRunes)
  return nUpperRunes > 0

proc isQuestion(s: string): bool =
  return s.strip().endsWith("?")

proc hey*(msg: string): string {.noSideEffect.} =
  ## Returns the response of a lackadaisical teenager to a futile attempt to
  ## communicate with him.
  ##
  ## .. code-block:: nimrod
  ##   let greeting = "Hi, Bob!"
  ##   assert hey(greeting) == "Whatever."
  ##
  ##   let question == "What's up, Bob?"
  ##   assert hey(question) == "Sure."
  ##
  ##   let rage = "TALK TO ME!!!"
  ##   assert hey(rage) == "Whoa, chill out!"
  ##
  ##   let resignation = ""
  ##   assert hey(resignation) == "Fine. Be that way!"
  if isSilence(msg):
    return "Fine. Be that way!"
  elif isYelling(msg):
    return "Whoa, chill out!"
  elif isQuestion(msg):
    return "Sure."
  else:
    return "Whatever."

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
trackler-2.2.1.155 tracks/nim/exercises/bob/example.nim
trackler-2.2.1.154 tracks/nim/exercises/bob/example.nim
trackler-2.2.1.153 tracks/nim/exercises/bob/example.nim
trackler-2.2.1.152 tracks/nim/exercises/bob/example.nim
trackler-2.2.1.151 tracks/nim/exercises/bob/example.nim
trackler-2.2.1.150 tracks/nim/exercises/bob/example.nim
trackler-2.2.1.149 tracks/nim/exercises/bob/example.nim
trackler-2.2.1.148 tracks/nim/exercises/bob/example.nim
trackler-2.2.1.147 tracks/nim/exercises/bob/example.nim
trackler-2.2.1.146 tracks/nim/exercises/bob/example.nim
trackler-2.2.1.145 tracks/nim/exercises/bob/example.nim
trackler-2.2.1.144 tracks/nim/exercises/bob/example.nim
trackler-2.2.1.143 tracks/nim/exercises/bob/example.nim
trackler-2.2.1.142 tracks/nim/exercises/bob/example.nim
trackler-2.2.1.141 tracks/nim/exercises/bob/example.nim
trackler-2.2.1.140 tracks/nim/exercises/bob/example.nim
trackler-2.2.1.139 tracks/nim/exercises/bob/example.nim