-
-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a7ea9ba
commit 725543b
Showing
11 changed files
with
184 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
12 changes: 12 additions & 0 deletions
12
exercises/practice/resistor-color/.config/dotnet-tools.json
This file contains 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,12 @@ | ||
{ | ||
"version": 1, | ||
"isRoot": true, | ||
"tools": { | ||
"fantomas-tool": { | ||
"version": "4.7.9", | ||
"commands": [ | ||
"fantomas" | ||
] | ||
} | ||
} | ||
} |
This file contains 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,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 |
This file contains 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,15 @@ | ||
module ResistorColor | ||
|
||
let colors = | ||
[ "black" | ||
"brown" | ||
"red" | ||
"orange" | ||
"yellow" | ||
"green" | ||
"blue" | ||
"violet" | ||
"grey" | ||
"white" ] | ||
|
||
let colorCode color = List.findIndex ((=) color) colors |
This file contains 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,19 @@ | ||
{ | ||
"authors": [ | ||
"erikschierboom" | ||
], | ||
"files": { | ||
"solution": [ | ||
"ResistorColor.fs" | ||
], | ||
"test": [ | ||
"ResistorColorTests.fs" | ||
], | ||
"example": [ | ||
".meta/Example.fs" | ||
] | ||
}, | ||
"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" | ||
} |
This file contains 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 @@ | ||
# 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. | ||
|
||
[49eb31c5-10a8-4180-9f7f-fea632ab87ef] | ||
description = "Color codes -> Black" | ||
|
||
[0a4df94b-92da-4579-a907-65040ce0b3fc] | ||
description = "Color codes -> White" | ||
|
||
[5f81608d-f36f-4190-8084-f45116b6f380] | ||
description = "Color codes -> Orange" | ||
|
||
[581d68fa-f968-4be2-9f9d-880f2fb73cf7] | ||
description = "Colors" |
This file contains 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,6 @@ | ||
module ResistorColor | ||
|
||
let colors: string list = failwith "You need to define the 'colors' binding." | ||
|
||
let colorCode (color: string) string = | ||
failwith "Please implement the 'colorCode' function" |
This file contains 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 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<IsPackable>false</IsPackable> | ||
<GenerateProgramFile>false</GenerateProgramFile> | ||
<IsTestProject>true</IsTestProject> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Compile Include="ResistorColor.fs" /> | ||
<Compile Include="ResistorColorTests.fs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Exercism.Tests" Version="0.1.0-beta1" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.3" /> | ||
<PackageReference Include="xunit" Version="2.4.1" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="FsUnit.xUnit" Version="4.0.4" /> | ||
</ItemGroup> | ||
</Project> |
This file contains 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 @@ | ||
module ResistorColorTests | ||
|
||
open FsUnit.Xunit | ||
open Xunit | ||
|
||
open ResistorColor | ||
|
||
[<Fact>] | ||
let ``Black`` () = colorCode "black" |> should equal 0 | ||
|
||
[<Fact(Skip = "Remove this Skip property to run this test")>] | ||
let ``White`` () = colorCode "white" |> should equal 9 | ||
|
||
[<Fact(Skip = "Remove this Skip property to run this test")>] | ||
let ``Orange`` () = colorCode "orange" |> should equal 3 | ||
|
||
[<Fact(Skip = "Remove this Skip property to run this test")>] | ||
let ``Colors`` () = | ||
colors | ||
|> should | ||
equal | ||
[ "black" | ||
"brown" | ||
"red" | ||
"orange" | ||
"yellow" | ||
"green" | ||
"blue" | ||
"violet" | ||
"grey" | ||
"white" ] |
This file contains 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