12345678910111213141516171819202122232425 |
- module KindergartenGarden
-
- open System
-
- type Plant =
- | Grass
- | Clover
- | Radishes
- | Violets
-
- let getNumFromName (student: string) = int (student.[0]) - int ('A')
-
- let getPlantChars (row: string) num =
- [ for c in (row.[(num * 2)..(num * 2 + 1)]) -> c ]
-
- let plants (diagram: string) (student: string) =
- diagram.Split [| '\n' |] // Split the rows up
- |> Seq.map (fun i -> (getPlantChars i (getNumFromName student))) // Go over each row getting the child's plants
- |> 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']
- |> List.map (fun i -> // Now for each plant character return the relavant plant type
- match i with
- | 'G' -> Grass
- | 'C' -> Clover
- | 'R' -> Radishes
- | _ -> Violets)
|