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.

KindergartenGarden.fs 843B

12345678910111213141516171819202122232425
  1. module KindergartenGarden
  2. open System
  3. type Plant =
  4. | Grass
  5. | Clover
  6. | Radishes
  7. | Violets
  8. let getNumFromName (student: string) = int (student.[0]) - int ('A')
  9. let getPlantChars (row: string) num =
  10. [ for c in (row.[(num * 2)..(num * 2 + 1)]) -> c ]
  11. let plants (diagram: string) (student: string) =
  12. diagram.Split [| '\n' |] // Split the rows up
  13. |> Seq.map (fun i -> (getPlantChars i (getNumFromName student))) // Go over each row getting the child's plants
  14. |> Seq.reduce List.append // This flattens the list becuase before this it looks like [['a', 'b']['c', 'd']] and we want ['a', 'b', 'c', 'd']
  15. |> List.map (fun i -> // Now for each plant character return the relavant plant type
  16. match i with
  17. | 'G' -> Grass
  18. | 'C' -> Clover
  19. | 'R' -> Radishes
  20. | _ -> Violets)