-
-
Notifications
You must be signed in to change notification settings - Fork 2
add resistor-color-duo
#8
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
Merged
TheRealOwenRees
merged 1 commit into
exercism:main
from
BNAndras:add-resistor-color-duo
Mar 10, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
exercises/practice/resistor-color-duo/.docs/instructions.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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, and | ||
| brown-green-violet should return 15 too, ignoring the third color. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| node_modules | ||
| */*.res.js |
49 changes: 49 additions & 0 deletions
49
exercises/practice/resistor-color-duo/.meta/ResistorColorDuo.res
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| type band = | ||
| | Black | ||
| | Brown | ||
| | Red | ||
| | Orange | ||
| | Yellow | ||
| | Green | ||
| | Blue | ||
| | Violet | ||
| | Grey | ||
| | White | ||
|
|
||
| let bandToValue = (c: band) => | ||
| switch c { | ||
| | Black => 0 | ||
| | Brown => 1 | ||
| | Red => 2 | ||
| | Orange => 3 | ||
| | Yellow => 4 | ||
| | Green => 5 | ||
| | Blue => 6 | ||
| | Violet => 7 | ||
| | Grey => 8 | ||
| | White => 9 | ||
| } | ||
|
|
||
| let stringToBand = (s: string) => | ||
| switch s { | ||
| | "black" => Black | ||
| | "brown" => Brown | ||
| | "red" => Red | ||
| | "orange" => Orange | ||
| | "yellow" => Yellow | ||
| | "green" => Green | ||
| | "blue" => Blue | ||
| | "violet" => Violet | ||
| | "grey" => Grey | ||
| | "white" => White | ||
| | _ => Black | ||
| } | ||
|
|
||
| let transform = (opt: option<string>) => | ||
| opt->Option.getOr("black")->stringToBand->bandToValue | ||
|
|
||
| let value = (colors: array<string>) => { | ||
| let tens = transform(colors[0]) | ||
| let ones = transform(colors[1]) | ||
| tens * 10 + ones | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| { | ||
| "authors": [ | ||
| "BNAndras" | ||
| ], | ||
| "files": { | ||
| "solution": [ | ||
| "src/ResistorColorDuo.res" | ||
| ], | ||
| "test": [ | ||
| "tests/ResistorColorDuo_test.res" | ||
| ], | ||
| "example": [ | ||
| ".meta/ResistorColorDuo.res" | ||
| ], | ||
| "editor": [ | ||
| "src/ResistorColorDuo.resi" | ||
| ] | ||
| }, | ||
| "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" | ||
| } |
17 changes: 17 additions & 0 deletions
17
exercises/practice/resistor-color-duo/.meta/testTemplate.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import path from 'node:path'; | ||
| import { fileURLToPath } from 'node:url'; | ||
| import { intEqual } from "../../../../test_generator/assertions.js"; | ||
| import { generateTests } from '../../../../test_generator/testGenerator.js'; | ||
|
|
||
| const __dirname = path.dirname(fileURLToPath(import.meta.url)); | ||
| const slug = path.basename(path.resolve(__dirname, '..')) | ||
|
|
||
| // EDIT THIS WITH YOUR ASSERTIONS | ||
| export const assertionFunctions = [ intEqual ] | ||
|
|
||
| // EDIT THIS WITH YOUR TEST TEMPLATES | ||
| export const template = (c) => { | ||
| return `intEqual(~message="${c.description}", value(${JSON.stringify(c.input.colors)}), ${c.expected})` | ||
| } | ||
|
|
||
| generateTests(__dirname, slug, assertionFunctions, template) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| MIT License | ||
|
|
||
| Copyright (c) 2026 Exercism | ||
|
|
||
| Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| of this software and associated documentation files (the "Software"), to deal | ||
| in the Software without restriction, including without limitation the rights | ||
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| copies of the Software, and to permit persons to whom the Software is | ||
| furnished to do so, subject to the following conditions: | ||
|
|
||
| The above copyright notice and this permission notice shall be included in all | ||
| copies or substantial portions of the Software. | ||
|
|
||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| SOFTWARE. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to ignore the JS files given they're just the transpiled ReScript code. It'd likely be confusing to have two copies of the test suite. This keeps it simple