-
-
Notifications
You must be signed in to change notification settings - Fork 102
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
725543b
commit f3ec023
Showing
11 changed files
with
193 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-duo/.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" | ||
] | ||
} | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
exercises/practice/resistor-color-duo/.docs/instructions.md
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,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 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 @@ | ||
module ResistorColorDuo | ||
|
||
let private colors = | ||
[ "black" | ||
"brown" | ||
"red" | ||
"orange" | ||
"yellow" | ||
"green" | ||
"blue" | ||
"violet" | ||
"grey" | ||
"white" ] | ||
|
||
let private colorCode color = List.findIndex ((=) color) colors | ||
|
||
let value colors = | ||
colorCode (List.item 0 colors) * 10 | ||
+ colorCode (List.item 1 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": [ | ||
"ResistorColorDuo.fs" | ||
], | ||
"test": [ | ||
"ResistorColorDuoTests.fs" | ||
], | ||
"example": [ | ||
".meta/Example.fs" | ||
] | ||
}, | ||
"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" | ||
} |
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 @@ | ||
# 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 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,4 @@ | ||
module ResistorColorDuo | ||
|
||
let value colors = | ||
failwith "Please implement the 'value' function" |
22 changes: 22 additions & 0 deletions
22
exercises/practice/resistor-color-duo/ResistorColorDuo.fsproj
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="ResistorColorDuo.fs" /> | ||
<Compile Include="ResistorColorDuoTests.fs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Exercism.Tests" Version="0.1.0-beta1" /> | ||
<PackageReference Include="FsUnit.xUnit" Version="4.0.4" /> | ||
<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> | ||
</ItemGroup> | ||
</Project> |
35 changes: 35 additions & 0 deletions
35
exercises/practice/resistor-color-duo/ResistorColorDuoTests.fs
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,35 @@ | ||
module ResistorColorDuoTests | ||
|
||
open FsUnit.Xunit | ||
open Xunit | ||
|
||
open ResistorColorDuo | ||
|
||
[<Fact>] | ||
let ``Brown and black`` () = | ||
value [ "brown"; "black" ] |> should equal 10 | ||
|
||
[<Fact(Skip = "Remove this Skip property to run this test")>] | ||
let ``Blue and grey`` () = | ||
value [ "blue"; "grey" ] |> should equal 68 | ||
|
||
[<Fact(Skip = "Remove this Skip property to run this test")>] | ||
let ``Yellow and violet`` () = | ||
value [ "yellow"; "violet" ] |> should equal 47 | ||
|
||
[<Fact(Skip = "Remove this Skip property to run this test")>] | ||
let ``White and red`` () = | ||
value [ "white"; "red" ] |> should equal 92 | ||
|
||
[<Fact(Skip = "Remove this Skip property to run this test")>] | ||
let ``Orange and orange`` () = | ||
value [ "orange"; "orange" ] |> should equal 33 | ||
|
||
[<Fact(Skip = "Remove this Skip property to run this test")>] | ||
let ``Ignore additional colors`` () = | ||
value [ "green"; "brown"; "orange" ] | ||
|> should equal 51 | ||
|
||
[<Fact(Skip = "Remove this Skip property to run this test")>] | ||
let ``Black and brown, one-digit`` () = | ||
value [ "black"; "brown" ] |> should equal 1 |
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