diff --git a/config.json b/config.json index c6540cc0..1d226374 100644 --- a/config.json +++ b/config.json @@ -691,6 +691,14 @@ "unicode" ] }, + { + "slug": "resistor-color", + "name": "Resistor Color", + "uuid": "ef7e22db-1f66-4d44-87f9-23d97f794628", + "practices": [], + "prerequisites": [], + "difficulty": 1 + }, { "slug": "resistor-color-trio", "name": "Resistor Color Trio", diff --git a/exercises/practice/resistor-color/.docs/instructions.md b/exercises/practice/resistor-color/.docs/instructions.md new file mode 100644 index 00000000..646c1439 --- /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/config.json b/exercises/practice/resistor-color/.meta/config.json new file mode 100644 index 00000000..c62ab5c6 --- /dev/null +++ b/exercises/practice/resistor-color/.meta/config.json @@ -0,0 +1,19 @@ +{ + "authors": [ + "BNAndras" + ], + "files": { + "solution": [ + "resistor-color.jl" + ], + "test": [ + "runtests.jl" + ], + "example": [ + ".meta/example.jl" + ] + }, + "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/example.jl b/exercises/practice/resistor-color/.meta/example.jl new file mode 100644 index 00000000..059adeff --- /dev/null +++ b/exercises/practice/resistor-color/.meta/example.jl @@ -0,0 +1,20 @@ +const COLORS = ( + "black", + "brown", + "red", + "orange", + "yellow", + "green", + "blue", + "violet", + "grey", + "white" +) + +function colorcode(color) + findfirst(==(color), COLORS) - 1 +end + +function colors() + COLORS +end diff --git a/exercises/practice/resistor-color/.meta/tests.toml b/exercises/practice/resistor-color/.meta/tests.toml new file mode 100644 index 00000000..9d4ee973 --- /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/resistor-color.jl b/exercises/practice/resistor-color/resistor-color.jl new file mode 100644 index 00000000..6c0dbe74 --- /dev/null +++ b/exercises/practice/resistor-color/resistor-color.jl @@ -0,0 +1,7 @@ +function colorcode(color) + +end + +function colors() + +end \ No newline at end of file diff --git a/exercises/practice/resistor-color/runtests.jl b/exercises/practice/resistor-color/runtests.jl new file mode 100644 index 00000000..fc2c0285 --- /dev/null +++ b/exercises/practice/resistor-color/runtests.jl @@ -0,0 +1,33 @@ +using Test + +include("resistor-color.jl") + +@testset verbose = true "Resistor Color" begin + @testset "Black" begin + @test colorcode("black") == 0 + end + + @testset "White" begin + @test colorcode("white") == 9 + end + + @testset "Orange" begin + @test colorcode("orange") == 3 + end + + @testset "Colors" begin + expected_colors = [ + "black", + "brown", + "red", + "orange", + "yellow", + "green", + "blue", + "violet", + "grey", + "white" + ] + @test all(colors() .== expected_colors) + end +end