trackler 2.2.1.80 → 2.2.1.81
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/trackler/version.rb +1 -1
- data/problem-specifications/exercises/bob/canonical-data.json +76 -26
- data/problem-specifications/exercises/isbn-verifier/canonical-data.json +9 -1
- data/problem-specifications/exercises/luhn/canonical-data.json +40 -14
- data/tracks/bash/CONTRIBUTING.md +3 -3
- data/tracks/bash/exercises/error-handling/README.md +15 -0
- data/tracks/bash/exercises/hello-world/{HINTS.md → .meta/hints.md} +1 -1
- data/tracks/csharp/config.json +24 -0
- data/tracks/csharp/exercises/binary/Binary.cs +9 -0
- data/tracks/csharp/exercises/binary/Binary.csproj +17 -0
- data/tracks/csharp/exercises/binary/BinaryTest.cs +94 -0
- data/tracks/csharp/exercises/binary/Example.cs +24 -0
- data/tracks/csharp/exercises/binary/README.md +41 -0
- data/tracks/csharp/exercises/hexadecimal/Example.cs +41 -0
- data/tracks/csharp/exercises/hexadecimal/Hexadecimal.cs +9 -0
- data/tracks/csharp/exercises/hexadecimal/Hexadecimal.csproj +17 -0
- data/tracks/csharp/exercises/hexadecimal/HexadecimalTest.cs +65 -0
- data/tracks/csharp/exercises/hexadecimal/README.md +20 -0
- data/tracks/csharp/exercises/octal/Example.cs +24 -0
- data/tracks/csharp/exercises/octal/Octal.cs +9 -0
- data/tracks/csharp/exercises/octal/Octal.csproj +17 -0
- data/tracks/csharp/exercises/octal/OctalTest.cs +88 -0
- data/tracks/csharp/exercises/octal/README.md +55 -0
- data/tracks/csharp/exercises/trinary/Example.cs +24 -0
- data/tracks/csharp/exercises/trinary/README.md +34 -0
- data/tracks/csharp/exercises/trinary/Trinary.cs +9 -0
- data/tracks/csharp/exercises/trinary/Trinary.csproj +17 -0
- data/tracks/csharp/exercises/trinary/TrinaryTest.cs +70 -0
- data/tracks/delphi/exercises/isbn-verifier/uTestISBNVerifier.pas +12 -0
- data/tracks/fsharp/config.json +21 -1
- data/tracks/fsharp/exercises/binary/Binary.fs +3 -0
- data/tracks/fsharp/exercises/binary/Binary.fsproj +23 -0
- data/tracks/fsharp/exercises/binary/BinaryTest.fs +67 -0
- data/tracks/fsharp/exercises/binary/Example.fs +13 -0
- data/tracks/fsharp/exercises/binary/Program.fs +1 -0
- data/tracks/fsharp/exercises/binary/README.md +35 -0
- data/tracks/fsharp/exercises/hexadecimal/Example.fs +14 -0
- data/tracks/fsharp/exercises/hexadecimal/Hexadecimal.fs +3 -0
- data/tracks/fsharp/exercises/hexadecimal/Hexadecimal.fsproj +23 -0
- data/tracks/fsharp/exercises/hexadecimal/HexadecimalTest.fs +47 -0
- data/tracks/fsharp/exercises/hexadecimal/Program.fs +1 -0
- data/tracks/fsharp/exercises/hexadecimal/README.md +14 -0
- data/tracks/fsharp/exercises/octal/Example.fs +10 -0
- data/tracks/fsharp/exercises/octal/Octal.fs +3 -0
- data/tracks/fsharp/exercises/octal/Octal.fsproj +23 -0
- data/tracks/fsharp/exercises/octal/OctalTest.fs +59 -0
- data/tracks/fsharp/exercises/octal/Program.fs +1 -0
- data/tracks/fsharp/exercises/octal/README.md +49 -0
- data/tracks/fsharp/exercises/transpose/TrinaryTest.fs +24 -0
- data/tracks/fsharp/exercises/trinary/Example.fs +13 -0
- data/tracks/fsharp/exercises/trinary/Program.fs +1 -0
- data/tracks/fsharp/exercises/trinary/README.md +28 -0
- data/tracks/fsharp/exercises/trinary/Trinary.fs +3 -0
- data/tracks/fsharp/exercises/trinary/Trinary.fsproj +23 -0
- data/tracks/fsharp/exercises/trinary/TrinaryTest.fs +51 -0
- data/tracks/lua/config.json +6 -1
- data/tracks/lua/exercises/accumulate/accumulate_spec.lua +27 -0
- data/tracks/lua/exercises/accumulate/example.lua +7 -0
- data/tracks/python/config.json +10 -0
- data/tracks/python/exercises/reverse-string/README.md +9 -0
- data/tracks/python/exercises/reverse-string/example.py +2 -0
- data/tracks/python/exercises/reverse-string/reverse_string.py +2 -0
- data/tracks/python/exercises/reverse-string/reverse_string_test.py +26 -0
- metadata +55 -3
@@ -0,0 +1,55 @@
|
|
1
|
+
# Octal
|
2
|
+
|
3
|
+
Convert an octal number, represented as a string (e.g. '1735263'), to its
|
4
|
+
decimal equivalent using first principles (i.e. no, you may not use built-in or
|
5
|
+
external libraries to accomplish the conversion).
|
6
|
+
|
7
|
+
Implement octal to decimal conversion. Given an octal input
|
8
|
+
string, your program should produce a decimal output.
|
9
|
+
|
10
|
+
## Note
|
11
|
+
- Implement the conversion yourself.
|
12
|
+
Do not use something else to perform the conversion for you.
|
13
|
+
- Treat invalid input as octal 0.
|
14
|
+
|
15
|
+
## About Octal (Base-8)
|
16
|
+
Decimal is a base-10 system.
|
17
|
+
|
18
|
+
A number 233 in base 10 notation can be understood
|
19
|
+
as a linear combination of powers of 10:
|
20
|
+
|
21
|
+
- The rightmost digit gets multiplied by 10^0 = 1
|
22
|
+
- The next number gets multiplied by 10^1 = 10
|
23
|
+
- ...
|
24
|
+
- The *n*th number gets multiplied by 10^*(n-1)*.
|
25
|
+
- All these values are summed.
|
26
|
+
|
27
|
+
So:
|
28
|
+
```
|
29
|
+
233 # decimal
|
30
|
+
= 2*10^2 + 3*10^1 + 3*10^0
|
31
|
+
= 2*100 + 3*10 + 3*1
|
32
|
+
```
|
33
|
+
|
34
|
+
Octal is similar, but uses powers of 8 rather than powers of 10.
|
35
|
+
|
36
|
+
So:
|
37
|
+
```
|
38
|
+
233 # octal
|
39
|
+
= 2*8^2 + 3*8^1 + 3*8^0
|
40
|
+
= 2*64 + 3*8 + 3*1
|
41
|
+
= 128 + 24 + 3
|
42
|
+
= 155
|
43
|
+
```
|
44
|
+
|
45
|
+
### Submitting Exercises
|
46
|
+
|
47
|
+
Note that, when trying to submit an exercise, make sure the exercise file that you're submitting is in the `exercism/csharp/<exerciseName>` directory.
|
48
|
+
|
49
|
+
For example, if you're submitting `bob.cs` for the Bob exercise, the submit command would be something like `exercism submit <path_to_exercism_dir>/csharp/bob/bob.cs`.
|
50
|
+
## Source
|
51
|
+
|
52
|
+
All of Computer Science [http://www.wolframalpha.com/input/?i=base+8](http://www.wolframalpha.com/input/?i=base+8)
|
53
|
+
|
54
|
+
## Submitting Incomplete Solutions
|
55
|
+
It's possible to submit an incomplete solution so you can see how others have completed the exercise.
|
@@ -0,0 +1,24 @@
|
|
1
|
+
using System;
|
2
|
+
using System.Linq;
|
3
|
+
|
4
|
+
public class Trinary
|
5
|
+
{
|
6
|
+
public static int ToDecimal(string trinary)
|
7
|
+
{
|
8
|
+
if (IsNotValidTrinary(trinary)) return 0;
|
9
|
+
|
10
|
+
return trinary
|
11
|
+
.Select((c, i) => int.Parse(c.ToString()) * ThreeToThePowerOf(trinary.Length - i - 1))
|
12
|
+
.Sum();
|
13
|
+
}
|
14
|
+
|
15
|
+
private static bool IsNotValidTrinary(string trinary)
|
16
|
+
{
|
17
|
+
return !trinary.All(x => char.IsDigit(x) && int.Parse(x.ToString()) < 3);
|
18
|
+
}
|
19
|
+
|
20
|
+
private static int ThreeToThePowerOf(int power)
|
21
|
+
{
|
22
|
+
return (int)Math.Pow(3, power);
|
23
|
+
}
|
24
|
+
}
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# Trinary
|
2
|
+
|
3
|
+
Convert a trinary number, represented as a string (e.g. '102012'), to its
|
4
|
+
decimal equivalent using first principles.
|
5
|
+
|
6
|
+
The program should consider strings specifying an invalid trinary as the
|
7
|
+
value 0.
|
8
|
+
|
9
|
+
Trinary numbers contain three symbols: 0, 1, and 2.
|
10
|
+
|
11
|
+
The last place in a trinary number is the 1's place. The second to last
|
12
|
+
is the 3's place, the third to last is the 9's place, etc.
|
13
|
+
|
14
|
+
```bash
|
15
|
+
# "102012"
|
16
|
+
1 0 2 0 1 2 # the number
|
17
|
+
1*3^5 + 0*3^4 + 2*3^3 + 0*3^2 + 1*3^1 + 2*3^0 # the value
|
18
|
+
243 + 0 + 54 + 0 + 3 + 2 = 302
|
19
|
+
```
|
20
|
+
|
21
|
+
If your language provides a method in the standard library to perform the
|
22
|
+
conversion, pretend it doesn't exist and implement it yourself.
|
23
|
+
|
24
|
+
### Submitting Exercises
|
25
|
+
|
26
|
+
Note that, when trying to submit an exercise, make sure the exercise file that you're submitting is in the `exercism/csharp/<exerciseName>` directory.
|
27
|
+
|
28
|
+
For example, if you're submitting `bob.cs` for the Bob exercise, the submit command would be something like `exercism submit <path_to_exercism_dir>/csharp/bob/bob.cs`.
|
29
|
+
## Source
|
30
|
+
|
31
|
+
All of Computer Science [http://www.wolframalpha.com/input/?i=binary&a=*C.binary-_*MathWorld-](http://www.wolframalpha.com/input/?i=binary&a=*C.binary-_*MathWorld-)
|
32
|
+
|
33
|
+
## Submitting Incomplete Solutions
|
34
|
+
It's possible to submit an incomplete solution so you can see how others have completed the exercise.
|
@@ -0,0 +1,17 @@
|
|
1
|
+
<Project Sdk="Microsoft.NET.Sdk">
|
2
|
+
|
3
|
+
<PropertyGroup>
|
4
|
+
<TargetFramework>netcoreapp2.0</TargetFramework>
|
5
|
+
</PropertyGroup>
|
6
|
+
|
7
|
+
<ItemGroup>
|
8
|
+
<Compile Remove="Example.cs" />
|
9
|
+
</ItemGroup>
|
10
|
+
|
11
|
+
<ItemGroup>
|
12
|
+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
|
13
|
+
<PackageReference Include="xunit" Version="2.3.1" />
|
14
|
+
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
|
15
|
+
</ItemGroup>
|
16
|
+
|
17
|
+
</Project>
|
@@ -0,0 +1,70 @@
|
|
1
|
+
using Xunit;
|
2
|
+
|
3
|
+
public class TrinaryTest
|
4
|
+
{
|
5
|
+
[Fact]
|
6
|
+
public void Trinary_1_is_decimal_1()
|
7
|
+
{
|
8
|
+
Assert.Equal(1, Trinary.ToDecimal("1"));
|
9
|
+
}
|
10
|
+
|
11
|
+
[Fact(Skip = "Remove to run test")]
|
12
|
+
public void Trinary_2_is_decimal_2()
|
13
|
+
{
|
14
|
+
Assert.Equal(2, Trinary.ToDecimal("2"));
|
15
|
+
}
|
16
|
+
|
17
|
+
[Fact(Skip = "Remove to run test")]
|
18
|
+
public void Trinary_10_is_decimal_3()
|
19
|
+
{
|
20
|
+
Assert.Equal(3, Trinary.ToDecimal("10"));
|
21
|
+
}
|
22
|
+
|
23
|
+
[Fact(Skip = "Remove to run test")]
|
24
|
+
public void Trinary_11_is_decimal_4()
|
25
|
+
{
|
26
|
+
Assert.Equal(4, Trinary.ToDecimal("11"));
|
27
|
+
}
|
28
|
+
|
29
|
+
[Fact(Skip = "Remove to run test")]
|
30
|
+
public void Trinary_100_is_decimal_9()
|
31
|
+
{
|
32
|
+
Assert.Equal(9, Trinary.ToDecimal("100"));
|
33
|
+
}
|
34
|
+
|
35
|
+
[Fact(Skip = "Remove to run test")]
|
36
|
+
public void Trinary_112_is_decimal_14()
|
37
|
+
{
|
38
|
+
Assert.Equal(14, Trinary.ToDecimal("112"));
|
39
|
+
}
|
40
|
+
|
41
|
+
[Fact(Skip = "Remove to run test")]
|
42
|
+
public void Trinary_222_is_decimal_26()
|
43
|
+
{
|
44
|
+
Assert.Equal(26, Trinary.ToDecimal("222"));
|
45
|
+
}
|
46
|
+
|
47
|
+
[Fact(Skip = "Remove to run test")]
|
48
|
+
public void Trinary_1122000120_is_decimal_32091()
|
49
|
+
{
|
50
|
+
Assert.Equal(32091, Trinary.ToDecimal("1122000120"));
|
51
|
+
}
|
52
|
+
|
53
|
+
[Fact(Skip = "Remove to run test")]
|
54
|
+
public void Invalid_trinary_digits_returns_0()
|
55
|
+
{
|
56
|
+
Assert.Equal(0, Trinary.ToDecimal("1234"));
|
57
|
+
}
|
58
|
+
|
59
|
+
[Fact(Skip = "Remove to run test")]
|
60
|
+
public void Invalid_word_as_input_returns_0()
|
61
|
+
{
|
62
|
+
Assert.Equal(0, Trinary.ToDecimal("carrot"));
|
63
|
+
}
|
64
|
+
|
65
|
+
[Fact(Skip = "Remove to run test")]
|
66
|
+
public void Invalid_numbers_with_letters_as_input_returns_0()
|
67
|
+
{
|
68
|
+
Assert.Equal(0, Trinary.ToDecimal("0a1b2c"));
|
69
|
+
}
|
70
|
+
}
|
@@ -4,6 +4,9 @@ interface
|
|
4
4
|
uses
|
5
5
|
DUnitX.TestFramework;
|
6
6
|
|
7
|
+
const
|
8
|
+
CanonicalVersion = '2.2.0';
|
9
|
+
|
7
10
|
type
|
8
11
|
[TestFixture]
|
9
12
|
ISBNVerifierTest = class(TObject)
|
@@ -59,6 +62,10 @@ type
|
|
59
62
|
[Test]
|
60
63
|
[Ignore]
|
61
64
|
procedure check_digit_of_X_should_not_be_used_for_0;
|
65
|
+
|
66
|
+
[Test]
|
67
|
+
[Ignore]
|
68
|
+
procedure empty_ISBN;
|
62
69
|
end;
|
63
70
|
|
64
71
|
implementation
|
@@ -76,6 +83,11 @@ begin
|
|
76
83
|
Assert.IsFalse(TIsbn.isValid('3-598-21515-X'));
|
77
84
|
end;
|
78
85
|
|
86
|
+
procedure ISBNVerifierTest.empty_ISBN;
|
87
|
+
begin
|
88
|
+
Assert.IsFalse(TIsbn.isValid(''))
|
89
|
+
end;
|
90
|
+
|
79
91
|
procedure ISBNVerifierTest.invalid_character_in_isbn;
|
80
92
|
begin
|
81
93
|
Assert.IsFalse(TIsbn.isValid('3-598-2K507-0'))
|
data/tracks/fsharp/config.json
CHANGED
@@ -1234,6 +1234,26 @@
|
|
1234
1234
|
],
|
1235
1235
|
"unlocked_by": "two-fer",
|
1236
1236
|
"uuid": "a6082751-98ca-45dc-aeed-cdd19a8da0ca"
|
1237
|
+
},
|
1238
|
+
{
|
1239
|
+
"uuid": "df8f4106-c1ce-4c33-86b2-ad61ba5ccc4a",
|
1240
|
+
"slug": "binary",
|
1241
|
+
"deprecated": true
|
1242
|
+
},
|
1243
|
+
{
|
1244
|
+
"uuid": "81904afe-a893-45be-99f8-2e074a6f1ad5",
|
1245
|
+
"slug": "trinary",
|
1246
|
+
"deprecated": true
|
1247
|
+
},
|
1248
|
+
{
|
1249
|
+
"uuid": "f29f9e56-c79b-4ae4-a0d0-29db78c677e4",
|
1250
|
+
"slug": "octal",
|
1251
|
+
"deprecated": true
|
1252
|
+
},
|
1253
|
+
{
|
1254
|
+
"uuid": "f4f80d57-a248-49d3-9329-587eb2643d4f",
|
1255
|
+
"slug": "hexadecimal",
|
1256
|
+
"deprecated": true
|
1237
1257
|
}
|
1238
1258
|
],
|
1239
1259
|
"foregone": [
|
@@ -1244,4 +1264,4 @@
|
|
1244
1264
|
"counter"
|
1245
1265
|
],
|
1246
1266
|
"language": "F#"
|
1247
|
-
}
|
1267
|
+
}
|
@@ -0,0 +1,23 @@
|
|
1
|
+
<Project Sdk="Microsoft.NET.Sdk">
|
2
|
+
|
3
|
+
<PropertyGroup>
|
4
|
+
<TargetFramework>netcoreapp2.0</TargetFramework>
|
5
|
+
|
6
|
+
<IsPackable>false</IsPackable>
|
7
|
+
</PropertyGroup>
|
8
|
+
|
9
|
+
<ItemGroup>
|
10
|
+
<Compile Include="Binary.fs" />
|
11
|
+
<Compile Include="BinaryTest.fs" />
|
12
|
+
<Compile Include="Program.fs" />
|
13
|
+
</ItemGroup>
|
14
|
+
|
15
|
+
<ItemGroup>
|
16
|
+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
|
17
|
+
<PackageReference Include="xunit" Version="2.3.1" />
|
18
|
+
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
|
19
|
+
<PackageReference Include="FsUnit.xUnit" Version="3.0.0" />
|
20
|
+
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
|
21
|
+
</ItemGroup>
|
22
|
+
|
23
|
+
</Project>
|
@@ -0,0 +1,67 @@
|
|
1
|
+
module BinaryTest
|
2
|
+
|
3
|
+
open FsUnit.Xunit
|
4
|
+
open Xunit
|
5
|
+
|
6
|
+
open Binary
|
7
|
+
|
8
|
+
[<Fact(Skip = "Remove to run test")>]
|
9
|
+
let ``Binary_0_is_decimal_0`` () =
|
10
|
+
toDecimal "0" |> should equal 0
|
11
|
+
|
12
|
+
[<Fact(Skip = "Remove to run test")>]
|
13
|
+
let ``Binary_1_is_decimal_1`` () =
|
14
|
+
toDecimal "1" |> should equal 1
|
15
|
+
|
16
|
+
[<Fact(Skip = "Remove to run test")>]
|
17
|
+
let ``Binary_10_is_decimal_2`` () =
|
18
|
+
toDecimal "10" |> should equal 2
|
19
|
+
|
20
|
+
[<Fact(Skip = "Remove to run test")>]
|
21
|
+
let ``Binary_11_is_decimal_3`` () =
|
22
|
+
toDecimal "11" |> should equal 3
|
23
|
+
|
24
|
+
[<Fact(Skip = "Remove to run test")>]
|
25
|
+
let ``Binary_100_is_decimal_4`` () =
|
26
|
+
toDecimal "100" |> should equal 4
|
27
|
+
|
28
|
+
[<Fact(Skip = "Remove to run test")>]
|
29
|
+
let ``Binary_1001_is_decimal_9`` () =
|
30
|
+
toDecimal "1001" |> should equal 9
|
31
|
+
|
32
|
+
[<Fact(Skip = "Remove to run test")>]
|
33
|
+
let ``Binary_11010_is_decimal_26`` () =
|
34
|
+
toDecimal "11010" |> should equal 26
|
35
|
+
|
36
|
+
[<Fact(Skip = "Remove to run test")>]
|
37
|
+
let ``Binary_10001101000_is_decimal_1128`` () =
|
38
|
+
toDecimal "10001101000" |> should equal 1128
|
39
|
+
|
40
|
+
[<Fact(Skip = "Remove to run test")>]
|
41
|
+
let ``Binary_ignores_leading_zeros`` () =
|
42
|
+
toDecimal "000011111" |> should equal 31
|
43
|
+
|
44
|
+
[<Fact(Skip = "Remove to run test")>]
|
45
|
+
let ``2_is_not_a_valid_binary_digit`` () =
|
46
|
+
toDecimal "2" |> should equal 0
|
47
|
+
|
48
|
+
[<Fact(Skip = "Remove to run test")>]
|
49
|
+
let ``A_number_containing_a_non_binary_digit_is_invalid`` () =
|
50
|
+
toDecimal "01201" |> should equal 0
|
51
|
+
|
52
|
+
[<Fact(Skip = "Remove to run test")>]
|
53
|
+
let ``A_number_with_trailing_non_binary_characters_is_invalid`` () =
|
54
|
+
toDecimal "10nope" |> should equal 0
|
55
|
+
|
56
|
+
[<Fact(Skip = "Remove to run test")>]
|
57
|
+
let ``A_number_with_leading_non_binary_characters_is_invalid`` () =
|
58
|
+
toDecimal "nope10" |> should equal 0
|
59
|
+
|
60
|
+
[<Fact(Skip = "Remove to run test")>]
|
61
|
+
let ``A_number_with_internal_non_binary_characters_is_invalid`` () =
|
62
|
+
toDecimal "10nope10" |> should equal 0
|
63
|
+
|
64
|
+
[<Fact(Skip = "Remove to run test")>]
|
65
|
+
let ``A_number_and_a_word_whitespace_separated_is_invalid`` () =
|
66
|
+
toDecimal "001 nope" |> should equal 0
|
67
|
+
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Binary
|
2
|
+
|
3
|
+
let isValid char =
|
4
|
+
match char with
|
5
|
+
| '0' | '1' -> true
|
6
|
+
| _ -> false
|
7
|
+
|
8
|
+
let charToDecimal char = (int)char - (int)'0'
|
9
|
+
|
10
|
+
let toDecimal(input: string) =
|
11
|
+
let chars = input.ToCharArray()
|
12
|
+
if Array.forall isValid chars then Array.fold (fun acc c -> acc * 2 + charToDecimal c) 0 chars
|
13
|
+
else 0
|
@@ -0,0 +1 @@
|
|
1
|
+
module Program = let [<EntryPoint>] main _ = 0
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# Binary
|
2
|
+
|
3
|
+
Convert a binary number, represented as a string (e.g. '101010'), to its decimal equivalent using first principles.
|
4
|
+
|
5
|
+
Implement binary to decimal conversion. Given a binary input
|
6
|
+
string, your program should produce a decimal output. The
|
7
|
+
program should handle invalid inputs.
|
8
|
+
|
9
|
+
## Note
|
10
|
+
- Implement the conversion yourself.
|
11
|
+
Do not use something else to perform the conversion for you.
|
12
|
+
|
13
|
+
## About Binary (Base-2)
|
14
|
+
Decimal is a base-10 system.
|
15
|
+
|
16
|
+
A number 23 in base 10 notation can be understood
|
17
|
+
as a linear combination of powers of 10:
|
18
|
+
|
19
|
+
- The rightmost digit gets multiplied by 10^0 = 1
|
20
|
+
- The next number gets multiplied by 10^1 = 10
|
21
|
+
- ...
|
22
|
+
- The *n*th number gets multiplied by 10^*(n-1)*.
|
23
|
+
- All these values are summed.
|
24
|
+
|
25
|
+
So: `23 => 2*10^1 + 3*10^0 => 2*10 + 3*1 = 23 base 10`
|
26
|
+
|
27
|
+
Binary is similar, but uses powers of 2 rather than powers of 10.
|
28
|
+
|
29
|
+
So: `101 => 1*2^2 + 0*2^1 + 1*2^0 => 1*4 + 0*2 + 1*1 => 4 + 1 => 5 base 10`.
|
30
|
+
## Source
|
31
|
+
|
32
|
+
All of Computer Science [http://www.wolframalpha.com/input/?i=binary&a=*C.binary-_*MathWorld-](http://www.wolframalpha.com/input/?i=binary&a=*C.binary-_*MathWorld-)
|
33
|
+
|
34
|
+
## Submitting Incomplete Solutions
|
35
|
+
It's possible to submit an incomplete solution so you can see how others have completed the exercise.
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Hexadecimal
|
2
|
+
|
3
|
+
open System
|
4
|
+
|
5
|
+
let private isValid char = "0123456789ABCDEF".Contains(string char)
|
6
|
+
|
7
|
+
let private charToDecimal (char: char) =
|
8
|
+
if Char.IsDigit(char) then (int)char - (int)'0'
|
9
|
+
else (int)(char) - (int)'A' + 10
|
10
|
+
|
11
|
+
let toDecimal(input: string) =
|
12
|
+
let chars = input.ToUpperInvariant().ToCharArray()
|
13
|
+
if Array.forall isValid chars then Array.fold (fun acc c -> acc * 16 + charToDecimal c) 0 chars
|
14
|
+
else 0
|