From b9aef7c1b3f22fc76b338475eda078650220f14e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20B=20Nagy?= <20251272+BNAndras@users.noreply.github.com> Date: Wed, 11 Feb 2026 08:03:29 -0800 Subject: [PATCH] Add `resistor-color-trio` --- config.json | 8 ++ .../resistor-color-trio/.docs/instructions.md | 56 +++++++++++ .../resistor-color-trio/.meta/config.json | 19 ++++ .../resistor-color-trio/.meta/tests.toml | 40 ++++++++ .../.meta/zcl_resistor_color_trio.clas.abap | 71 ++++++++++++++ .../resistor-color-trio/package.devc.xml | 10 ++ .../zcl_resistor_color_trio.clas.abap | 21 ++++ ..._resistor_color_trio.clas.testclasses.abap | 98 +++++++++++++++++++ .../zcl_resistor_color_trio.clas.xml | 17 ++++ 9 files changed, 340 insertions(+) create mode 100644 exercises/practice/resistor-color-trio/.docs/instructions.md create mode 100644 exercises/practice/resistor-color-trio/.meta/config.json create mode 100644 exercises/practice/resistor-color-trio/.meta/tests.toml create mode 100644 exercises/practice/resistor-color-trio/.meta/zcl_resistor_color_trio.clas.abap create mode 100644 exercises/practice/resistor-color-trio/package.devc.xml create mode 100644 exercises/practice/resistor-color-trio/zcl_resistor_color_trio.clas.abap create mode 100644 exercises/practice/resistor-color-trio/zcl_resistor_color_trio.clas.testclasses.abap create mode 100644 exercises/practice/resistor-color-trio/zcl_resistor_color_trio.clas.xml diff --git a/config.json b/config.json index 161cd9f..3171830 100644 --- a/config.json +++ b/config.json @@ -134,6 +134,14 @@ "prerequisites": [], "difficulty": 1 }, + { + "slug": "resistor-color-trio", + "name": "Resistor Color Trio", + "uuid": "5d31468c-8e83-4901-8e08-0397f09e0462", + "practices": [], + "prerequisites": [], + "difficulty": 1 + }, { "slug": "leap", "name": "Leap", diff --git a/exercises/practice/resistor-color-trio/.docs/instructions.md b/exercises/practice/resistor-color-trio/.docs/instructions.md new file mode 100644 index 0000000..1ac5cf5 --- /dev/null +++ b/exercises/practice/resistor-color-trio/.docs/instructions.md @@ -0,0 +1,56 @@ +# Instructions + +If you want to build something using a Raspberry Pi, you'll probably use _resistors_. +For this exercise, you need to know only three 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 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. + 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 3 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 Duo you decoded the first two colors. +For instance: orange-orange got the main value `33`. +The third color stands for how many zeros need to be added to the main value. +The main value plus the zeros gives us a value in ohms. +For the exercise it doesn't matter what ohms really are. +For example: + +- orange-orange-black would be 33 and no zeros, which becomes 33 ohms. +- orange-orange-red would be 33 and 2 zeros, which becomes 3300 ohms. +- orange-orange-orange would be 33 and 3 zeros, which becomes 33000 ohms. + +(If Math is your thing, you may want to think of the zeros as exponents of 10. +If Math is not your thing, go with the zeros. +It really is the same thing, just in plain English instead of Math lingo.) + +This exercise is about translating the colors into a label: + +> "... ohms" + +So an input of `"orange", "orange", "black"` should return: + +> "33 ohms" + +When we get to larger resistors, a [metric prefix][metric-prefix] is used to indicate a larger magnitude of ohms, such as "kiloohms". +That is similar to saying "2 kilometers" instead of "2000 meters", or "2 kilograms" for "2000 grams". + +For example, an input of `"orange", "orange", "orange"` should return: + +> "33 kiloohms" + +[metric-prefix]: https://en.wikipedia.org/wiki/Metric_prefix diff --git a/exercises/practice/resistor-color-trio/.meta/config.json b/exercises/practice/resistor-color-trio/.meta/config.json new file mode 100644 index 0000000..857da15 --- /dev/null +++ b/exercises/practice/resistor-color-trio/.meta/config.json @@ -0,0 +1,19 @@ +{ + "authors": [ + "BNAndras" + ], + "files": { + "solution": [ + "zcl_resistor_color_trio.clas.abap" + ], + "test": [ + "zcl_resistor_color_trio.clas.testclasses.abap" + ], + "example": [ + ".meta/zcl_resistor_color_trio.clas.abap" + ] + }, + "blurb": "Convert color codes, as used on resistors, to a human-readable label.", + "source": "Maud de Vries, Erik Schierboom", + "source_url": "https://github.com/exercism/problem-specifications/issues/1549" +} diff --git a/exercises/practice/resistor-color-trio/.meta/tests.toml b/exercises/practice/resistor-color-trio/.meta/tests.toml new file mode 100644 index 0000000..b7d45fa --- /dev/null +++ b/exercises/practice/resistor-color-trio/.meta/tests.toml @@ -0,0 +1,40 @@ +# 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. + +[d6863355-15b7-40bb-abe0-bfb1a25512ed] +description = "Orange and orange and black" + +[1224a3a9-8c8e-4032-843a-5224e04647d6] +description = "Blue and grey and brown" + +[b8bda7dc-6b95-4539-abb2-2ad51d66a207] +description = "Red and black and red" + +[5b1e74bc-d838-4eda-bbb3-eaba988e733b] +description = "Green and brown and orange" + +[f5d37ef9-1919-4719-a90d-a33c5a6934c9] +description = "Yellow and violet and yellow" + +[5f6404a7-5bb3-4283-877d-3d39bcc33854] +description = "Blue and violet and blue" + +[7d3a6ab8-e40e-46c3-98b1-91639fff2344] +description = "Minimum possible value" + +[ca0aa0ac-3825-42de-9f07-dac68cc580fd] +description = "Maximum possible value" + +[0061a76c-903a-4714-8ce2-f26ce23b0e09] +description = "First two colors make an invalid octal number" + +[30872c92-f567-4b69-a105-8455611c10c4] +description = "Ignore extra colors" diff --git a/exercises/practice/resistor-color-trio/.meta/zcl_resistor_color_trio.clas.abap b/exercises/practice/resistor-color-trio/.meta/zcl_resistor_color_trio.clas.abap new file mode 100644 index 0000000..a2756fe --- /dev/null +++ b/exercises/practice/resistor-color-trio/.meta/zcl_resistor_color_trio.clas.abap @@ -0,0 +1,71 @@ +CLASS zcl_resistor_color_trio DEFINITION + PUBLIC + FINAL + CREATE PUBLIC. + + PUBLIC SECTION. + METHODS label + IMPORTING + colors TYPE string_table + RETURNING + VALUE(result) TYPE string. + PROTECTED SECTION. + PRIVATE SECTION. + METHODS color_code + IMPORTING + color TYPE string + RETURNING + VALUE(result) TYPE i. +ENDCLASS. + +CLASS zcl_resistor_color_trio IMPLEMENTATION. + METHOD label. + DATA(color1) = colors[ 1 ]. + DATA(color2) = colors[ 2 ]. + DATA(color3) = colors[ 3 ]. + + DATA(base_value) = color_code( color1 ) * 10 + color_code( color2 ). + DATA(zeros) = color_code( color3 ). + + DATA(formatted_value) = base_value * ( 10 ** zeros ). + DATA(unit) = CONV string( 'ohms' ). + + IF formatted_value >= 1000000000. + formatted_value = formatted_value / 1000000000. + unit = 'gigaohms'. + ELSEIF formatted_value >= 1000000. + formatted_value = formatted_value / 1000000. + unit = 'megaohms'. + ELSEIF formatted_value >= 1000. + formatted_value = formatted_value / 1000. + unit = 'kiloohms'. + ENDIF. + + result = |{ formatted_value } { unit }|. + ENDMETHOD. + + METHOD color_code. + CASE color. + WHEN 'black'. + result = 0. + WHEN 'brown'. + result = 1. + WHEN 'red'. + result = 2. + WHEN 'orange'. + result = 3. + WHEN 'yellow'. + result = 4. + WHEN 'green'. + result = 5. + WHEN 'blue'. + result = 6. + WHEN 'violet'. + result = 7. + WHEN 'grey'. + result = 8. + WHEN 'white'. + result = 9. + ENDCASE. + ENDMETHOD. +ENDCLASS. diff --git a/exercises/practice/resistor-color-trio/package.devc.xml b/exercises/practice/resistor-color-trio/package.devc.xml new file mode 100644 index 0000000..bbbfa52 --- /dev/null +++ b/exercises/practice/resistor-color-trio/package.devc.xml @@ -0,0 +1,10 @@ + + + + + + Exercism: Resistor Color Trio + + + + diff --git a/exercises/practice/resistor-color-trio/zcl_resistor_color_trio.clas.abap b/exercises/practice/resistor-color-trio/zcl_resistor_color_trio.clas.abap new file mode 100644 index 0000000..347e5f6 --- /dev/null +++ b/exercises/practice/resistor-color-trio/zcl_resistor_color_trio.clas.abap @@ -0,0 +1,21 @@ +CLASS zcl_resistor_color_trio DEFINITION + PUBLIC + FINAL + CREATE PUBLIC. + + PUBLIC SECTION. + METHODS label + IMPORTING + colors TYPE string_table + RETURNING + VALUE(result) TYPE string. + PROTECTED SECTION. + PRIVATE SECTION. + +ENDCLASS. + +CLASS zcl_resistor_color_trio IMPLEMENTATION. + METHOD label. + "Implement solution + ENDMETHOD. +ENDCLASS. diff --git a/exercises/practice/resistor-color-trio/zcl_resistor_color_trio.clas.testclasses.abap b/exercises/practice/resistor-color-trio/zcl_resistor_color_trio.clas.testclasses.abap new file mode 100644 index 0000000..a361939 --- /dev/null +++ b/exercises/practice/resistor-color-trio/zcl_resistor_color_trio.clas.testclasses.abap @@ -0,0 +1,98 @@ +*"* use this source file for your ABAP unit test classes +CLASS ltcl_resistor_color_trio DEFINITION FINAL FOR TESTING + DURATION SHORT + RISK LEVEL HARMLESS. + + PRIVATE SECTION. + DATA cut TYPE REF TO zcl_resistor_color_trio. + METHODS setup. + METHODS: + test_orange_and_orange_black FOR TESTING, + test_blue_and_grey_brown FOR TESTING, + test_red_and_black_red FOR TESTING, + test_green_and_brown_orange FOR TESTING, + test_yellow_and_violet_yellow FOR TESTING, + test_blue_and_violet_blue FOR TESTING, + test_minimum_possible_value FOR TESTING, + test_maximum_possible_value FOR TESTING, + test_invalid_octal FOR TESTING, + test_ignore_extra_colors FOR TESTING. +ENDCLASS. + +CLASS ltcl_resistor_color_trio IMPLEMENTATION. + + METHOD setup. + cut = NEW zcl_resistor_color_trio( ). + ENDMETHOD. + + METHOD test_orange_and_orange_black. + DATA(input_colors) = VALUE string_table( ( `orange` ) ( `orange` ) ( `black` ) ). + cl_abap_unit_assert=>assert_equals( + act = cut->label( input_colors ) + exp = '33 ohms' ). + ENDMETHOD. + + METHOD test_blue_and_grey_brown. + DATA(input_colors) = VALUE string_table( ( `blue` ) ( `grey` ) ( `brown` ) ). + cl_abap_unit_assert=>assert_equals( + act = cut->label( input_colors ) + exp = '680 ohms' ). + ENDMETHOD. + + METHOD test_red_and_black_red. + DATA(input_colors) = VALUE string_table( ( `red` ) ( `black` ) ( `red` ) ). + cl_abap_unit_assert=>assert_equals( + act = cut->label( input_colors ) + exp = '2 kiloohms' ). + ENDMETHOD. + + METHOD test_green_and_brown_orange. + DATA(input_colors) = VALUE string_table( ( `green` ) ( `brown` ) ( `orange` ) ). + cl_abap_unit_assert=>assert_equals( + act = cut->label( input_colors ) + exp = '51 kiloohms' ). + ENDMETHOD. + + METHOD test_yellow_and_violet_yellow. + DATA(input_colors) = VALUE string_table( ( `yellow` ) ( `violet` ) ( `yellow` ) ). + cl_abap_unit_assert=>assert_equals( + act = cut->label( input_colors ) + exp = '470 kiloohms' ). + ENDMETHOD. + + METHOD test_blue_and_violet_blue. + DATA(input_colors) = VALUE string_table( ( `blue` ) ( `violet` ) ( `blue` ) ). + cl_abap_unit_assert=>assert_equals( + act = cut->label( input_colors ) + exp = '67 megaohms' ). + ENDMETHOD. + + METHOD test_minimum_possible_value. + DATA(input_colors) = VALUE string_table( ( `black` ) ( `black` ) ( `black` ) ). + cl_abap_unit_assert=>assert_equals( + act = cut->label( input_colors ) + exp = '0 ohms' ). + ENDMETHOD. + + METHOD test_maximum_possible_value. + DATA(input_colors) = VALUE string_table( ( `white` ) ( `white` ) ( `white` ) ). + cl_abap_unit_assert=>assert_equals( + act = cut->label( input_colors ) + exp = '99 gigaohms' ). + ENDMETHOD. + + METHOD test_invalid_octal. + DATA(input_colors) = VALUE string_table( ( `black` ) ( `grey` ) ( `black` ) ). + cl_abap_unit_assert=>assert_equals( + act = cut->label( input_colors ) + exp = '8 ohms' ). + ENDMETHOD. + + METHOD test_ignore_extra_colors. + DATA(input_colors) = VALUE string_table( ( `blue` ) ( `green` ) ( `yellow` ) ( `orange` ) ). + cl_abap_unit_assert=>assert_equals( + act = cut->label( input_colors ) + exp = '650 kiloohms' ). + ENDMETHOD. + +ENDCLASS. \ No newline at end of file diff --git a/exercises/practice/resistor-color-trio/zcl_resistor_color_trio.clas.xml b/exercises/practice/resistor-color-trio/zcl_resistor_color_trio.clas.xml new file mode 100644 index 0000000..fd81446 --- /dev/null +++ b/exercises/practice/resistor-color-trio/zcl_resistor_color_trio.clas.xml @@ -0,0 +1,17 @@ + + + + + + ZCL_RESISTOR_COLOR_TRIO + E + Exercism: Resistor Color Trio + 1 + X + X + X + X + + + +