Skip to content

Commit f941181

Browse files
authored
Resistor color (#728)
Add exercise: Resistor Color
1 parent 6beb556 commit f941181

File tree

8 files changed

+814
-2
lines changed

8 files changed

+814
-2
lines changed

config.json

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,14 @@
221221
"input_validation"
222222
]
223223
},
224+
{
225+
"slug": "resistor-color",
226+
"name": "Resistor Color",
227+
"uuid": "93e9a833-d9d2-4d73-b559-2396b8f76446",
228+
"practices": [],
229+
"prerequisites": [],
230+
"difficulty": 2
231+
},
224232
{
225233
"slug": "resistor-color-duo",
226234
"name": "Resistor Color Duo",
@@ -809,11 +817,11 @@
809817
"practices": [],
810818
"prerequisites": [],
811819
"difficulty": 3,
820+
"status": "deprecated",
812821
"topics": [
813822
"control_flow_loops",
814823
"text_formatting"
815-
],
816-
"status": "deprecated"
824+
]
817825
},
818826
{
819827
"slug": "bottle-song",
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Instructions
2+
3+
If you want to build something using a Raspberry Pi, you'll probably use _resistors_.
4+
For this exercise, you need to know two things about them:
5+
6+
- Each resistor has a resistance value.
7+
- Resistors are small - so small in fact that if you printed the resistance value on them, it would be hard to read.
8+
9+
To get around this problem, manufacturers print color-coded bands onto the resistors to denote their resistance values.
10+
Each band has a position and a numeric value.
11+
12+
The first 2 bands of a resistor have a simple encoding scheme: each color maps to a single number.
13+
14+
In this exercise you are going to create a helpful program so that you don't have to remember the values of the bands.
15+
16+
These colors are encoded as follows:
17+
18+
- black: 0
19+
- brown: 1
20+
- red: 2
21+
- orange: 3
22+
- yellow: 4
23+
- green: 5
24+
- blue: 6
25+
- violet: 7
26+
- grey: 8
27+
- white: 9
28+
29+
The goal of this exercise is to create a way:
30+
31+
- to look up the numerical value associated with a particular color band
32+
- to list the different band colors
33+
34+
Mnemonics map the colors to the numbers, that, when stored as an array, happen to map to their index in the array:
35+
Better Be Right Or Your Great Big Values Go Wrong.
36+
37+
More information on the color encoding of resistors can be found in the [Electronic color code Wikipedia article][e-color-code].
38+
39+
[e-color-code]: https://en.wikipedia.org/wiki/Electronic_color_code
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"authors": [
3+
"glennj"
4+
],
5+
"files": {
6+
"solution": [
7+
"resistor_color.sh"
8+
],
9+
"test": [
10+
"resistor_color.bats"
11+
],
12+
"example": [
13+
".meta/example.sh"
14+
]
15+
},
16+
"blurb": "Convert a resistor band's color to its numeric representation.",
17+
"source": "Maud de Vries, Erik Schierboom",
18+
"source_url": "https://github.com/exercism/problem-specifications/issues/1458"
19+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env bash
2+
3+
readonly Colors=( black brown red orange yellow green blue violet grey white )
4+
5+
main () {
6+
case "$1" in
7+
colors)
8+
printf '%s\n' "${Colors[@]}"
9+
;;
10+
11+
code)
12+
for idx in "${!Colors[@]}"; do
13+
if [[ "${Colors[idx]}" == "$2" ]]; then
14+
echo "$idx"
15+
break
16+
fi
17+
done
18+
;;
19+
esac
20+
}
21+
22+
main "$@"
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# This is an auto-generated file.
2+
#
3+
# Regenerating this file via `configlet sync` will:
4+
# - Recreate every `description` key/value pair
5+
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications
6+
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion)
7+
# - Preserve any other key/value pair
8+
#
9+
# As user-added comments (using the # character) will be removed when this file
10+
# is regenerated, comments can be added via a `comment` key.
11+
12+
[49eb31c5-10a8-4180-9f7f-fea632ab87ef]
13+
description = "Color codes -> Black"
14+
15+
[0a4df94b-92da-4579-a907-65040ce0b3fc]
16+
description = "Color codes -> White"
17+
18+
[5f81608d-f36f-4190-8084-f45116b6f380]
19+
description = "Color codes -> Orange"
20+
21+
[581d68fa-f968-4be2-9f9d-880f2fb73cf7]
22+
description = "Colors"

0 commit comments

Comments
 (0)