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.

ScrabbleScore.fs 663B

1234567891011121314151617181920212223242526272829
  1. module ScrabbleScore
  2. open System
  3. let onePointLetter =
  4. [ 'A'
  5. 'E'
  6. 'I'
  7. 'O'
  8. 'U'
  9. 'L'
  10. 'N'
  11. 'R'
  12. 'S'
  13. 'T' ]
  14. let score word =
  15. word
  16. |> Seq.fold (fun a i ->
  17. let inset = List.contains (Char.ToUpper i)
  18. match Char.ToUpper i with
  19. | _ when inset onePointLetter -> a + 1
  20. | _ when inset [ 'D'; 'G' ] -> a + 2
  21. | _ when inset [ 'B'; 'C'; 'M'; 'P' ] -> a + 3
  22. | _ when inset [ 'F'; 'H'; 'V'; 'W'; 'Y' ] -> a + 4
  23. | _ when inset [ 'K' ] -> a + 5
  24. | _ when inset [ 'J'; 'X' ] -> a + 8
  25. | _ when inset [ 'Q'; 'Z' ] -> a + 10
  26. | _ -> a + 0) 0