diff --git a/config.json b/config.json index aa92e417f..774192c39 100644 --- a/config.json +++ b/config.json @@ -2117,6 +2117,14 @@ "lists" ], "difficulty": 5 + }, + { + "slug": "resistor-color", + "name": "Resistor Color", + "uuid": "bd2bd26c-6eab-411d-8472-7643cb86c6c9", + "practices": [], + "prerequisites": [], + "difficulty": 1 } ], "foregone": [ diff --git a/exercises/Exercises.sln b/exercises/Exercises.sln index 67a00ca54..4e6ebdb9a 100644 --- a/exercises/Exercises.sln +++ b/exercises/Exercises.sln @@ -279,6 +279,8 @@ Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "ZebraPuzzle", "practice\zeb EndProject Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Zipper", "practice\zipper\Zipper.fsproj", "{73AB6DA8-AA91-44A9-B5E5-0670FFB6A4AC}" EndProject +Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "ResistorColor", "practice\resistor-color\ResistorColor.fsproj", "{6D2CFE86-D6B2-4820-B3D8-62255BF94DCD}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -832,6 +834,10 @@ Global {73AB6DA8-AA91-44A9-B5E5-0670FFB6A4AC}.Debug|Any CPU.Build.0 = Debug|Any CPU {73AB6DA8-AA91-44A9-B5E5-0670FFB6A4AC}.Release|Any CPU.ActiveCfg = Release|Any CPU {73AB6DA8-AA91-44A9-B5E5-0670FFB6A4AC}.Release|Any CPU.Build.0 = Release|Any CPU + {6D2CFE86-D6B2-4820-B3D8-62255BF94DCD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6D2CFE86-D6B2-4820-B3D8-62255BF94DCD}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6D2CFE86-D6B2-4820-B3D8-62255BF94DCD}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6D2CFE86-D6B2-4820-B3D8-62255BF94DCD}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(NestedProjects) = preSolution {9815492D-D8F9-439C-B73C-711693755626} = {9D239135-8242-4AC0-94AE-7CCD8408B531} @@ -970,5 +976,6 @@ Global {FA29F301-0448-47A3-941C-ABB8A8ED367A} = {29984DF2-2734-483C-BC7D-F6D41599DACD} {F6217F6F-DD9C-4DBD-8A7A-894E05FCF78E} = {29984DF2-2734-483C-BC7D-F6D41599DACD} {73AB6DA8-AA91-44A9-B5E5-0670FFB6A4AC} = {29984DF2-2734-483C-BC7D-F6D41599DACD} + {6D2CFE86-D6B2-4820-B3D8-62255BF94DCD} = {29984DF2-2734-483C-BC7D-F6D41599DACD} EndGlobalSection EndGlobal diff --git a/exercises/practice/resistor-color/.config/dotnet-tools.json b/exercises/practice/resistor-color/.config/dotnet-tools.json new file mode 100644 index 000000000..0f7926bad --- /dev/null +++ b/exercises/practice/resistor-color/.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/resistor-color/.docs/instructions.md b/exercises/practice/resistor-color/.docs/instructions.md new file mode 100644 index 000000000..0125e718b --- /dev/null +++ b/exercises/practice/resistor-color/.docs/instructions.md @@ -0,0 +1,39 @@ +# Instructions + +If you want to build something using a Raspberry Pi, you'll probably use _resistors_. +For this exercise, you need to know two things about them: + +- Each resistor has a resistance value. +- Resistors are small - so small in fact that if you printed the resistance value on them, it would be hard to read. + +To get around this problem, manufacturers print color-coded bands onto the resistors to denote their resistance values. +Each band has a position and a numeric value. + +The first 2 bands of a resistor have a simple encoding scheme: each color maps to a single number. + +In this exercise you are going to create a helpful program so that you don't have to remember the values of the bands. + +These colors are encoded as follows: + +- black: 0 +- brown: 1 +- red: 2 +- orange: 3 +- yellow: 4 +- green: 5 +- blue: 6 +- violet: 7 +- grey: 8 +- white: 9 + +The goal of this exercise is to create a way: + +- to look up the numerical value associated with a particular color band +- to list the different band colors + +Mnemonics map the colors to the numbers, that, when stored as an array, happen to map to their index in the array: +Better Be Right Or Your Great Big Values Go Wrong. + +More information on the color encoding of resistors can be found in the [Electronic color code Wikipedia article][e-color-code]. + +[e-color-code]: https://en.wikipedia.org/wiki/Electronic_color_code diff --git a/exercises/practice/resistor-color/.meta/Example.fs b/exercises/practice/resistor-color/.meta/Example.fs new file mode 100644 index 000000000..a282628f0 --- /dev/null +++ b/exercises/practice/resistor-color/.meta/Example.fs @@ -0,0 +1,15 @@ +module ResistorColor + +let colors = + [ "black" + "brown" + "red" + "orange" + "yellow" + "green" + "blue" + "violet" + "grey" + "white" ] + +let colorCode color = List.findIndex ((=) color) colors diff --git a/exercises/practice/resistor-color/.meta/config.json b/exercises/practice/resistor-color/.meta/config.json new file mode 100644 index 000000000..6e70a8782 --- /dev/null +++ b/exercises/practice/resistor-color/.meta/config.json @@ -0,0 +1,19 @@ +{ + "authors": [ + "erikschierboom" + ], + "files": { + "solution": [ + "ResistorColor.fs" + ], + "test": [ + "ResistorColorTests.fs" + ], + "example": [ + ".meta/Example.fs" + ] + }, + "blurb": "Convert a resistor band's color to its numeric representation.", + "source": "Maud de Vries, Erik Schierboom", + "source_url": "https://github.com/exercism/problem-specifications/issues/1458" +} diff --git a/exercises/practice/resistor-color/.meta/tests.toml b/exercises/practice/resistor-color/.meta/tests.toml new file mode 100644 index 000000000..9d4ee9737 --- /dev/null +++ b/exercises/practice/resistor-color/.meta/tests.toml @@ -0,0 +1,22 @@ +# 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. + +[49eb31c5-10a8-4180-9f7f-fea632ab87ef] +description = "Color codes -> Black" + +[0a4df94b-92da-4579-a907-65040ce0b3fc] +description = "Color codes -> White" + +[5f81608d-f36f-4190-8084-f45116b6f380] +description = "Color codes -> Orange" + +[581d68fa-f968-4be2-9f9d-880f2fb73cf7] +description = "Colors" diff --git a/exercises/practice/resistor-color/ResistorColor.fs b/exercises/practice/resistor-color/ResistorColor.fs new file mode 100644 index 000000000..5a8afa26c --- /dev/null +++ b/exercises/practice/resistor-color/ResistorColor.fs @@ -0,0 +1,6 @@ +module ResistorColor + +let colors: string list = failwith "You need to define the 'colors' binding." + +let colorCode (color: string) string = + failwith "Please implement the 'colorCode' function" diff --git a/exercises/practice/resistor-color/ResistorColor.fsproj b/exercises/practice/resistor-color/ResistorColor.fsproj new file mode 100644 index 000000000..ffd04dd4a --- /dev/null +++ b/exercises/practice/resistor-color/ResistorColor.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/resistor-color/ResistorColorTests.fs b/exercises/practice/resistor-color/ResistorColorTests.fs new file mode 100644 index 000000000..ce20e9b3a --- /dev/null +++ b/exercises/practice/resistor-color/ResistorColorTests.fs @@ -0,0 +1,31 @@ +module ResistorColorTests + +open FsUnit.Xunit +open Xunit + +open ResistorColor + +[] +let ``Black`` () = colorCode "black" |> should equal 0 + +[] +let ``White`` () = colorCode "white" |> should equal 9 + +[] +let ``Orange`` () = colorCode "orange" |> should equal 3 + +[] +let ``Colors`` () = + colors + |> should + equal + [ "black" + "brown" + "red" + "orange" + "yellow" + "green" + "blue" + "violet" + "grey" + "white" ] diff --git a/generators/Generators.fs b/generators/Generators.fs index c587380fb..b19b7b105 100644 --- a/generators/Generators.fs +++ b/generators/Generators.fs @@ -2029,3 +2029,6 @@ type GameOfLife() = match Seq.isEmpty value with | true -> Some "int[,]" | false -> None + +type ResistorColor() = + inherit ExerciseGenerator()