| @@ -0,0 +1,25 @@ | |||
| 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) | |||
| @@ -0,0 +1,21 @@ | |||
| <Project Sdk="Microsoft.NET.Sdk"> | |||
| <PropertyGroup> | |||
| <TargetFramework>netcoreapp3.0</TargetFramework> | |||
| <IsPackable>false</IsPackable> | |||
| </PropertyGroup> | |||
| <ItemGroup> | |||
| <Compile Include="KindergartenGarden.fs" /> | |||
| <Compile Include="KindergartenGardenTests.fs" /> | |||
| </ItemGroup> | |||
| <ItemGroup> | |||
| <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" /> | |||
| <PackageReference Include="xunit" Version="2.4.1" /> | |||
| <PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" /> | |||
| <PackageReference Include="FsUnit.xUnit" Version="3.8.1" /> | |||
| </ItemGroup> | |||
| </Project> | |||
| @@ -0,0 +1,72 @@ | |||
| // This file was auto-generated based on version 1.1.1 of the canonical data. | |||
| module KindergartenGardenTests | |||
| open FsUnit.Xunit | |||
| open Xunit | |||
| open KindergartenGarden | |||
| [<Fact>] | |||
| let ``Partial garden - garden with single student`` () = | |||
| let student = "Alice" | |||
| let diagram = "RC\nGG" | |||
| let expected = [Plant.Radishes; Plant.Clover; Plant.Grass; Plant.Grass] | |||
| plants diagram student |> should equal expected | |||
| [<Fact>] | |||
| let ``Partial garden - different garden with single student`` () = | |||
| let student = "Alice" | |||
| let diagram = "VC\nRC" | |||
| let expected = [Plant.Violets; Plant.Clover; Plant.Radishes; Plant.Clover] | |||
| plants diagram student |> should equal expected | |||
| [<Fact>] | |||
| let ``Partial garden - garden with two students`` () = | |||
| let student = "Bob" | |||
| let diagram = "VVCG\nVVRC" | |||
| let expected = [Plant.Clover; Plant.Grass; Plant.Radishes; Plant.Clover] | |||
| plants diagram student |> should equal expected | |||
| [<Fact>] | |||
| let ``Partial garden - multiple students for the same garden with three students - second student's garden`` () = | |||
| let student = "Bob" | |||
| let diagram = "VVCCGG\nVVCCGG" | |||
| let expected = [Plant.Clover; Plant.Clover; Plant.Clover; Plant.Clover] | |||
| plants diagram student |> should equal expected | |||
| [<Fact>] | |||
| let ``Partial garden - multiple students for the same garden with three students - third student's garden`` () = | |||
| let student = "Charlie" | |||
| let diagram = "VVCCGG\nVVCCGG" | |||
| let expected = [Plant.Grass; Plant.Grass; Plant.Grass; Plant.Grass] | |||
| plants diagram student |> should equal expected | |||
| [<Fact>] | |||
| let ``Full garden - first student's garden`` () = | |||
| let student = "Alice" | |||
| let diagram = "VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV" | |||
| let expected = [Plant.Violets; Plant.Radishes; Plant.Violets; Plant.Radishes] | |||
| plants diagram student |> should equal expected | |||
| [<Fact>] | |||
| let ``Full garden - second student's garden`` () = | |||
| let student = "Bob" | |||
| let diagram = "VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV" | |||
| let expected = [Plant.Clover; Plant.Grass; Plant.Clover; Plant.Clover] | |||
| plants diagram student |> should equal expected | |||
| [<Fact>] | |||
| let ``Full garden - second to last student's garden`` () = | |||
| let student = "Kincaid" | |||
| let diagram = "VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV" | |||
| let expected = [Plant.Grass; Plant.Clover; Plant.Clover; Plant.Grass] | |||
| plants diagram student |> should equal expected | |||
| [<Fact>] | |||
| let ``Full garden - last student's garden`` () = | |||
| let student = "Larry" | |||
| let diagram = "VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV" | |||
| let expected = [Plant.Grass; Plant.Violets; Plant.Clover; Plant.Violets] | |||
| plants diagram student |> should equal expected | |||
| @@ -0,0 +1,80 @@ | |||
| # Kindergarten Garden | |||
| Given a diagram, determine which plants each child in the kindergarten class is | |||
| responsible for. | |||
| The kindergarten class is learning about growing plants. The teacher | |||
| thought it would be a good idea to give them actual seeds, plant them in | |||
| actual dirt, and grow actual plants. | |||
| They've chosen to grow grass, clover, radishes, and violets. | |||
| To this end, the children have put little cups along the window sills, and | |||
| planted one type of plant in each cup, choosing randomly from the available | |||
| types of seeds. | |||
| ```text | |||
| [window][window][window] | |||
| ........................ # each dot represents a cup | |||
| ........................ | |||
| ``` | |||
| There are 12 children in the class: | |||
| - Alice, Bob, Charlie, David, | |||
| - Eve, Fred, Ginny, Harriet, | |||
| - Ileana, Joseph, Kincaid, and Larry. | |||
| Each child gets 4 cups, two on each row. Their teacher assigns cups to | |||
| the children alphabetically by their names. | |||
| The following diagram represents Alice's plants: | |||
| ```text | |||
| [window][window][window] | |||
| VR...................... | |||
| RG...................... | |||
| ``` | |||
| In the first row, nearest the windows, she has a violet and a radish. In the | |||
| second row she has a radish and some grass. | |||
| Your program will be given the plants from left-to-right starting with | |||
| the row nearest the windows. From this, it should be able to determine | |||
| which plants belong to each student. | |||
| For example, if it's told that the garden looks like so: | |||
| ```text | |||
| [window][window][window] | |||
| VRCGVVRVCGGCCGVRGCVCGCGV | |||
| VRCCCGCRRGVCGCRVVCVGCGCV | |||
| ``` | |||
| Then if asked for Alice's plants, it should provide: | |||
| - Violets, radishes, violets, radishes | |||
| While asking for Bob's plants would yield: | |||
| - Clover, grass, clover, clover | |||
| ## Running the tests | |||
| To run the tests, run the command `dotnet test` from within the exercise directory. | |||
| ## Autoformatting the code | |||
| F# source code can be formatted with the [Fantomas](https://github.com/fsprojects/fantomas) tool. | |||
| After installing it with `dotnet tool restore`, run `dotnet fantomas .` to format code within the current directory. | |||
| ## Further information | |||
| For more detailed information about the F# track, including how to get help if | |||
| you're having trouble, please visit the exercism.io [F# language page](http://exercism.io/languages/fsharp/resources). | |||
| ## Source | |||
| Random musings during airplane trip. [http://jumpstartlab.com](http://jumpstartlab.com) | |||