From f441205a808becef0332613d839d4b6bd698fe72 Mon Sep 17 00:00:00 2001 From: manumafe98 Date: Fri, 19 Apr 2024 14:10:55 -0300 Subject: [PATCH] Starting to add practice exercise resistor-color-expert --- config.json | 10 +++ .../.docs/instructions.md | 79 +++++++++++++++++++ .../.docs/introduction.md | 10 +++ .../resistor-color-expert/.meta/config.json | 22 ++++++ .../reference/java/ResistorColorExpert.java | 3 + .../src/main/java/ResistorColorExpert.java | 3 + .../test/java/ResistorColorExpertTest.java | 3 + exercises/settings.gradle | 1 + 8 files changed, 131 insertions(+) create mode 100644 exercises/practice/resistor-color-expert/.docs/instructions.md create mode 100644 exercises/practice/resistor-color-expert/.docs/introduction.md create mode 100644 exercises/practice/resistor-color-expert/.meta/config.json create mode 100644 exercises/practice/resistor-color-expert/.meta/src/reference/java/ResistorColorExpert.java create mode 100644 exercises/practice/resistor-color-expert/src/main/java/ResistorColorExpert.java create mode 100644 exercises/practice/resistor-color-expert/src/test/java/ResistorColorExpertTest.java diff --git a/config.json b/config.json index 0b281151c..96edde27f 100644 --- a/config.json +++ b/config.json @@ -488,6 +488,16 @@ ], "difficulty": 2 }, + { + "slug": "resistor-color-expert", + "name": "Resistor Color Expert", + "uuid": "9be3fb37-9b52-4e23-bb4f-0c7a8c4c3299", + "practices": [], + "prerequisites": [ + "arrays" + ], + "difficulty": 2 + }, { "slug": "rna-transcription", "name": "RNA Transcription", diff --git a/exercises/practice/resistor-color-expert/.docs/instructions.md b/exercises/practice/resistor-color-expert/.docs/instructions.md new file mode 100644 index 000000000..7a110832c --- /dev/null +++ b/exercises/practice/resistor-color-expert/.docs/instructions.md @@ -0,0 +1,79 @@ +# Instructions + +In this exercise, you are going to create a helpful program so that you don't have to remember the values of the bands. +The program will take 1, 4, or 5 colors as input, and outputs the correct value, in ohms. +The color bands are encoded as follows: + +- Black: 0 +- Brown: 1 +- Red: 2 +- Orange: 3 +- Yellow: 4 +- Green: 5 +- Blue: 6 +- Violet: 7 +- Grey: 8 +- White: 9 + +In `resistor-color trio` you decoded the first three colors. +For instance: orange-orange-brown translated to the main value `330`. +In this exercise you will need to add _tolerance_ to the mix. +Tolerance is the maximum amount that a value can be above or below the main value. +For example, if the last band is green, the maximum tolerance will be ±0.5%. + +The tolerance band will have one of these values: + +- Grey - 0.05% +- Violet - 0.1% +- Blue - 0.25% +- Green - 0.5% +- Brown - 1% +- Red - 2% +- Gold - 5% +- Silver - 10% + +The four-band resistor is built up like this: + +| Band_1 | Band_2 | Band_3 | band_4 | +| ------- | ------- | ---------- | --------- | +| Value_1 | Value_2 | Multiplier | Tolerance | + +Meaning + +- orange-orange-brown-green would be 330 ohms with a ±0.5% tolerance. +- orange-orange-red-grey would be 3300 ohms with ±0.05% tolerance. + +The difference between a four and five-band resistor is that the five-band resistor has an extra band to indicate a more precise value. + +| Band_1 | Band_2 | Band_3 | Band_4 | band_5 | +| ------- | ------- | ------- | ---------- | --------- | +| Value_1 | Value_2 | Value_3 | Multiplier | Tolerance | + +Meaning + +- orange-orange-orange-black-green would be 333 ohms with a ±0.5% tolerance. +- orange-red-orange-blue-violet would be 323M ohms with a ±0.10 tolerance. + +There are also one band resistors. +One band resistors only have the color black with a value of 0. + +This exercise is about translating the resistor band colors into a label: + +"... ohms ...%" + +So an input of "orange", "orange", "black", "green" should return: + +"33 ohms ±0.5%" + +When there are more than a thousand ohms, we say "kiloohms". + That's similar to saying "kilometer" for 1000 meters, and "kilograms" for 1000 grams. + +So an input of "orange", "orange", "orange", "grey" should return: + +"33 kiloohms ±0.05%" + +When there are more than a million ohms, we say "megaohms". + +So an input of "orange", "orange", "blue", "red" should return: + +"33 megaohms ±2%" diff --git a/exercises/practice/resistor-color-expert/.docs/introduction.md b/exercises/practice/resistor-color-expert/.docs/introduction.md new file mode 100644 index 000000000..fd9e05efc --- /dev/null +++ b/exercises/practice/resistor-color-expert/.docs/introduction.md @@ -0,0 +1,10 @@ +# Introduction + +If you want to build something using a Raspberry Pi, you'll probably use _resistors_. +Like the previous `Resistor Color Duo` and `Resistor Color Trio` exercises, you will be translating resistor color bands to human-readable labels. + +- 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 acts as a digit of a number. + For example, if they printed a brown band (value 1) followed by a green band (value 5), it would translate to the number 15. diff --git a/exercises/practice/resistor-color-expert/.meta/config.json b/exercises/practice/resistor-color-expert/.meta/config.json new file mode 100644 index 000000000..e1e5278d4 --- /dev/null +++ b/exercises/practice/resistor-color-expert/.meta/config.json @@ -0,0 +1,22 @@ +{ + "authors": [ + "manumafe98" + ], + "files": { + "solution": [ + "src/main/java/ResistorColorExpert.java" + ], + "test": [ + "src/test/java/ResistorColorExpertTest.java" + ], + "example": [ + ".meta/src/reference/java/ResistorColorExpert.java" + ], + "invalidator": [ + "build.gradle" + ] + }, + "blurb": "Convert color codes as used on resistors with different bands to a human-readable label.", + "source": "Based on earlier resistor color exercises made by Erik Schierboom and Maud de Vries", + "source_url": "https://github.com/exercism/problem-specifications/issues/1464" +} diff --git a/exercises/practice/resistor-color-expert/.meta/src/reference/java/ResistorColorExpert.java b/exercises/practice/resistor-color-expert/.meta/src/reference/java/ResistorColorExpert.java new file mode 100644 index 000000000..2348bc46e --- /dev/null +++ b/exercises/practice/resistor-color-expert/.meta/src/reference/java/ResistorColorExpert.java @@ -0,0 +1,3 @@ +class ResistorColorExpert { + +} diff --git a/exercises/practice/resistor-color-expert/src/main/java/ResistorColorExpert.java b/exercises/practice/resistor-color-expert/src/main/java/ResistorColorExpert.java new file mode 100644 index 000000000..2348bc46e --- /dev/null +++ b/exercises/practice/resistor-color-expert/src/main/java/ResistorColorExpert.java @@ -0,0 +1,3 @@ +class ResistorColorExpert { + +} diff --git a/exercises/practice/resistor-color-expert/src/test/java/ResistorColorExpertTest.java b/exercises/practice/resistor-color-expert/src/test/java/ResistorColorExpertTest.java new file mode 100644 index 000000000..1c4635369 --- /dev/null +++ b/exercises/practice/resistor-color-expert/src/test/java/ResistorColorExpertTest.java @@ -0,0 +1,3 @@ +public class ResistorColorExpertTest { + +} diff --git a/exercises/settings.gradle b/exercises/settings.gradle index 916d7dd7f..a330eda28 100644 --- a/exercises/settings.gradle +++ b/exercises/settings.gradle @@ -118,6 +118,7 @@ include 'practice:rectangles' include 'practice:resistor-color' include 'practice:resistor-color-duo' include 'practice:resistor-color-trio' +include 'practice:resistor-color-expert' include 'practice:rest-api' include 'practice:reverse-string' include 'practice:rna-transcription'