-
-
Notifications
You must be signed in to change notification settings - Fork 563
Adding a fourth canonical exercise to the 'resistor color' series #2682
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
dc1738d
3b69921
96ef5a8
e20a463
d579af7
9685af6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,167 @@ | ||
| { | ||
| "exercise": "resistor-color-tolerance", | ||
| "cases": [ | ||
| { | ||
| "uuid": "fb677832-9a1b-4493-a5b0-786db5a8479c", | ||
| "description": "Orange, orange, black and red", | ||
| "property": "labelDecoder", | ||
| "input": { | ||
| "colors": ["orange", "orange", "black", "red"] | ||
| }, | ||
| "expected": { | ||
| "value": 33, | ||
| "unit": "ohms", | ||
| "tolerance": "±2%" | ||
| } | ||
| }, | ||
| { | ||
| "uuid": "8bdeb354-b8cf-47c1-96e4-84dceda90f8c", | ||
| "description": "Blue, gray, brown and violet", | ||
| "property": "labelDecoder", | ||
| "input": { | ||
| "colors": ["blue", "grey", "brown", "violet"] | ||
| }, | ||
| "expected": { | ||
| "value": 680, | ||
| "unit": "ohms", | ||
| "tolerance": "±0.1%" | ||
| } | ||
| }, | ||
| { | ||
| "uuid": "b4ef8864-09fc-443b-b4fb-82835c081637", | ||
| "description": "Red, black, red and green", | ||
| "property": "labelDecoder", | ||
| "input": { | ||
| "colors": ["red", "black", "red", "green"] | ||
| }, | ||
| "expected": { | ||
| "value": 2, | ||
| "unit": "kiloohms", | ||
| "tolerance": "±0.5%" | ||
| } | ||
| }, | ||
| { | ||
| "uuid": "c001757b-d388-4f42-9987-23e42bc22d68", | ||
| "description": "Green, brownm orange and grey", | ||
| "property": "labelDecoder", | ||
| "input": { | ||
| "colors": ["green", "brown", "orange", "grey"] | ||
| }, | ||
| "expected": { | ||
| "value": 51, | ||
| "unit": "kiloohms", | ||
| "tolerance": "±0.5%" | ||
| } | ||
| }, | ||
| { | ||
| "uuid": "1cb18e15-1fc5-4375-8a24-ca6eee130a27", | ||
| "description": "Only one band", | ||
| "comments": [ | ||
| "One band resistors only have the color black with a value of 0 and no tolerance." | ||
| ], | ||
| "property": "labelDecoder", | ||
| "input": { | ||
| "colors": ["black"] | ||
| }, | ||
| "expected": { | ||
| "value": 0, | ||
| "unit": "ohms" | ||
| } | ||
| }, | ||
| { | ||
| "uuid": "7e6841b9-0d11-43fb-85ad-be50e49b0656", | ||
| "description": "Orange, orange, yellow, black and brown", | ||
| "property": "labelDecoder", | ||
| "input": { | ||
| "colors": ["orange", "orange", "yellow", "black", "brown"] | ||
| }, | ||
| "expected": { | ||
| "value": 334, | ||
| "unit": "ohms", | ||
| "tolerance": "±1%" | ||
| } | ||
| }, | ||
| { | ||
| "uuid": "00019463-44d1-47f5-b59f-f3e7defc03d9", | ||
| "description": "Red, green, yellow, yellow and brown", | ||
| "property": "labelDecoder", | ||
| "input": { | ||
| "colors": ["red", "green", "yellow", "yellow", "brown"] | ||
| }, | ||
| "expected": { | ||
| "value": 2.54, | ||
| "unit": "megaohms", | ||
| "tolerance": "±1%" | ||
| } | ||
| }, | ||
| { | ||
| "uuid": "7998837e-fdfa-48c6-9191-0ab27c4777cc", | ||
| "description": "Blue, gray, white, brown and brown", | ||
| "scenarios": ["floating-point"], | ||
| "property": "labelDecoder", | ||
| "input": { | ||
| "colors": ["blue", "grey", "white", "brown", "brown"] | ||
| }, | ||
| "expected": { | ||
| "value": 6.89, | ||
| "unit": "kiloohms", | ||
| "tolerance": "±1%" | ||
| } | ||
| }, | ||
| { | ||
| "uuid": "51554e9f-c21d-4a73-a54c-1d9a973eaed0", | ||
| "description": "Violet, orange, red and gray", | ||
| "scenarios": ["floating-point"], | ||
| "property": "labelDecoder", | ||
| "input": { | ||
| "colors": ["violet", "orange", "red", "grey"] | ||
| }, | ||
| "expected": { | ||
| "value": 7.3, | ||
| "unit": "kiloohms", | ||
| "tolerance": "±0.05%" | ||
| } | ||
| }, | ||
| { | ||
| "uuid": "68aa7ba3-2334-411a-b3a4-7c47fe20fd99", | ||
| "description": "Brown, red, orange, green and blue", | ||
| "scenarios": ["floating-point"], | ||
| "property": "labelDecoder", | ||
| "input": { | ||
| "colors": ["brown", "red", "orange", "green", "blue"] | ||
| }, | ||
| "expected": { | ||
| "value": 12.3, | ||
| "unit": "megaohms", | ||
| "tolerance": "±0.25%" | ||
| } | ||
| }, | ||
| { | ||
| "uuid": "f6069edc-099b-429b-b2a9-bbe2537d2fae", | ||
| "description": "Brown, black, brown, yellow and violet", | ||
| "scenarios": ["floating-point"], | ||
| "property": "labelDecoder", | ||
| "input": { | ||
| "colors": ["brown", "black", "brown", "yellow", "violet"] | ||
| }, | ||
| "expected": { | ||
| "value": 1.01, | ||
| "unit": "megaohms", | ||
| "tolerance": "±0.1%" | ||
| } | ||
| }, | ||
| { | ||
| "uuid": "8fce56df-326e-45fe-9265-b69c334b9023", | ||
| "description": "Brown, black, red and red", | ||
| "property": "labelDecoder", | ||
| "input": { | ||
| "colors": ["brown", "black", "red", "red"] | ||
| }, | ||
| "expected": { | ||
| "value": 1, | ||
| "unit": "kiloohms", | ||
| "tolerance": "±2%" | ||
| } | ||
| } | ||
| ] | ||
| } | ||
|
IsaacG marked this conversation as resolved.
|
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,81 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||
| # Description | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| 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 output the correct value in ohms. | ||||||||||||||||||||||||||||||||||||||||||||||||
| The color bands are encoded as follows: | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| - black: 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we switch to a table for the colors (here and tolerance)? |
||||||||||||||||||||||||||||||||||||||||||||||||
| - brown: 1 | ||||||||||||||||||||||||||||||||||||||||||||||||
| - red: 2 | ||||||||||||||||||||||||||||||||||||||||||||||||
| - orange: 3 | ||||||||||||||||||||||||||||||||||||||||||||||||
| - yellow: 4 | ||||||||||||||||||||||||||||||||||||||||||||||||
| - green: 5 | ||||||||||||||||||||||||||||||||||||||||||||||||
| - blue: 6 | ||||||||||||||||||||||||||||||||||||||||||||||||
| - violet: 7 | ||||||||||||||||||||||||||||||||||||||||||||||||
| - grey: 8 | ||||||||||||||||||||||||||||||||||||||||||||||||
| - white: 9 | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+7
to
+16
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
For convenience, in case you want to use this. I did not leave it in a more "codey" flavor, since it is the information not the formatting that is important here (the dash and colon looks like adherence to some formal syntax for some languages data structures). |
||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| In [`Resistor Color Trio`][resistor-color-trio-exercise] you decoded the first three color bands. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 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% | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+26
to
+33
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or if you want to right-align the Tolerances:
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We probably need to include the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch. If anyone wants to amend, feel free, since I'm away from a computer for a while.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be able to click on "Apply suggestion" if it is looking OK now. |
||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| The four-band resistor is built up like this: | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| | Band_1 | Band_2 | Band_3 | Band_4 | | ||||||||||||||||||||||||||||||||||||||||||||||||
| | ------- | ------- | ---------- | --------- | | ||||||||||||||||||||||||||||||||||||||||||||||||
| | Value_1 | Value_2 | Multiplier | Tolerance | | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| Examples: | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| - orange-orange-brown-green would be `330` ohms with a `±0.5%` tolerance. | ||||||||||||||||||||||||||||||||||||||||||||||||
| - orange-orange-red-grey would be `3300` ohms with a `±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 | | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| Examples: | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| - orange-orange-orange-black-green would be `333` ohms with a `±0.5%` tolerance. | ||||||||||||||||||||||||||||||||||||||||||||||||
| - orange-red-orange-blue-violet would be `323 million` ohms with a `±0.1%` tolerance. | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| There are also one band resistors. | ||||||||||||||||||||||||||||||||||||||||||||||||
| One band resistors only have the color black with a value of 0. | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| Your program should translate an input `list` of resistor band colors into a label: | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| "... ohms ±...%" | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| So an input `list` of `["orange", "orange", "black", "green"]` should return: | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| "33 ohms ±0.5%" | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| When there are thousands of ohms, we say "kiloohms". | ||||||||||||||||||||||||||||||||||||||||||||||||
| That's similar to saying "kilometer" for 1000 meters, and "kilograms" for 1000 grams. | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| So an input `list` of `["orange", "orange", "orange", "grey"]` should return: | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| "33 kiloohms ±0.05%" | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| When there are millions of ohms, we say "megaohms". | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| So an input `list` of `["orange", "orange", "blue", "red"]` should return: | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| "33 megaohms ±2%" | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you mention the decimals used |
||||||||||||||||||||||||||||||||||||||||||||||||
| [resistor-color-trio-exercise]: https://exercism.org/tracks/python/exercises/resistor-color-trio | ||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,4 @@ | ||||||||||
| title = "Resistor Color Tolerance" | ||||||||||
| blurb = "Convert color codes as used on resistors with different bands to a human-readable label." | ||||||||||
| source = "Ported from the Python Track" | ||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since Meatball was the genesis of this exercise on the Python track, we should give him author credit here. (Sorry - I missed this the first time around)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you have a link to the original conversation then, or should it be just 'credit to Meatball'
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
or
Suggested change
+cc @meatball133 for input :)
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For |
||||||||||
| source_url = "https://github.com/exercism/python/tree/main/exercises/practice/resistor-color-expert" | ||||||||||
Uh oh!
There was an error while loading. Please reload this page.