Skip to content

Commit 2acdffd

Browse files
committed
Implement exercise 'resistor-color-duo'
1 parent 3a67e0a commit 2acdffd

File tree

15 files changed

+410
-0
lines changed

15 files changed

+410
-0
lines changed

config.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,14 @@
7676
"prerequisites": [],
7777
"difficulty": 1
7878
},
79+
{
80+
"slug": "resistor-color-duo",
81+
"name": "Resistor Color Duo",
82+
"uuid": "8a49347f-461f-415c-b203-bb491ac98fac",
83+
"practices": [],
84+
"prerequisites": [],
85+
"difficulty": 1
86+
},
7987
{
8088
"slug": "reverse-string",
8189
"name": "Reverse String",

config.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,13 @@ exercises:
7878
prerequisites: []
7979
difficulty: 1
8080

81+
- slug: resistor-color-duo
82+
name: Resistor Color Duo
83+
uuid: 8a49347f-461f-415c-b203-bb491ac98fac
84+
practices: []
85+
prerequisites: []
86+
difficulty: 1
87+
8188
- slug: reverse-string
8289
name: Reverse String
8390
uuid: 89681570-5734-4f20-b68f-de8b176accdc
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
For example, if they printed a brown band (value 1) followed by a green band (value 5), it would translate to the number 15.
14+
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.
16+
The program will take color names as input and output a two digit number, even if the input is more than two colors!
17+
18+
The band colors are encoded as follows:
19+
20+
- black: 0
21+
- brown: 1
22+
- red: 2
23+
- orange: 3
24+
- yellow: 4
25+
- green: 5
26+
- blue: 6
27+
- violet: 7
28+
- grey: 8
29+
- white: 9
30+
31+
From the example above:
32+
brown-green should return 15, and
33+
brown-green-violet should return 15 too, ignoring the third color.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
YS_VERSION := 0.1.75
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
SHELL := bash
2+
3+
BASE := $(shell pwd)
4+
5+
export YS_VERSION := 0.1.76
6+
7+
YS_LOCAL_PREFIX := ../../../../.local/v$(YS_VERSION)
8+
9+
YS_LOCAL_BIN := $(YS_LOCAL_PREFIX)/bin
10+
11+
YS_BIN := $(YS_LOCAL_BIN)/ys-$(YS_VERSION)
12+
13+
TEST_FILE ?= $(wildcard *-test.ys)
14+
15+
16+
export PATH := $(YS_LOCAL_BIN):$(PATH)
17+
18+
export YSPATH := $(BASE)
19+
20+
21+
default:
22+
23+
test: $(YS_BIN)
24+
prove -v $(TEST_FILE)
25+
26+
$(YS_BIN):
27+
curl -s https://yamlscript.org/install | \
28+
BIN=1 VERSION=$(YS_VERSION) PREFIX=$(YS_LOCAL_PREFIX) bash >/dev/null
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"authors": [
3+
"ingydotnet"
4+
],
5+
"files": {
6+
"solution": [
7+
"resistor-color-duo.ys"
8+
],
9+
"test": [
10+
"resistor-color-duo-test.ys",
11+
"GNUmakefile",
12+
"Makefile",
13+
".yamlscript/exercise.mk",
14+
".yamlscript/exercism-ys-installer"
15+
],
16+
"example": [
17+
".meta/resistor-color-duo.ys"
18+
]
19+
},
20+
"blurb": "Convert color codes, as used on resistors, to a numeric value.",
21+
"source": "Maud de Vries, Erik Schierboom",
22+
"source_url": "https://github.com/exercism/problem-specifications/issues/1464"
23+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env ys-0
2+
3+
require ys::taptest: :all
4+
5+
use: resistor-color-duo
6+
7+
test::
8+
- name: Brown and black
9+
code: value(["brown" "black"])
10+
want: 10
11+
uuid: ce11995a-5b93-4950-a5e9-93423693b2fc
12+
13+
- name: Blue and grey
14+
code: value(["blue" "grey"])
15+
want: 68
16+
uuid: 7bf82f7a-af23-48ba-a97d-38d59406a920
17+
18+
- name: Yellow and violet
19+
code: value(["yellow" "violet"])
20+
want: 47
21+
uuid: f1886361-fdfd-4693-acf8-46726fe24e0c
22+
23+
- name: White and red
24+
code: value(["white" "red"])
25+
want: 92
26+
uuid: b7a6cbd2-ae3c-470a-93eb-56670b305640
27+
28+
- name: Orange and orange
29+
code: value(["orange" "orange"])
30+
want: 33
31+
uuid: 77a8293d-2a83-4016-b1af-991acc12b9fe
32+
33+
- name: Ignore additional colors
34+
code: value(["green" "brown" "orange"])
35+
want: 51
36+
uuid: 0c4fb44f-db7c-4d03-afa8-054350f156a8
37+
38+
- name: Black and brown, one-digit
39+
code: value(["black" "brown"])
40+
want: 1
41+
uuid: 4a8ceec5-0ab4-4904-88a4-daf953a5e818
42+
43+
done: 7
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
!yamlscript/v0
2+
3+
4+
colors =:
5+
zipmap _ range():
6+
qw(black brown red orange yellow
7+
green blue violet grey white)
8+
9+
defn value([c1 c2]):
10+
colors.$c1 * 10 +: colors.$c2
11+
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
[ce11995a-5b93-4950-a5e9-93423693b2fc]
13+
description = "Brown and black"
14+
15+
[7bf82f7a-af23-48ba-a97d-38d59406a920]
16+
description = "Blue and grey"
17+
18+
[f1886361-fdfd-4693-acf8-46726fe24e0c]
19+
description = "Yellow and violet"
20+
21+
[b7a6cbd2-ae3c-470a-93eb-56670b305640]
22+
description = "White and red"
23+
24+
[77a8293d-2a83-4016-b1af-991acc12b9fe]
25+
description = "Orange and orange"
26+
27+
[0c4fb44f-db7c-4d03-afa8-054350f156a8]
28+
description = "Ignore additional colors"
29+
30+
[4a8ceec5-0ab4-4904-88a4-daf953a5e818]
31+
description = "Black and brown, one-digit"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
YS_VERSION := 0.1.75

0 commit comments

Comments
 (0)