diff --git a/config.json b/config.json index 56ab420f..20125a54 100644 --- a/config.json +++ b/config.json @@ -1,407 +1,420 @@ -{ - "language": "D", - "active": true, - "blurb": "", - "checklist_issue": 6, - "test_pattern": "source.*[.]d", - "exercises": [ - { - "slug": "hello-world", - "uuid": "a91c2216-9331-4485-ae4b-190ee9e2a7f8", - "core": false, - "auto_approve": true, - "unlocked_by": null, - "difficulty": 1, - "topics": [ - "language_basics" - ] - }, - { - "slug": "leap", - "uuid": "9f52d6a7-1002-4614-afc3-cce03187c59b", - "core": false, - "unlocked_by": null, - "difficulty": 1, - "topics": [ - "language_basics" - ] - }, - { - "slug": "gigasecond", - "uuid": "8c976f92-fcfa-45f0-9bd1-2353822e51e8", - "core": false, - "unlocked_by": null, - "difficulty": 1, - "topics": [ - "language_basics", - "time" - ] - }, - { - "slug": "rna-transcription", - "uuid": "208f9a34-bdf2-4c2b-b102-f0ef1a5d04fe", - "core": false, - "unlocked_by": null, - "difficulty": 2, - "topics": [ - "control_flow_foreach", - "error_handling", - "string_manipulation" - ] - }, - { - "slug": "raindrops", - "uuid": "f6d21f86-b4d3-4dec-b830-8e19e1018548", - "core": false, - "unlocked_by": null, - "difficulty": 1, - "topics": [ - "control_flow_if_statements", - "language_basics" - ] - }, - { - "slug": "bob", - "uuid": "99ee69a6-2c0f-4c7c-86f9-bee1633b4f51", - "core": false, - "unlocked_by": null, - "difficulty": 2, - "topics": [ - "control_flow_if_statements", - "string_manipulation" - ] - }, - { - "slug": "etl", - "uuid": "dc631076-1eb8-4120-bd8f-dccf33df9a3f", - "core": false, - "unlocked_by": null, - "difficulty": 2, - "topics": [ - "associative_arrays", - "control_flow_foreach", - "string_manipulation" - ] - }, - { - "slug": "hamming", - "uuid": "87c87444-2349-40ab-a9a3-c0f0d2e200d6", - "core": false, - "unlocked_by": null, - "difficulty": 2, - "topics": [ - "control_flow_foreach", - "error_handling" - ] - }, - { - "slug": "nucleotide-count", - "uuid": "23b23ac0-62ef-4a22-b634-d64206c8a226", - "core": false, - "unlocked_by": null, - "difficulty": 3, - "topics": [ - "associative_arrays", - "classes", - "parsing" - ] - }, - { - "slug": "robot-name", - "uuid": "d7dd5df3-ff36-47ee-88db-e0f974a4cb19", - "core": false, - "unlocked_by": null, - "difficulty": 3, - "topics": [ - "classes", - "random_numbers" - ] - }, - { - "slug": "difference-of-squares", - "uuid": "d6c67e30-c950-40b6-b6db-0fa6df5652af", - "core": false, - "unlocked_by": null, - "difficulty": 2, - "topics": [ - "algorithms", - "control_flow_foreach", - "functional", - "math", - "template_metaprogramming" - ] - }, - { - "slug": "roman-numerals", - "uuid": "5647c00e-d4be-4546-bac3-6a3e1670c2a1", - "core": false, - "unlocked_by": null, - "difficulty": 3, - "topics": [ - "conversions", - "functional", - "string_manipulation" - ] - }, - { - "slug": "series", - "uuid": "14c3c478-9dc1-470b-8517-35c3ceac3f47", - "core": false, - "unlocked_by": null, - "difficulty": 3, - "topics": [ - "arrays", - "string_manipulation" - ] - }, - { - "slug": "triangle", - "uuid": "c9acd967-fc2a-4c74-b584-2572ce690e71", - "core": false, - "unlocked_by": null, - "difficulty": 2, - "topics": [ - "control_flow_if_statements", - "language_basics" - ] - }, - { - "slug": "crypto-square", - "uuid": "45afc532-3f6c-4b9e-90f6-c53a79551af1", - "core": false, - "unlocked_by": null, - "difficulty": 3, - "topics": [ - "algorithms", - "classes", - "string_manipulation" - ] - }, - { - "slug": "circular-buffer", - "uuid": "2ba799a8-eab9-44a0-9b31-a10e72baa38b", - "core": false, - "unlocked_by": null, - "difficulty": 4, - "topics": [ - "class_templates", - "data_structures" - ] - }, - { - "slug": "pangram", - "uuid": "a4cf4571-1f97-438c-9c02-3fe7c52ee25f", - "core": false, - "unlocked_by": null, - "difficulty": 1, - "topics": [ - "control_flow", - "language_basics", - "string_manipulation" - ] - }, - { - "slug": "react", - "uuid": "31dd1e53-2b5e-4d40-ac4c-a68fe5e6635c", - "core": false, - "unlocked_by": null, - "difficulty": 10, - "topics": [ - "delegates", - "generics", - "higher_order_functions", - "nested_classes", - "reactive_programming" - ] - }, - { - "slug": "run-length-encoding", - "uuid": "44d24e19-2600-469d-a405-d08d2a524b95", - "core": false, - "unlocked_by": null, - "difficulty": 4, - "topics": [ - "algorithms", - "control_flow_if_statements", - "strings" - ] - }, - { - "slug": "reverse-string", - "uuid": "298095e4-329f-402e-b3bc-28252eddd79b", - "core": false, - "unlocked_by": null, - "difficulty": 2, - "topics": [ - "strings" - ] - }, - { - "slug": "collatz-conjecture", - "uuid": "825e7682-7e09-4a8b-9bd5-ee67273054e6", - "core": false, - "unlocked_by": null, - "difficulty": 1, - "topics": [ - "loops", - "math" - ] - }, - { - "slug": "armstrong-numbers", - "uuid": "78b3eae1-7f3f-4e7c-8185-3532e80db4f3", - "core": false, - "unlocked_by": null, - "difficulty": 1, - "topics": [ - "algorithms", - "loops", - "math" - ] - }, - { - "slug": "two-fer", - "uuid": "4d9c55db-88c2-4cab-a456-f6d9844dbfdc", - "core": false, - "unlocked_by": null, - "difficulty": 1, - "topics": [ - "conditionals", - "optional_values", - "text_formatting" - ] - }, - { - "slug": "isogram", - "uuid": "833e59f1-6f81-405f-9412-7d0c42aaa2cb", - "core": false, - "unlocked_by": null, - "difficulty": 1, - "topics": [ - "algorithms", - "conditionals", - "loops", - "maps", - "strings" - ] - }, - { - "slug": "darts", - "uuid": "34ea72a7-8741-4421-812c-da4648c333ff", - "core": false, - "unlocked_by": null, - "difficulty": 1, - "topics": [ - "conditionals", - "floating_point_numbers", - "math" - ] - }, - { - "slug": "resistor-color", - "uuid": "975c6fb4-f447-42ee-a1df-62ea9ac5a011", - "core": false, - "unlocked_by": null, - "difficulty": 2, - "topics": [ - "arrays", - "strings" - ] - }, - { - "slug": "resistor-color-duo", - "uuid": "6fd7d4dd-7473-4530-a3dc-892be4321efb", - "core": false, - "unlocked_by": null, - "difficulty": 1, - "topics": [ - "arrays", - "transforming" - ] - }, - { - "slug": "perfect-numbers", - "uuid": "4382a967-c1fc-4295-ae95-077a103acc58", - "core": false, - "unlocked_by": null, - "difficulty": 3, - "topics": [ - "enumerations", - "exception_handling", - "filtering", - "integers", - "math" - ] - }, - { - "slug": "sum-of-multiples", - "uuid": "747d5874-2896-48fe-934c-030175d9729c", - "core": false, - "unlocked_by": null, - "difficulty": 1, - "topics": [ - "integers", - "math" - ] - }, - { - "slug": "prime-factors", - "uuid": "9042f732-2aa4-438c-90ca-7f0da088b9eb", - "core": false, - "unlocked_by": null, - "difficulty": 1, - "topics": [ - "integers", - "math" - ] - }, - { - "slug": "luhn", - "uuid": "c0374786-2736-42c4-93d3-7576abfece88", - "core": false, - "unlocked_by": null, - "difficulty": 1, - "topics": [ - "algorithms", - "integers", - "strings" - ] - }, - { - "slug": "nth-prime", - "uuid": "1e854d3a-afce-48ab-8802-d4d0a43eeca3", - "core": false, - "unlocked_by": null, - "difficulty": 1, - "topics": [ - "algorithms", - "lists", - "loops", - "math" - ] - }, - { - "slug": "matching-brackets", - "uuid": "ed189c57-0585-4534-a44a-e23d795f91a1", - "core": false, - "unlocked_by": null, - "difficulty": 1, - "topics": [ - "parsing", - "recursion", - "stacks", - "strings" - ] - }, - { - "slug": "grains", - "uuid": "e29d6573-0829-4ad8-9ae9-0160e70738ea", - "core": false, - "unlocked_by": null, - "difficulty": 4, - "topics": [ - "integers" - ] - } - ] -} +{ + "language": "D", + "active": true, + "blurb": "", + "checklist_issue": 6, + "test_pattern": "source.*[.]d", + "exercises": [ + { + "slug": "hello-world", + "uuid": "a91c2216-9331-4485-ae4b-190ee9e2a7f8", + "core": false, + "auto_approve": true, + "unlocked_by": null, + "difficulty": 1, + "topics": [ + "language_basics" + ] + }, + { + "slug": "leap", + "uuid": "9f52d6a7-1002-4614-afc3-cce03187c59b", + "core": false, + "unlocked_by": null, + "difficulty": 1, + "topics": [ + "language_basics" + ] + }, + { + "slug": "gigasecond", + "uuid": "8c976f92-fcfa-45f0-9bd1-2353822e51e8", + "core": false, + "unlocked_by": null, + "difficulty": 1, + "topics": [ + "language_basics", + "time" + ] + }, + { + "slug": "rna-transcription", + "uuid": "208f9a34-bdf2-4c2b-b102-f0ef1a5d04fe", + "core": false, + "unlocked_by": null, + "difficulty": 2, + "topics": [ + "control_flow_foreach", + "error_handling", + "string_manipulation" + ] + }, + { + "slug": "raindrops", + "uuid": "f6d21f86-b4d3-4dec-b830-8e19e1018548", + "core": false, + "unlocked_by": null, + "difficulty": 1, + "topics": [ + "control_flow_if_statements", + "language_basics" + ] + }, + { + "slug": "bob", + "uuid": "99ee69a6-2c0f-4c7c-86f9-bee1633b4f51", + "core": false, + "unlocked_by": null, + "difficulty": 2, + "topics": [ + "control_flow_if_statements", + "string_manipulation" + ] + }, + { + "slug": "etl", + "uuid": "dc631076-1eb8-4120-bd8f-dccf33df9a3f", + "core": false, + "unlocked_by": null, + "difficulty": 2, + "topics": [ + "associative_arrays", + "control_flow_foreach", + "string_manipulation" + ] + }, + { + "slug": "hamming", + "uuid": "87c87444-2349-40ab-a9a3-c0f0d2e200d6", + "core": false, + "unlocked_by": null, + "difficulty": 2, + "topics": [ + "control_flow_foreach", + "error_handling" + ] + }, + { + "slug": "nucleotide-count", + "uuid": "23b23ac0-62ef-4a22-b634-d64206c8a226", + "core": false, + "unlocked_by": null, + "difficulty": 3, + "topics": [ + "associative_arrays", + "classes", + "parsing" + ] + }, + { + "slug": "robot-name", + "uuid": "d7dd5df3-ff36-47ee-88db-e0f974a4cb19", + "core": false, + "unlocked_by": null, + "difficulty": 3, + "topics": [ + "classes", + "random_numbers" + ] + }, + { + "slug": "difference-of-squares", + "uuid": "d6c67e30-c950-40b6-b6db-0fa6df5652af", + "core": false, + "unlocked_by": null, + "difficulty": 2, + "topics": [ + "algorithms", + "control_flow_foreach", + "functional", + "math", + "template_metaprogramming" + ] + }, + { + "slug": "roman-numerals", + "uuid": "5647c00e-d4be-4546-bac3-6a3e1670c2a1", + "core": false, + "unlocked_by": null, + "difficulty": 3, + "topics": [ + "conversions", + "functional", + "string_manipulation" + ] + }, + { + "slug": "series", + "uuid": "14c3c478-9dc1-470b-8517-35c3ceac3f47", + "core": false, + "unlocked_by": null, + "difficulty": 3, + "topics": [ + "arrays", + "string_manipulation" + ] + }, + { + "slug": "triangle", + "uuid": "c9acd967-fc2a-4c74-b584-2572ce690e71", + "core": false, + "unlocked_by": null, + "difficulty": 2, + "topics": [ + "control_flow_if_statements", + "language_basics" + ] + }, + { + "slug": "crypto-square", + "uuid": "45afc532-3f6c-4b9e-90f6-c53a79551af1", + "core": false, + "unlocked_by": null, + "difficulty": 3, + "topics": [ + "algorithms", + "classes", + "string_manipulation" + ] + }, + { + "slug": "first-range", + "uuid": "5db8d8e8-ba48-4668-afc3-6949b898fd81", + "core": false, + "unlocked_by": null, + "difficulty": 1, + "topics": [ + "struct_templates", + "data_structures", + "containers" + ] + } + , + { + "slug": "circular-buffer", + "uuid": "2ba799a8-eab9-44a0-9b31-a10e72baa38b", + "core": false, + "unlocked_by": null, + "difficulty": 4, + "topics": [ + "class_templates", + "data_structures" + ] + }, + { + "slug": "pangram", + "uuid": "a4cf4571-1f97-438c-9c02-3fe7c52ee25f", + "core": false, + "unlocked_by": null, + "difficulty": 1, + "topics": [ + "control_flow", + "language_basics", + "string_manipulation" + ] + }, + { + "slug": "react", + "uuid": "31dd1e53-2b5e-4d40-ac4c-a68fe5e6635c", + "core": false, + "unlocked_by": null, + "difficulty": 10, + "topics": [ + "delegates", + "generics", + "higher_order_functions", + "nested_classes", + "reactive_programming" + ] + }, + { + "slug": "run-length-encoding", + "uuid": "44d24e19-2600-469d-a405-d08d2a524b95", + "core": false, + "unlocked_by": null, + "difficulty": 4, + "topics": [ + "algorithms", + "control_flow_if_statements", + "strings" + ] + }, + { + "slug": "reverse-string", + "uuid": "298095e4-329f-402e-b3bc-28252eddd79b", + "core": false, + "unlocked_by": null, + "difficulty": 2, + "topics": [ + "strings" + ] + }, + { + "slug": "collatz-conjecture", + "uuid": "825e7682-7e09-4a8b-9bd5-ee67273054e6", + "core": false, + "unlocked_by": null, + "difficulty": 1, + "topics": [ + "loops", + "math" + ] + }, + { + "slug": "armstrong-numbers", + "uuid": "78b3eae1-7f3f-4e7c-8185-3532e80db4f3", + "core": false, + "unlocked_by": null, + "difficulty": 1, + "topics": [ + "algorithms", + "loops", + "math" + ] + }, + { + "slug": "two-fer", + "uuid": "4d9c55db-88c2-4cab-a456-f6d9844dbfdc", + "core": false, + "unlocked_by": null, + "difficulty": 1, + "topics": [ + "conditionals", + "optional_values", + "text_formatting" + ] + }, + { + "slug": "isogram", + "uuid": "833e59f1-6f81-405f-9412-7d0c42aaa2cb", + "core": false, + "unlocked_by": null, + "difficulty": 1, + "topics": [ + "algorithms", + "conditionals", + "loops", + "maps", + "strings" + ] + }, + { + "slug": "darts", + "uuid": "34ea72a7-8741-4421-812c-da4648c333ff", + "core": false, + "unlocked_by": null, + "difficulty": 1, + "topics": [ + "conditionals", + "floating_point_numbers", + "math" + ] + }, + { + "slug": "resistor-color", + "uuid": "975c6fb4-f447-42ee-a1df-62ea9ac5a011", + "core": false, + "unlocked_by": null, + "difficulty": 2, + "topics": [ + "arrays", + "strings" + ] + }, + { + "slug": "resistor-color-duo", + "uuid": "6fd7d4dd-7473-4530-a3dc-892be4321efb", + "core": false, + "unlocked_by": null, + "difficulty": 1, + "topics": [ + "arrays", + "transforming" + ] + }, + { + "slug": "perfect-numbers", + "uuid": "4382a967-c1fc-4295-ae95-077a103acc58", + "core": false, + "unlocked_by": null, + "difficulty": 3, + "topics": [ + "enumerations", + "exception_handling", + "filtering", + "integers", + "math" + ] + }, + { + "slug": "sum-of-multiples", + "uuid": "747d5874-2896-48fe-934c-030175d9729c", + "core": false, + "unlocked_by": null, + "difficulty": 1, + "topics": [ + "integers", + "math" + ] + }, + { + "slug": "prime-factors", + "uuid": "9042f732-2aa4-438c-90ca-7f0da088b9eb", + "core": false, + "unlocked_by": null, + "difficulty": 1, + "topics": [ + "integers", + "math" + ] + }, + { + "slug": "luhn", + "uuid": "c0374786-2736-42c4-93d3-7576abfece88", + "core": false, + "unlocked_by": null, + "difficulty": 1, + "topics": [ + "algorithms", + "integers", + "strings" + ] + }, + { + "slug": "nth-prime", + "uuid": "1e854d3a-afce-48ab-8802-d4d0a43eeca3", + "core": false, + "unlocked_by": null, + "difficulty": 1, + "topics": [ + "algorithms", + "lists", + "loops", + "math" + ] + }, + { + "slug": "matching-brackets", + "uuid": "ed189c57-0585-4534-a44a-e23d795f91a1", + "core": false, + "unlocked_by": null, + "difficulty": 1, + "topics": [ + "parsing", + "recursion", + "stacks", + "strings" + ] + }, + { + "slug": "grains", + "uuid": "e29d6573-0829-4ad8-9ae9-0160e70738ea", + "core": false, + "unlocked_by": null, + "difficulty": 4, + "topics": [ + "integers" + ] + } + ] +} diff --git a/exercises/first-range/README.md b/exercises/first-range/README.md new file mode 100644 index 00000000..69ee8573 --- /dev/null +++ b/exercises/first-range/README.md @@ -0,0 +1,39 @@ +# The task +Your task is to construct a *generic* [Input Range](https://tour.dlang.org/tour/en/basics/ranges) that takes +an array, __copies__ it and then presents said copy through it's range interface. + +Also included, an introduction to D's type inference. + +## Getting Started + +Make sure you have read [D page](http://exercism.io/languages/d) on +exercism.io. This covers the basic information on setting up the development +environment expected by the exercises. + +## Passing the Tests + +Get the first test compiling, linking and passing by following the [three +rules of test-driven development](http://butunclebob.com/ArticleS.UncleBob.TheThreeRulesOfTdd). +Create just enough structure by declaring namespaces, functions, classes, +etc., to satisfy any compiler errors and get the test to fail. Then write +just enough code to get the test to pass. Once you've done that, +uncomment the next test by moving the following line past the next test. + +```D +version = moreTests; +``` + +This may result in compile errors as new constructs may be invoked that +you haven't yet declared or defined. Again, fix the compile errors minimally +to get a failing test, then change the code minimally to pass the test, +refactor your implementation for readability and expressiveness and then +go on to the next test. + +Try to use standard D facilities in preference to writing your own +low-level algorithms or facilities by hand. [DRefLanguage](https://dlang.org/spec/spec.html) +and [DReference](https://dlang.org/phobos/index.html) are references to the D language and D standard library. + + + +## Submitting Incomplete Solutions +It's possible to submit an incomplete solution so you can see how others have completed the exercise. diff --git a/exercises/first-range/dub.sdl b/exercises/first-range/dub.sdl new file mode 100644 index 00000000..370c312f --- /dev/null +++ b/exercises/first-range/dub.sdl @@ -0,0 +1,2 @@ +name "firstrange" +buildRequirements "disallowDeprecations" diff --git a/exercises/first-range/example/firstrange.d b/exercises/first-range/example/firstrange.d new file mode 100644 index 00000000..ddb05c9c --- /dev/null +++ b/exercises/first-range/example/firstrange.d @@ -0,0 +1,54 @@ +module firstrange; + +import std.range; +import std.algorithm; +auto myFirstRange(T)(const T[] data) +{ + struct myFirstRange(Type) + { + private + { + immutable Type[] data; + size_t loc = 0; + } + this(const Type[] pData) + { + data = pData.idup; + } + + @property Type front() const + { + return data[loc]; + } + + void popFront() + { + ++loc; + } + + bool empty() + { + return data.length == loc; + } + } + return myFirstRange!T(data); +} + +version = moreTests; +@safe unittest +{ + auto rng = myFirstRange!int([0, 1, 2, 3, 4]); + typeof(rng.front) count; + foreach (elem; rng) + { + count += elem; + } + assert(count == 10); + + version (moreTests) + { + //Can you get this(just the line below) syntax working? + auto inferredRange = myFirstRange([1, 4, 5]); + assert(inferredRange.map!(x => 2 * x).sum == 20); + } +} diff --git a/exercises/first-range/source/firstrange.d b/exercises/first-range/source/firstrange.d new file mode 100644 index 00000000..5b25b54b --- /dev/null +++ b/exercises/first-range/source/firstrange.d @@ -0,0 +1,23 @@ +module firstrange; +import std.range; +import std.algorithm; + + +version = moreTests; +@safe unittest +{ + auto rng = myFirstRange!int([0, 1, 2, 3, 4]); + typeof(rng.front) count; + foreach (elem; rng) + { + count += elem; + } + assert(count == 10); + + version (moreTests) + { + //Can you get this(just the line below) syntax working? + auto inferredRange = myFirstRange([1, 4, 5]); + assert(inferredRange.map!(x => 2 * x).sum == 20); + } +}