From f90dc78e1684fd557de10f011b11bc0b5dbf3b1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20B=20Nagy?= <20251272+BNAndras@users.noreply.github.com> Date: Sun, 8 Oct 2023 15:52:45 -0700 Subject: [PATCH 1/2] Add resistor-color-duo --- config.json | 8 +++++ .../resistor-color-duo/.docs/instructions.md | 33 +++++++++++++++++ .../resistor-color-duo/.meta/config.json | 19 ++++++++++ .../resistor-color-duo/.meta/example.vim | 9 +++++ .../resistor-color-duo/.meta/tests.toml | 31 ++++++++++++++++ .../resistor_color_duo.vader | 35 +++++++++++++++++++ .../resistor-color-duo/resistor_color_duo.vim | 20 +++++++++++ 7 files changed, 155 insertions(+) create mode 100644 exercises/practice/resistor-color-duo/.docs/instructions.md create mode 100644 exercises/practice/resistor-color-duo/.meta/config.json create mode 100644 exercises/practice/resistor-color-duo/.meta/example.vim create mode 100644 exercises/practice/resistor-color-duo/.meta/tests.toml create mode 100644 exercises/practice/resistor-color-duo/resistor_color_duo.vader create mode 100644 exercises/practice/resistor-color-duo/resistor_color_duo.vim diff --git a/config.json b/config.json index ce05b90..04a044a 100644 --- a/config.json +++ b/config.json @@ -250,6 +250,14 @@ "transforming" ] }, + { + "slug": "resistor-color-duo", + "name": "Resistor Color Duo", + "uuid": "8f00c858-c288-4dad-a7a8-a6592ce3dd15", + "practices": [], + "prerequisites": [], + "difficulty": 3 + }, { "slug": "triangle", "name": "Triangle", diff --git a/exercises/practice/resistor-color-duo/.docs/instructions.md b/exercises/practice/resistor-color-duo/.docs/instructions.md new file mode 100644 index 0000000..bdcd549 --- /dev/null +++ b/exercises/practice/resistor-color-duo/.docs/instructions.md @@ -0,0 +1,33 @@ +# 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. +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 color names as input and output a two digit number, even if the input is more than two colors! + +The band 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 + +From the example above: +brown-green should return 15 +brown-green-violet should return 15 too, ignoring the third color. diff --git a/exercises/practice/resistor-color-duo/.meta/config.json b/exercises/practice/resistor-color-duo/.meta/config.json new file mode 100644 index 0000000..a806c09 --- /dev/null +++ b/exercises/practice/resistor-color-duo/.meta/config.json @@ -0,0 +1,19 @@ +{ + "authors": [ + "BNAndras" + ], + "files": { + "solution": [ + "resistor_color.vim" + ], + "test": [ + "resistor_color.vader" + ], + "example": [ + ".meta/example.vim" + ] + }, + "blurb": "Convert color codes, as used on resistors, to a numeric value.", + "source": "Maud de Vries, Erik Schierboom", + "source_url": "https://github.com/exercism/problem-specifications/issues/1464" +} diff --git a/exercises/practice/resistor-color-duo/.meta/example.vim b/exercises/practice/resistor-color-duo/.meta/example.vim new file mode 100644 index 0000000..db32cc3 --- /dev/null +++ b/exercises/practice/resistor-color-duo/.meta/example.vim @@ -0,0 +1,9 @@ +let s:COLORS = ['black', 'brown', 'red', 'orange', 'yellow', 'green', 'blue', 'violet', 'grey', 'white'] + +function! Value(colors) abort + let [color1, color2; rest] = a:colors + let tens = index(s:COLORS, color1) + let ones = index(s:COLORS, color2) + + return tens * 10 + ones +endfunction diff --git a/exercises/practice/resistor-color-duo/.meta/tests.toml b/exercises/practice/resistor-color-duo/.meta/tests.toml new file mode 100644 index 0000000..9036fc7 --- /dev/null +++ b/exercises/practice/resistor-color-duo/.meta/tests.toml @@ -0,0 +1,31 @@ +# 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. + +[ce11995a-5b93-4950-a5e9-93423693b2fc] +description = "Brown and black" + +[7bf82f7a-af23-48ba-a97d-38d59406a920] +description = "Blue and grey" + +[f1886361-fdfd-4693-acf8-46726fe24e0c] +description = "Yellow and violet" + +[b7a6cbd2-ae3c-470a-93eb-56670b305640] +description = "White and red" + +[77a8293d-2a83-4016-b1af-991acc12b9fe] +description = "Orange and orange" + +[0c4fb44f-db7c-4d03-afa8-054350f156a8] +description = "Ignore additional colors" + +[4a8ceec5-0ab4-4904-88a4-daf953a5e818] +description = "Black and brown, one-digit" diff --git a/exercises/practice/resistor-color-duo/resistor_color_duo.vader b/exercises/practice/resistor-color-duo/resistor_color_duo.vader new file mode 100644 index 0000000..0848516 --- /dev/null +++ b/exercises/practice/resistor-color-duo/resistor_color_duo.vader @@ -0,0 +1,35 @@ + +Execute (Brown and black): + let g:colors = ['brown', 'black'] + let g:expected = 10 + AssertEqual g:expected, Value(g:colors) + +Execute (Blue and grey): + let g:colors = ['blue', 'grey'] + let g:expected = 68 + AssertEqual g:expected, Value(g:colors) + +Execute (Yellow and violet): + let g:colors = ['yellow', 'violet'] + let g:expected = 47 + AssertEqual g:expected, Value(g:colors) + +Execute (White and red): + let g:colors = ['white', 'red'] + let g:expected = 92 + AssertEqual g:expected, Value(g:colors) + +Execute (Orange and orange): + let g:colors = ['orange', 'orange'] + let g:expected = 33 + AssertEqual g:expected, Value(g:colors) + +Execute (Ignore additional colors): + let g:colors = ['green', 'brown', 'orange'] + let g:expected = 51 + AssertEqual g:expected, Value(g:colors) + +Execute (Black and brown, one-digit): + let g:colors = ['black', 'brown'] + let g:expected = 1 + AssertEqual g:expected, Value(g:colors) diff --git a/exercises/practice/resistor-color-duo/resistor_color_duo.vim b/exercises/practice/resistor-color-duo/resistor_color_duo.vim new file mode 100644 index 0000000..87cab8c --- /dev/null +++ b/exercises/practice/resistor-color-duo/resistor_color_duo.vim @@ -0,0 +1,20 @@ +" +" Returns the resistance value represented by the first two color strings in the passed list +" +" Example: +" +" :echo Value(['black', 'brown']) +" 1 +" +" :echo Value(['brown', 'black']) +" 10 +" +" :echo Value(['green', 'brown']) +" 51 +" +" :echo Value(['green', 'brown', 'orange']) +" 51 +" +function! Value(colors) abort + " your code goes here +endfunction From 15de0a01f792028ad9ef14e83edbbfe36125f041 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20B=20Nagy?= <20251272+BNAndras@users.noreply.github.com> Date: Sun, 8 Oct 2023 19:29:12 -0700 Subject: [PATCH 2/2] Update exercises/practice/resistor-color-duo/.meta/config.json Co-authored-by: Victor Goff --- exercises/practice/resistor-color-duo/.meta/config.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/exercises/practice/resistor-color-duo/.meta/config.json b/exercises/practice/resistor-color-duo/.meta/config.json index a806c09..8cb6554 100644 --- a/exercises/practice/resistor-color-duo/.meta/config.json +++ b/exercises/practice/resistor-color-duo/.meta/config.json @@ -4,10 +4,10 @@ ], "files": { "solution": [ - "resistor_color.vim" + "resistor_color_duo.vim" ], "test": [ - "resistor_color.vader" + "resistor_color_duo.vader" ], "example": [ ".meta/example.vim"