Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,30 @@
"practices": [],
"prerequisites": [],
"difficulty": 1
},
{
"slug": "resistor-color-duo",
"name": "Resistor Color Duo",
"uuid": "e4c59681-3664-4ad4-8948-83b6084ad244",
"practices": [],
"prerequisites": [],
"difficulty": 1
},
{
"slug": "resistor-color",
"name": "Resistor Color",
"uuid": "366f8b1c-2368-4e96-9dff-21b552a3be14",
"practices": [],
"prerequisites": [],
"difficulty": 1
},
{
"slug": "resistor-color-trio",
"name": "Resistor Color Trio",
"uuid": "a1f5a88f-aa72-405f-88a3-e1a120ce3a89",
"practices": [],
"prerequisites": [],
"difficulty": 1
}
]
},
Expand Down
33 changes: 33 additions & 0 deletions exercises/practice/resistor-color-duo/.docs/instructions.md
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.
20 changes: 20 additions & 0 deletions exercises/practice/resistor-color-duo/.meta/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"authors": [
"quintuple-mallard"
],
"files": {
"solution": [
"resistor-color-duo.nu"
],
"test": [
"tests.nu"
],
"example": [
".meta/example.nu"
]
},
"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",
"difficulty": 2
}
10 changes: 10 additions & 0 deletions exercises/practice/resistor-color-duo/.meta/example.nu
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
def color_code [color] {
[black brown red orange yellow green blue violet grey white]
| enumerate
| filter {|item| $item.item == $color}
| get index
| get 0
}
export def value [colors] {
(color_code $colors.0) * 10 + (color_code $colors.1)
}
31 changes: 31 additions & 0 deletions exercises/practice/resistor-color-duo/.meta/tests.toml
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"
3 changes: 3 additions & 0 deletions exercises/practice/resistor-color-duo/resistor-color-duo.nu
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export def value [colors] {
error make {"msg": "Remove this line and implement value"}
}
8 changes: 8 additions & 0 deletions exercises/practice/resistor-color-duo/tests.nu
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use resistor-color-duo.nu value
use std/assert
assert equal (value [brown black]) 10
assert equal (value [blue grey]) 68
assert equal (value [yellow violet]) 47
assert equal (value [orange orange]) 33
assert equal (value [green brown orange]) 51
assert equal (value [black brown]) 1
56 changes: 56 additions & 0 deletions exercises/practice/resistor-color-trio/.docs/instructions.md
Original file line number Diff line number Diff line change
@@ -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
20 changes: 20 additions & 0 deletions exercises/practice/resistor-color-trio/.meta/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"authors": [
"quintuple-mallard"
],
"files": {
"solution": [
"resistor-color-trio.nu"
],
"test": [
"tests.nu"
],
"example": [
".meta/example.nu"
]
},
"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",
"difficulty": 4
}
26 changes: 26 additions & 0 deletions exercises/practice/resistor-color-trio/.meta/example.nu
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
def color_code [color] {
[black brown red orange yellow green blue violet grey white]
| enumerate
| filter {|item| $item.item == $color}
| get index
| get 0
}
def value [colors] {
(color_code $colors.0) * 10 + (color_code $colors.1)
}

def unit [] {
let ohms = $in
if $ohms < 1_000 {
$"($ohms) ohms"
} else if $ohms < 1_000_000 {
$"($ohms / 1_000) kiloohms"
} else if $ohms < 1_000_000_000 {
$"($ohms / 1_000_000) megaohms"
} else {
$"($ohms / 1_000_000_000) gigaohms"
}
}
export def label [colors] {
(value $colors) * 10 ** ((color_code $colors.2)) | unit
}
40 changes: 40 additions & 0 deletions exercises/practice/resistor-color-trio/.meta/tests.toml
Original file line number Diff line number Diff line change
@@ -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"
3 changes: 3 additions & 0 deletions exercises/practice/resistor-color-trio/resistor-color-trio.nu
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export def label [colors] {
error make {"msg": "Remove this line and implement label"}
}
12 changes: 12 additions & 0 deletions exercises/practice/resistor-color-trio/tests.nu
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use resistor-color-trio.nu label
use std/assert
assert equal (label [orange orange black]) "33 ohms"
assert equal (label [blue grey brown]) "680 ohms"
assert equal (label [red black red]) "2 kiloohms"
assert equal (label [green brown orange]) "51 kiloohms"
assert equal (label [yellow violet yellow]) "470 kiloohms"
assert equal (label [blue violet blue]) "67 megaohms"
assert equal (label [black black black]) "0 ohms"
assert equal (label [white white white]) "99 gigaohms"
assert equal (label [black grey black]) "8 ohms"
assert equal (label [blue green yellow orange]) "650 kiloohms"
39 changes: 39 additions & 0 deletions exercises/practice/resistor-color/.docs/instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# 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.

In this exercise you are going to create a helpful program so that you don't have to remember the values of the bands.

These 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

The goal of this exercise is to create a way:

- to look up the numerical value associated with a particular color band
- to list the different band colors

Mnemonics map the colors to the numbers, that, when stored as an array, happen to map to their index in the array:
Better Be Right Or Your Great Big Values Go Wrong.

More information on the color encoding of resistors can be found in the [Electronic color code Wikipedia article][e-color-code].

[e-color-code]: https://en.wikipedia.org/wiki/Electronic_color_code
20 changes: 20 additions & 0 deletions exercises/practice/resistor-color/.meta/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"authors": [
"quintuple-mallard"
],
"files": {
"solution": [
"resistor-color.nu"
],
"test": [
"tests.nu"
],
"example": [
".meta/example.nu"
]
},
"blurb": "Convert a resistor band's color to its numeric representation.",
"source": "Maud de Vries, Erik Schierboom",
"source_url": "https://github.com/exercism/problem-specifications/issues/1458",
"difficulty": 1
}
7 changes: 7 additions & 0 deletions exercises/practice/resistor-color/.meta/example.nu
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export def color_code [color] {
colors | enumerate | filter {|item| $item.item == $color} | get index | get 0
}

export def colors [] {
[black brown red orange yellow green blue violet grey white]
}
Loading