learning F#, it seems pretty cool, favourite functional language so far.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

Bob.fs 1017B

12345678910111213141516171819202122232425262728293031
  1. module Bob
  2. open System
  3. let containsLowercase = Seq.fold (fun a x -> if x >= 'a' && x <= 'z' then true else a) false
  4. let containsUppercase = Seq.fold (fun a x -> if x >= 'A' && x <= 'Z' then true else a) false
  5. let containsLetters input = containsLowercase input || containsUppercase input
  6. let lastLetter = Seq.last
  7. let question (input: string) = String.length input > 0 && lastLetter input = '?'
  8. let upperCase (input: string) =
  9. not (containsLowercase input) && containsUppercase input
  10. let emptyOrBlank (input: string) =
  11. String.length input = 0
  12. let response (rawInput: string): string =
  13. let strip = ['\t';' ';'\n';'\r']
  14. let input = rawInput |> Seq.filter (fun c -> not (List.contains c strip)) |> String.Concat
  15. let uc = upperCase input
  16. let q = question input
  17. let empty = emptyOrBlank input
  18. if q && uc then "Calm down, I know what I'm doing!" else
  19. if q then "Sure." else
  20. if empty then "Fine. Be that way!" else
  21. if uc then "Whoa, chill out!" else
  22. "Whatever."