From 4e284ec505bf73f1ed01bd8d2b3169522705d413 Mon Sep 17 00:00:00 2001 From: Erik Schierboom Date: Mon, 21 Oct 2024 08:56:43 +0200 Subject: [PATCH] Add `square-root` exercise --- config.json | 8 +++++ exercises/Exercises.sln | 7 +++++ .../square-root/.config/dotnet-tools.json | 12 +++++++ .../square-root/.docs/instructions.md | 13 ++++++++ .../practice/square-root/.meta/Example.fs | 5 +++ .../practice/square-root/.meta/config.json | 19 ++++++++++++ .../practice/square-root/.meta/tests.toml | 28 +++++++++++++++++ exercises/practice/square-root/SquareRoot.fs | 4 +++ .../practice/square-root/SquareRoot.fsproj | 22 +++++++++++++ .../practice/square-root/SquareRootTests.fs | 31 +++++++++++++++++++ generators/Generators.fs | 3 ++ 11 files changed, 152 insertions(+) create mode 100644 exercises/practice/square-root/.config/dotnet-tools.json create mode 100644 exercises/practice/square-root/.docs/instructions.md create mode 100644 exercises/practice/square-root/.meta/Example.fs create mode 100644 exercises/practice/square-root/.meta/config.json create mode 100644 exercises/practice/square-root/.meta/tests.toml create mode 100644 exercises/practice/square-root/SquareRoot.fs create mode 100644 exercises/practice/square-root/SquareRoot.fsproj create mode 100644 exercises/practice/square-root/SquareRootTests.fs diff --git a/config.json b/config.json index 6b30b0f86..f923b99b2 100644 --- a/config.json +++ b/config.json @@ -2133,6 +2133,14 @@ "practices": [], "prerequisites": [], "difficulty": 1 + }, + { + "slug": "square-root", + "name": "Square Root", + "uuid": "2c85587e-9b6c-4edf-9f05-e600489a9074", + "practices": [], + "prerequisites": [], + "difficulty": 1 } ], "foregone": [ diff --git a/exercises/Exercises.sln b/exercises/Exercises.sln index f17d45ed8..378b9b917 100644 --- a/exercises/Exercises.sln +++ b/exercises/Exercises.sln @@ -283,6 +283,8 @@ Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "ResistorColor", "practice\r EndProject Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "ResistorColorDuo", "practice\resistor-color-duo\ResistorColorDuo.fsproj", "{D7E215C6-4EE6-41AB-BD80-F126C50A590E}" EndProject +Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "SquareRoot", "practice\square-root\SquareRoot.fsproj", "{C41EB0DE-54C9-4673-8B8B-E9AA43DF3746}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -844,6 +846,10 @@ Global {D7E215C6-4EE6-41AB-BD80-F126C50A590E}.Debug|Any CPU.Build.0 = Debug|Any CPU {D7E215C6-4EE6-41AB-BD80-F126C50A590E}.Release|Any CPU.ActiveCfg = Release|Any CPU {D7E215C6-4EE6-41AB-BD80-F126C50A590E}.Release|Any CPU.Build.0 = Release|Any CPU + {C41EB0DE-54C9-4673-8B8B-E9AA43DF3746}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C41EB0DE-54C9-4673-8B8B-E9AA43DF3746}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C41EB0DE-54C9-4673-8B8B-E9AA43DF3746}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C41EB0DE-54C9-4673-8B8B-E9AA43DF3746}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(NestedProjects) = preSolution {9815492D-D8F9-439C-B73C-711693755626} = {9D239135-8242-4AC0-94AE-7CCD8408B531} @@ -984,5 +990,6 @@ Global {73AB6DA8-AA91-44A9-B5E5-0670FFB6A4AC} = {29984DF2-2734-483C-BC7D-F6D41599DACD} {6D2CFE86-D6B2-4820-B3D8-62255BF94DCD} = {29984DF2-2734-483C-BC7D-F6D41599DACD} {D7E215C6-4EE6-41AB-BD80-F126C50A590E} = {29984DF2-2734-483C-BC7D-F6D41599DACD} + {C41EB0DE-54C9-4673-8B8B-E9AA43DF3746} = {29984DF2-2734-483C-BC7D-F6D41599DACD} EndGlobalSection EndGlobal diff --git a/exercises/practice/square-root/.config/dotnet-tools.json b/exercises/practice/square-root/.config/dotnet-tools.json new file mode 100644 index 000000000..0f7926bad --- /dev/null +++ b/exercises/practice/square-root/.config/dotnet-tools.json @@ -0,0 +1,12 @@ +{ + "version": 1, + "isRoot": true, + "tools": { + "fantomas-tool": { + "version": "4.7.9", + "commands": [ + "fantomas" + ] + } + } +} \ No newline at end of file diff --git a/exercises/practice/square-root/.docs/instructions.md b/exercises/practice/square-root/.docs/instructions.md new file mode 100644 index 000000000..e9905e9d4 --- /dev/null +++ b/exercises/practice/square-root/.docs/instructions.md @@ -0,0 +1,13 @@ +# Instructions + +Given a natural radicand, return its square root. + +Note that the term "radicand" refers to the number for which the root is to be determined. +That is, it is the number under the root symbol. + +Check out the Wikipedia pages on [square root][square-root] and [methods of computing square roots][computing-square-roots]. + +Recall also that natural numbers are positive real whole numbers (i.e. 1, 2, 3 and up). + +[square-root]: https://en.wikipedia.org/wiki/Square_root +[computing-square-roots]: https://en.wikipedia.org/wiki/Methods_of_computing_square_roots diff --git a/exercises/practice/square-root/.meta/Example.fs b/exercises/practice/square-root/.meta/Example.fs new file mode 100644 index 000000000..4613d86b0 --- /dev/null +++ b/exercises/practice/square-root/.meta/Example.fs @@ -0,0 +1,5 @@ +module SquareRoot + +let squareRoot n = + let rec loop i = if i * i <= n then loop (i + 1) else i - 1 + loop 1 diff --git a/exercises/practice/square-root/.meta/config.json b/exercises/practice/square-root/.meta/config.json new file mode 100644 index 000000000..f2b50b1d3 --- /dev/null +++ b/exercises/practice/square-root/.meta/config.json @@ -0,0 +1,19 @@ +{ + "authors": [ + "erikschierboom" + ], + "files": { + "solution": [ + "SquareRoot.fs" + ], + "test": [ + "SquareRootTests.fs" + ], + "example": [ + ".meta/Example.fs" + ] + }, + "blurb": "Given a natural radicand, return its square root.", + "source": "wolf99", + "source_url": "https://github.com/exercism/problem-specifications/pull/1582" +} diff --git a/exercises/practice/square-root/.meta/tests.toml b/exercises/practice/square-root/.meta/tests.toml new file mode 100644 index 000000000..ead7882fc --- /dev/null +++ b/exercises/practice/square-root/.meta/tests.toml @@ -0,0 +1,28 @@ +# This is an auto-generated file. +# +# Regenerating this file via `configlet sync` will: +# - Recreate every `description` key/value pair +# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications +# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion) +# - Preserve any other key/value pair +# +# As user-added comments (using the # character) will be removed when this file +# is regenerated, comments can be added via a `comment` key. + +[9b748478-7b0a-490c-b87a-609dacf631fd] +description = "root of 1" + +[7d3aa9ba-9ac6-4e93-a18b-2e8b477139bb] +description = "root of 4" + +[6624aabf-3659-4ae0-a1c8-25ae7f33c6ef] +description = "root of 25" + +[93beac69-265e-4429-abb1-94506b431f81] +description = "root of 81" + +[fbddfeda-8c4f-4bc4-87ca-6991af35360e] +description = "root of 196" + +[c03d0532-8368-4734-a8e0-f96a9eb7fc1d] +description = "root of 65025" diff --git a/exercises/practice/square-root/SquareRoot.fs b/exercises/practice/square-root/SquareRoot.fs new file mode 100644 index 000000000..a4d4d752c --- /dev/null +++ b/exercises/practice/square-root/SquareRoot.fs @@ -0,0 +1,4 @@ +module SquareRoot + +let squareRoot n = + failwith "Please implement the 'squareRoot' function" diff --git a/exercises/practice/square-root/SquareRoot.fsproj b/exercises/practice/square-root/SquareRoot.fsproj new file mode 100644 index 000000000..b519df1a5 --- /dev/null +++ b/exercises/practice/square-root/SquareRoot.fsproj @@ -0,0 +1,22 @@ + + + net8.0 + false + false + true + + + + + + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + \ No newline at end of file diff --git a/exercises/practice/square-root/SquareRootTests.fs b/exercises/practice/square-root/SquareRootTests.fs new file mode 100644 index 000000000..c7332dd17 --- /dev/null +++ b/exercises/practice/square-root/SquareRootTests.fs @@ -0,0 +1,31 @@ +module SquareRootTests + +open FsUnit.Xunit +open Xunit + +open SquareRoot + +[] +let ``Root of 1`` () = + squareRoot 1 |> should equal 1 + +[] +let ``Root of 4`` () = + squareRoot 4 |> should equal 2 + +[] +let ``Root of 25`` () = + squareRoot 25 |> should equal 5 + +[] +let ``Root of 81`` () = + squareRoot 81 |> should equal 9 + +[] +let ``Root of 196`` () = + squareRoot 196 |> should equal 14 + +[] +let ``Root of 65025`` () = + squareRoot 65025 |> should equal 255 + diff --git a/generators/Generators.fs b/generators/Generators.fs index dbf84b510..c3c5e9928 100644 --- a/generators/Generators.fs +++ b/generators/Generators.fs @@ -2035,3 +2035,6 @@ type ResistorColor() = type ResistorColorDuo() = inherit ExerciseGenerator() + +type SquareRoot() = + inherit ExerciseGenerator()