diff --git a/config.json b/config.json index b284b0cf..3a841ad3 100644 --- a/config.json +++ b/config.json @@ -141,6 +141,14 @@ "prerequisites": [], "difficulty": 1 }, + { + "slug": "square-root", + "name": "Square Root", + "uuid": "f78cf535-17de-465a-b54c-2f9c0c1f1161", + "practices": [], + "prerequisites": [], + "difficulty": 2 + }, { "slug": "twelve-days", "name": "Twelve Days", diff --git a/exercises/practice/square-root/.docs/instructions.md b/exercises/practice/square-root/.docs/instructions.md new file mode 100644 index 00000000..e9905e9d --- /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/config.json b/exercises/practice/square-root/.meta/config.json new file mode 100644 index 00000000..70428418 --- /dev/null +++ b/exercises/practice/square-root/.meta/config.json @@ -0,0 +1,19 @@ +{ + "authors": [ + "BNAndras" + ], + "files": { + "solution": [ + "square-root.rkt" + ], + "test": [ + "square-root-test.rkt" + ], + "example": [ + ".meta/example.rkt" + ] + }, + "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/example.rkt b/exercises/practice/square-root/.meta/example.rkt new file mode 100644 index 00000000..bcb3bbae --- /dev/null +++ b/exercises/practice/square-root/.meta/example.rkt @@ -0,0 +1,8 @@ +#lang racket + +(provide square-root) + +(define (square-root radicand) + (for/first ([num (in-naturals)] + #:when (equal? (expt num 2) radicand)) + num)) \ No newline at end of file diff --git a/exercises/practice/square-root/.meta/tests.toml b/exercises/practice/square-root/.meta/tests.toml new file mode 100644 index 00000000..ead7882f --- /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/square-root-test.rkt b/exercises/practice/square-root/square-root-test.rkt new file mode 100644 index 00000000..27032bf5 --- /dev/null +++ b/exercises/practice/square-root/square-root-test.rkt @@ -0,0 +1,36 @@ +#lang racket/base + +(require "square-root.rkt") + +(module+ test + (require rackunit rackunit/text-ui) + + (define suite + (test-suite + "square-root tests" + + (test-eqv? "root of 1" + (square-root 1) + 1) + + (test-eqv? "root of 4" + (square-root 4) + 2) + + (test-eqv? "root of 25" + (square-root 25) + 5) + + (test-eqv? "root of 81" + (square-root 81) + 9) + + (test-eqv? "root of 196" + (square-root 196) + 14) + + (test-eqv? "root of 65025" + (square-root 65025) + 255))) + +(run-tests suite)) diff --git a/exercises/practice/square-root/square-root.rkt b/exercises/practice/square-root/square-root.rkt new file mode 100644 index 00000000..73ac13ad --- /dev/null +++ b/exercises/practice/square-root/square-root.rkt @@ -0,0 +1,6 @@ +#lang racket + +(provide square-root) + +(define (square-root radicand) + (error "Not implemented yet"))