trackler 2.2.1.133 → 2.2.1.134
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/tracks/csharp/config.json +10 -0
- data/tracks/csharp/exercises/Exercises.sln +6 -0
- data/tracks/csharp/exercises/rational-numbers/Example.cs +167 -0
- data/tracks/csharp/exercises/rational-numbers/README.md +27 -0
- data/tracks/csharp/exercises/rational-numbers/RationalNumbers.cs +77 -0
- data/tracks/csharp/exercises/rational-numbers/RationalNumbers.csproj +17 -0
- data/tracks/csharp/exercises/rational-numbers/RationalNumbersTest.cs +222 -0
- data/tracks/csharp/exercises/rational-numbers/hints.md +5 -0
- data/tracks/csharp/generators/Exercises/RationalNumbers.cs +73 -0
- data/tracks/java/exercises/all-your-base/.meta/version +1 -1
- data/tracks/java/exercises/all-your-base/src/test/java/BaseConverterTest.java +1 -1
- data/tracks/java/exercises/roman-numerals/.meta/version +1 -1
- data/tracks/java/exercises/roman-numerals/src/test/java/RomanNumeralsTest.java +7 -0
- data/tracks/python/exercises/crypto-square/README.md +4 -5
- data/tracks/python/exercises/scale-generator/README.md +9 -16
- data/tracks/swift/config.json +1 -1
- metadata +9 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c199b6b186e79a6addc55c7b4c2ff2f43c3c39f6
|
4
|
+
data.tar.gz: c1c6657ba396dcb12f60736f1a09509e3c1eaf7c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d8be6e7f925daa5c522612b69e7023de0c4d1708655dc85dd31b8bc48e954f3fcdf7220db6a0b4ecdf1d413f44f719e629aa23f3e4f39179cb65a383504140d3
|
7
|
+
data.tar.gz: 49926783363b14e9328ebfa736c8f72cedf49e9aefccd98e81d5f71ffb80f728032884189caa0afa6675f267402c8642b4c98ba27d29af492efa75665c0654a3
|
data/lib/trackler/version.rb
CHANGED
data/tracks/csharp/config.json
CHANGED
@@ -135,6 +135,16 @@
|
|
135
135
|
"unlocked_by": "sum-of-multiples",
|
136
136
|
"uuid": "8150604d-4cdc-414a-a523-dd65ac536f0e"
|
137
137
|
},
|
138
|
+
{
|
139
|
+
"core": false,
|
140
|
+
"difficulty": 4,
|
141
|
+
"slug": "rational-numbers",
|
142
|
+
"topics": [
|
143
|
+
"mathematics"
|
144
|
+
],
|
145
|
+
"unlocked_by": "leap",
|
146
|
+
"uuid": "9ae7f7ed-75d8-4d03-967c-53846634ae07"
|
147
|
+
},
|
138
148
|
{
|
139
149
|
"core": true,
|
140
150
|
"difficulty": 3,
|
@@ -228,6 +228,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ArmstrongNumbers", "armstro
|
|
228
228
|
EndProject
|
229
229
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Yacht", "yacht\Yacht.csproj", "{C029D4C6-3A10-459E-96D7-3E77170A5A10}"
|
230
230
|
EndProject
|
231
|
+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RationalNumbers", "rational-numbers\RationalNumbers.csproj", "{0CBB430D-BF64-436F-93BE-8E8088DBCBFE}"
|
232
|
+
EndProject
|
231
233
|
Global
|
232
234
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
233
235
|
Debug|Any CPU = Debug|Any CPU
|
@@ -686,6 +688,10 @@ Global
|
|
686
688
|
{C029D4C6-3A10-459E-96D7-3E77170A5A10}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
687
689
|
{C029D4C6-3A10-459E-96D7-3E77170A5A10}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
688
690
|
{C029D4C6-3A10-459E-96D7-3E77170A5A10}.Release|Any CPU.Build.0 = Release|Any CPU
|
691
|
+
{0CBB430D-BF64-436F-93BE-8E8088DBCBFE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
692
|
+
{0CBB430D-BF64-436F-93BE-8E8088DBCBFE}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
693
|
+
{0CBB430D-BF64-436F-93BE-8E8088DBCBFE}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
694
|
+
{0CBB430D-BF64-436F-93BE-8E8088DBCBFE}.Release|Any CPU.Build.0 = Release|Any CPU
|
689
695
|
EndGlobalSection
|
690
696
|
GlobalSection(SolutionProperties) = preSolution
|
691
697
|
HideSolutionNode = FALSE
|
@@ -0,0 +1,167 @@
|
|
1
|
+
using System;
|
2
|
+
using System.Diagnostics;
|
3
|
+
|
4
|
+
public static class RealNumberExtension
|
5
|
+
{
|
6
|
+
// exponentiate real number to the rational number power
|
7
|
+
public static double Expreal(this int realNumber, RationalNumber r)
|
8
|
+
{
|
9
|
+
return r.Expreal(realNumber);
|
10
|
+
}
|
11
|
+
}
|
12
|
+
|
13
|
+
[DebuggerDisplay("{Numerator} / {Denominator}")]
|
14
|
+
public struct RationalNumber
|
15
|
+
{
|
16
|
+
public RationalNumber(int numerator, int denominator)
|
17
|
+
{
|
18
|
+
this.Numerator = numerator;
|
19
|
+
this.Denominator = denominator;
|
20
|
+
}
|
21
|
+
|
22
|
+
public int Numerator { get; }
|
23
|
+
public int Denominator { get; }
|
24
|
+
|
25
|
+
public RationalNumber Add(RationalNumber r)
|
26
|
+
{
|
27
|
+
return ReducedRationalNumber(this.Numerator * r.Denominator + this.Denominator * r.Numerator, this.Denominator * r.Denominator);
|
28
|
+
}
|
29
|
+
|
30
|
+
public static RationalNumber operator+ (RationalNumber r1, RationalNumber r2)
|
31
|
+
{
|
32
|
+
return r1.Add(r2);
|
33
|
+
}
|
34
|
+
|
35
|
+
public RationalNumber Sub(RationalNumber r)
|
36
|
+
{
|
37
|
+
return ReducedRationalNumber(this.Numerator * r.Denominator - this.Denominator * r.Numerator, this.Denominator * r.Denominator);
|
38
|
+
}
|
39
|
+
|
40
|
+
public static RationalNumber operator -(RationalNumber r1, RationalNumber r2)
|
41
|
+
{
|
42
|
+
return r1.Sub(r2);
|
43
|
+
}
|
44
|
+
|
45
|
+
public RationalNumber Mul(RationalNumber r)
|
46
|
+
{
|
47
|
+
if (this.Numerator == 0) return new RationalNumber(0, 1);
|
48
|
+
return ReducedRationalNumber(this.Numerator * r.Numerator, this.Denominator * r.Denominator);
|
49
|
+
}
|
50
|
+
|
51
|
+
public static RationalNumber operator *(RationalNumber r1, RationalNumber r2)
|
52
|
+
{
|
53
|
+
return r1.Mul(r2);
|
54
|
+
}
|
55
|
+
|
56
|
+
public RationalNumber Div(RationalNumber r)
|
57
|
+
{
|
58
|
+
return ReducedRationalNumber(this.Numerator * r.Denominator, this.Denominator * r.Numerator);
|
59
|
+
}
|
60
|
+
|
61
|
+
public static RationalNumber operator /(RationalNumber r1, RationalNumber r2)
|
62
|
+
{
|
63
|
+
return r1.Div(r2);
|
64
|
+
}
|
65
|
+
|
66
|
+
public RationalNumber Abs()
|
67
|
+
{
|
68
|
+
return new RationalNumber(Abs(this.Numerator), Abs(this.Denominator));
|
69
|
+
}
|
70
|
+
|
71
|
+
public RationalNumber Reduce()
|
72
|
+
{
|
73
|
+
if (this.Denominator == 0) return new RationalNumber(this.Numerator, this.Denominator);
|
74
|
+
else if (this.Numerator == 0) return new RationalNumber(0, 1);
|
75
|
+
|
76
|
+
var a = Abs(this.Numerator);
|
77
|
+
var b = Abs(this.Denominator);
|
78
|
+
|
79
|
+
var sign = Sign(this.Numerator) * Sign(this.Denominator);
|
80
|
+
|
81
|
+
return new RationalNumber(sign * a / GreatestCommonDenominator(a, b), b / GreatestCommonDenominator(a, b));
|
82
|
+
}
|
83
|
+
|
84
|
+
public RationalNumber Exprational(int power)
|
85
|
+
{
|
86
|
+
if (power == 0) return new RationalNumber(1, 1);
|
87
|
+
|
88
|
+
return ReducedRationalNumber
|
89
|
+
(
|
90
|
+
(Sign(this.Numerator) / Sign(this.Denominator)) *
|
91
|
+
Abs((int)Pow(this.Numerator, power)),
|
92
|
+
Abs((int)Pow(this.Denominator, power))
|
93
|
+
);
|
94
|
+
}
|
95
|
+
|
96
|
+
public double Expreal(int baseNumber)
|
97
|
+
{
|
98
|
+
if (this.Numerator == 0)
|
99
|
+
return 1;
|
100
|
+
else
|
101
|
+
return Pow(baseNumber);
|
102
|
+
}
|
103
|
+
|
104
|
+
private static RationalNumber ReducedRationalNumber(int numerator, int denominator)
|
105
|
+
{
|
106
|
+
return new RationalNumber(numerator, denominator).Reduce();
|
107
|
+
}
|
108
|
+
|
109
|
+
private double Pow(int baseNumber)
|
110
|
+
{
|
111
|
+
return NthRoot((Sign(this.Numerator) == Sign(this.Denominator) ?
|
112
|
+
Pow(baseNumber, Abs(this.Numerator)) :
|
113
|
+
1d / Pow(baseNumber, Abs(this.Numerator))),
|
114
|
+
Abs(this.Denominator));
|
115
|
+
}
|
116
|
+
|
117
|
+
private int Abs(int value)
|
118
|
+
{
|
119
|
+
return (value > 0) ? value : -value;
|
120
|
+
}
|
121
|
+
|
122
|
+
private double Abs(double value)
|
123
|
+
{
|
124
|
+
return (value > 0) ? value : -value;
|
125
|
+
}
|
126
|
+
|
127
|
+
private int Sign(int value)
|
128
|
+
{
|
129
|
+
return (value > 0) ? 1 : -1;
|
130
|
+
}
|
131
|
+
|
132
|
+
private int GreatestCommonDenominator(int a, int b)
|
133
|
+
{
|
134
|
+
var x = Abs(a);
|
135
|
+
var y = Abs(b);
|
136
|
+
|
137
|
+
while (x != 0 && y != 0)
|
138
|
+
if (x > y) x %= y; else y %= x;
|
139
|
+
return x == 0 ? y : x;
|
140
|
+
}
|
141
|
+
|
142
|
+
private double Pow(double baseValue, int exp)
|
143
|
+
{
|
144
|
+
double result = 1.0;
|
145
|
+
while (exp != 0)
|
146
|
+
{
|
147
|
+
if ((exp & 1) != 0) result *= baseValue;
|
148
|
+
baseValue *= baseValue;
|
149
|
+
exp >>= 1;
|
150
|
+
}
|
151
|
+
return result;
|
152
|
+
}
|
153
|
+
|
154
|
+
private double NthRoot(double baseValue, int n)
|
155
|
+
{
|
156
|
+
if (n == 1) return baseValue;
|
157
|
+
double deltaX;
|
158
|
+
double x = 0.1;
|
159
|
+
do
|
160
|
+
{
|
161
|
+
deltaX = ((double)baseValue / Pow(x, (n - 1)) - x) / n;
|
162
|
+
x = x + deltaX;
|
163
|
+
}
|
164
|
+
while (Abs(deltaX) > 0);
|
165
|
+
return x;
|
166
|
+
}
|
167
|
+
}
|
@@ -0,0 +1,27 @@
|
|
1
|
+
A rational number is defined as the quotient of two integers `a` and `b`, called the numerator and denominator, respectively, where `b != 0`.
|
2
|
+
|
3
|
+
The absolute value `|r|` of the rational number `r = a/b` is equal to `|a|/|b|`.
|
4
|
+
|
5
|
+
The sum of two rational numbers `r1 = a1/b1` and `r2 = a2/b2` is `r1 + r2 = a1/b1 + a2/b2 = (a1 * b2 + a2 * b1) / (b1 * b2)`.
|
6
|
+
|
7
|
+
The difference of two rational numbers `r1 = a1/b1` and `r2 = a2/b2` is `r1 - r2 = a1/b1 - a2/b2 = (a1 * b2 - a2 * b1) / (b1 * b2)`.
|
8
|
+
|
9
|
+
The product (multiplication) of two rational numbers `r1 = a1/b1` and `r2 = a2/b2` is `r1 * r2 = (a1 * a2) / (b1 * b2)`.
|
10
|
+
|
11
|
+
Dividing a rational number `r1 = a1/b1` by another `r2 = a2/b2` is `r1 / r2 = (a1 * b2) / (a2 * b1)` if `a2 * b1` is not zero.
|
12
|
+
|
13
|
+
Exponentiation of a rational number `r = a/b` to a non-negative integer power `n` is `r^n = (a^n)/(b^n)`.
|
14
|
+
|
15
|
+
Exponentiation of a rational number `r = a/b` to a negative integer power `n` is `r^n = (b^m)/(a^m)`, where `m = |n|`.
|
16
|
+
|
17
|
+
Exponentiation of a rational number `r = a/b` to a real (floating-point) number `x` is the quotient `(a^x)/(b^x)`, which is a real number.
|
18
|
+
|
19
|
+
Exponentiation of a real number `x` to a rational number `r = a/b` is `x^(a/b) = root(x^a, b)`, where `root(p, q)` is the `q`th root of `p`.
|
20
|
+
|
21
|
+
Implement the following operations:
|
22
|
+
- addition, subtraction, multiplication and division of two rational numbers,
|
23
|
+
- absolute value, exponentiation of a given rational number to an integer power, exponentiation of a given rational number to a real (floating-point) power, exponentiation of a real number to a rational number.
|
24
|
+
|
25
|
+
Your implementation of rational numbers should always be reduced to lowest terms. For example, `4/4` should reduce to `1/1`, `30/60` should reduce to `1/2`, `12/8` should reduce to `3/2`, etc. To reduce a rational number `r = a/b`, divide `a` and `b` by the greatest common divisor (gcd) of `a` and `b`. So, for example, `gcd(12, 8) = 4`, so `r = 12/8` can be reduced to `(12/4)/(8/4) = 3/2`.
|
26
|
+
|
27
|
+
Assume that the programming language you are using does not have an implementation of rational numbers.
|
@@ -0,0 +1,77 @@
|
|
1
|
+
using System;
|
2
|
+
using System.Diagnostics;
|
3
|
+
|
4
|
+
public static class RealNumberExtension
|
5
|
+
{
|
6
|
+
public static double Expreal(this int realNumber, RationalNumber r)
|
7
|
+
{
|
8
|
+
throw new NotImplementedException("You need to implement this extension method.");
|
9
|
+
}
|
10
|
+
}
|
11
|
+
|
12
|
+
public struct RationalNumber
|
13
|
+
{
|
14
|
+
public RationalNumber(int numerator, int denominator)
|
15
|
+
{
|
16
|
+
}
|
17
|
+
|
18
|
+
public RationalNumber Add(RationalNumber r)
|
19
|
+
{
|
20
|
+
throw new NotImplementedException("You need to implement this function.");
|
21
|
+
}
|
22
|
+
|
23
|
+
public static RationalNumber operator +(RationalNumber r1, RationalNumber r2)
|
24
|
+
{
|
25
|
+
throw new NotImplementedException("You need to implement this operator.");
|
26
|
+
}
|
27
|
+
|
28
|
+
public RationalNumber Sub(RationalNumber r)
|
29
|
+
{
|
30
|
+
throw new NotImplementedException("You need to implement this function.");
|
31
|
+
}
|
32
|
+
|
33
|
+
public static RationalNumber operator -(RationalNumber r1, RationalNumber r2)
|
34
|
+
{
|
35
|
+
throw new NotImplementedException("You need to implement this operator.");
|
36
|
+
}
|
37
|
+
|
38
|
+
public RationalNumber Mul(RationalNumber r)
|
39
|
+
{
|
40
|
+
throw new NotImplementedException("You need to implement this function.");
|
41
|
+
}
|
42
|
+
|
43
|
+
public static RationalNumber operator *(RationalNumber r1, RationalNumber r2)
|
44
|
+
{
|
45
|
+
throw new NotImplementedException("You need to implement this operator.");
|
46
|
+
}
|
47
|
+
|
48
|
+
public RationalNumber Div(RationalNumber r)
|
49
|
+
{
|
50
|
+
throw new NotImplementedException("You need to implement this function.");
|
51
|
+
}
|
52
|
+
|
53
|
+
public static RationalNumber operator /(RationalNumber r1, RationalNumber r2)
|
54
|
+
{
|
55
|
+
throw new NotImplementedException("You need to implement this operator.");
|
56
|
+
}
|
57
|
+
|
58
|
+
public RationalNumber Abs()
|
59
|
+
{
|
60
|
+
throw new NotImplementedException("You need to implement this function.");
|
61
|
+
}
|
62
|
+
|
63
|
+
public RationalNumber Reduce()
|
64
|
+
{
|
65
|
+
throw new NotImplementedException("You need to implement this function.");
|
66
|
+
}
|
67
|
+
|
68
|
+
public RationalNumber Exprational(int power)
|
69
|
+
{
|
70
|
+
throw new NotImplementedException("You need to implement this function.");
|
71
|
+
}
|
72
|
+
|
73
|
+
public double Expreal(int baseNumber)
|
74
|
+
{
|
75
|
+
throw new NotImplementedException("You need to implement this function.");
|
76
|
+
}
|
77
|
+
}
|
@@ -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,222 @@
|
|
1
|
+
// This file was auto-generated based on version 1.0.0 of the canonical data.
|
2
|
+
|
3
|
+
using Xunit;
|
4
|
+
|
5
|
+
public class RationalNumbersTest
|
6
|
+
{
|
7
|
+
[Fact]
|
8
|
+
public void Add_two_positive_rational_numbers()
|
9
|
+
{
|
10
|
+
Assert.Equal(new RationalNumber (7, 6), new RationalNumber(1, 2) + (new RationalNumber(2, 3)));
|
11
|
+
}
|
12
|
+
|
13
|
+
[Fact(Skip = "Remove to run test")]
|
14
|
+
public void Add_a_positive_rational_number_and_a_negative_rational_number()
|
15
|
+
{
|
16
|
+
Assert.Equal(new RationalNumber (-1, 6), new RationalNumber(1, 2) + (new RationalNumber(-2, 3)));
|
17
|
+
}
|
18
|
+
|
19
|
+
[Fact(Skip = "Remove to run test")]
|
20
|
+
public void Add_two_negative_rational_numbers()
|
21
|
+
{
|
22
|
+
Assert.Equal(new RationalNumber (-7, 6), new RationalNumber(-1, 2) + (new RationalNumber(-2, 3)));
|
23
|
+
}
|
24
|
+
|
25
|
+
[Fact(Skip = "Remove to run test")]
|
26
|
+
public void Add_a_rational_number_to_its_additive_inverse()
|
27
|
+
{
|
28
|
+
Assert.Equal(new RationalNumber (0, 1), new RationalNumber(1, 2) + (new RationalNumber(-1, 2)));
|
29
|
+
}
|
30
|
+
|
31
|
+
[Fact(Skip = "Remove to run test")]
|
32
|
+
public void Subtract_two_positive_rational_numbers()
|
33
|
+
{
|
34
|
+
Assert.Equal(new RationalNumber (-1, 6), new RationalNumber(1, 2) - (new RationalNumber(2, 3)));
|
35
|
+
}
|
36
|
+
|
37
|
+
[Fact(Skip = "Remove to run test")]
|
38
|
+
public void Subtract_a_positive_rational_number_and_a_negative_rational_number()
|
39
|
+
{
|
40
|
+
Assert.Equal(new RationalNumber (7, 6), new RationalNumber(1, 2) - (new RationalNumber(-2, 3)));
|
41
|
+
}
|
42
|
+
|
43
|
+
[Fact(Skip = "Remove to run test")]
|
44
|
+
public void Subtract_two_negative_rational_numbers()
|
45
|
+
{
|
46
|
+
Assert.Equal(new RationalNumber (1, 6), new RationalNumber(-1, 2) - (new RationalNumber(-2, 3)));
|
47
|
+
}
|
48
|
+
|
49
|
+
[Fact(Skip = "Remove to run test")]
|
50
|
+
public void Subtract_a_rational_number_from_itself()
|
51
|
+
{
|
52
|
+
Assert.Equal(new RationalNumber (0, 1), new RationalNumber(1, 2) - (new RationalNumber(1, 2)));
|
53
|
+
}
|
54
|
+
|
55
|
+
[Fact(Skip = "Remove to run test")]
|
56
|
+
public void Multiply_two_positive_rational_numbers()
|
57
|
+
{
|
58
|
+
Assert.Equal(new RationalNumber (1, 3), new RationalNumber(1, 2) * (new RationalNumber(2, 3)));
|
59
|
+
}
|
60
|
+
|
61
|
+
[Fact(Skip = "Remove to run test")]
|
62
|
+
public void Multiply_a_negative_rational_number_by_a_positive_rational_number()
|
63
|
+
{
|
64
|
+
Assert.Equal(new RationalNumber (-1, 3), new RationalNumber(-1, 2) * (new RationalNumber(2, 3)));
|
65
|
+
}
|
66
|
+
|
67
|
+
[Fact(Skip = "Remove to run test")]
|
68
|
+
public void Multiply_two_negative_rational_numbers()
|
69
|
+
{
|
70
|
+
Assert.Equal(new RationalNumber (1, 3), new RationalNumber(-1, 2) * (new RationalNumber(-2, 3)));
|
71
|
+
}
|
72
|
+
|
73
|
+
[Fact(Skip = "Remove to run test")]
|
74
|
+
public void Multiply_a_rational_number_by_its_reciprocal()
|
75
|
+
{
|
76
|
+
Assert.Equal(new RationalNumber (1, 1), new RationalNumber(1, 2) * (new RationalNumber(2, 1)));
|
77
|
+
}
|
78
|
+
|
79
|
+
[Fact(Skip = "Remove to run test")]
|
80
|
+
public void Multiply_a_rational_number_by_1()
|
81
|
+
{
|
82
|
+
Assert.Equal(new RationalNumber (1, 2), new RationalNumber(1, 2) * (new RationalNumber(1, 1)));
|
83
|
+
}
|
84
|
+
|
85
|
+
[Fact(Skip = "Remove to run test")]
|
86
|
+
public void Multiply_a_rational_number_by_0()
|
87
|
+
{
|
88
|
+
Assert.Equal(new RationalNumber (0, 1), new RationalNumber(1, 2) * (new RationalNumber(0, 1)));
|
89
|
+
}
|
90
|
+
|
91
|
+
[Fact(Skip = "Remove to run test")]
|
92
|
+
public void Divide_two_positive_rational_numbers()
|
93
|
+
{
|
94
|
+
Assert.Equal(new RationalNumber (3, 4), new RationalNumber(1, 2) / (new RationalNumber(2, 3)));
|
95
|
+
}
|
96
|
+
|
97
|
+
[Fact(Skip = "Remove to run test")]
|
98
|
+
public void Divide_a_positive_rational_number_by_a_negative_rational_number()
|
99
|
+
{
|
100
|
+
Assert.Equal(new RationalNumber (-3, 4), new RationalNumber(1, 2) / (new RationalNumber(-2, 3)));
|
101
|
+
}
|
102
|
+
|
103
|
+
[Fact(Skip = "Remove to run test")]
|
104
|
+
public void Divide_two_negative_rational_numbers()
|
105
|
+
{
|
106
|
+
Assert.Equal(new RationalNumber (3, 4), new RationalNumber(-1, 2) / (new RationalNumber(-2, 3)));
|
107
|
+
}
|
108
|
+
|
109
|
+
[Fact(Skip = "Remove to run test")]
|
110
|
+
public void Divide_a_rational_number_by_1()
|
111
|
+
{
|
112
|
+
Assert.Equal(new RationalNumber (1, 2), new RationalNumber(1, 2) / (new RationalNumber(1, 1)));
|
113
|
+
}
|
114
|
+
|
115
|
+
[Fact(Skip = "Remove to run test")]
|
116
|
+
public void Absolute_value_of_a_positive_rational_number()
|
117
|
+
{
|
118
|
+
Assert.Equal(new RationalNumber (1, 2), new RationalNumber(1, 2).Abs());
|
119
|
+
}
|
120
|
+
|
121
|
+
[Fact(Skip = "Remove to run test")]
|
122
|
+
public void Absolute_value_of_a_negative_rational_number()
|
123
|
+
{
|
124
|
+
Assert.Equal(new RationalNumber (1, 2), new RationalNumber(-1, 2).Abs());
|
125
|
+
}
|
126
|
+
|
127
|
+
[Fact(Skip = "Remove to run test")]
|
128
|
+
public void Absolute_value_of_zero()
|
129
|
+
{
|
130
|
+
Assert.Equal(new RationalNumber (0, 1), new RationalNumber(0, 1).Abs());
|
131
|
+
}
|
132
|
+
|
133
|
+
[Fact(Skip = "Remove to run test")]
|
134
|
+
public void Raise_a_positive_rational_number_to_a_positive_integer_power()
|
135
|
+
{
|
136
|
+
Assert.Equal(new RationalNumber (1, 8), new RationalNumber(1, 2).Exprational(3));
|
137
|
+
}
|
138
|
+
|
139
|
+
[Fact(Skip = "Remove to run test")]
|
140
|
+
public void Raise_a_negative_rational_number_to_a_positive_integer_power()
|
141
|
+
{
|
142
|
+
Assert.Equal(new RationalNumber (-1, 8), new RationalNumber(-1, 2).Exprational(3));
|
143
|
+
}
|
144
|
+
|
145
|
+
[Fact(Skip = "Remove to run test")]
|
146
|
+
public void Raise_zero_to_an_integer_power()
|
147
|
+
{
|
148
|
+
Assert.Equal(new RationalNumber (0, 1), new RationalNumber(0, 1).Exprational(5));
|
149
|
+
}
|
150
|
+
|
151
|
+
[Fact(Skip = "Remove to run test")]
|
152
|
+
public void Raise_one_to_an_integer_power()
|
153
|
+
{
|
154
|
+
Assert.Equal(new RationalNumber (1, 1), new RationalNumber(1, 1).Exprational(4));
|
155
|
+
}
|
156
|
+
|
157
|
+
[Fact(Skip = "Remove to run test")]
|
158
|
+
public void Raise_a_positive_rational_number_to_the_power_of_zero()
|
159
|
+
{
|
160
|
+
Assert.Equal(new RationalNumber (1, 1), new RationalNumber(1, 2).Exprational(0));
|
161
|
+
}
|
162
|
+
|
163
|
+
[Fact(Skip = "Remove to run test")]
|
164
|
+
public void Raise_a_negative_rational_number_to_the_power_of_zero()
|
165
|
+
{
|
166
|
+
Assert.Equal(new RationalNumber (1, 1), new RationalNumber(-1, 2).Exprational(0));
|
167
|
+
}
|
168
|
+
|
169
|
+
[Fact(Skip = "Remove to run test")]
|
170
|
+
public void Raise_a_real_number_to_a_positive_rational_number()
|
171
|
+
{
|
172
|
+
Assert.Equal(16, 8.Expreal(new RationalNumber(4, 3)),0);
|
173
|
+
}
|
174
|
+
|
175
|
+
[Fact(Skip = "Remove to run test")]
|
176
|
+
public void Raise_a_real_number_to_a_negative_rational_number()
|
177
|
+
{
|
178
|
+
Assert.Equal(0.333333333333333, 9.Expreal(new RationalNumber(-1, 2)),15);
|
179
|
+
}
|
180
|
+
|
181
|
+
[Fact(Skip = "Remove to run test")]
|
182
|
+
public void Raise_a_real_number_to_a_zero_rational_number()
|
183
|
+
{
|
184
|
+
Assert.Equal(1, 2.Expreal(new RationalNumber(0, 1)),0);
|
185
|
+
}
|
186
|
+
|
187
|
+
[Fact(Skip = "Remove to run test")]
|
188
|
+
public void Reduce_a_positive_rational_number_to_lowest_terms()
|
189
|
+
{
|
190
|
+
Assert.Equal(new RationalNumber (1, 2), new RationalNumber(2, 4).Reduce());
|
191
|
+
}
|
192
|
+
|
193
|
+
[Fact(Skip = "Remove to run test")]
|
194
|
+
public void Reduce_a_negative_rational_number_to_lowest_terms()
|
195
|
+
{
|
196
|
+
Assert.Equal(new RationalNumber (-2, 3), new RationalNumber(-4, 6).Reduce());
|
197
|
+
}
|
198
|
+
|
199
|
+
[Fact(Skip = "Remove to run test")]
|
200
|
+
public void Reduce_a_rational_number_with_a_negative_denominator_to_lowest_terms()
|
201
|
+
{
|
202
|
+
Assert.Equal(new RationalNumber (-1, 3), new RationalNumber(3, -9).Reduce());
|
203
|
+
}
|
204
|
+
|
205
|
+
[Fact(Skip = "Remove to run test")]
|
206
|
+
public void Reduce_zero_to_lowest_terms()
|
207
|
+
{
|
208
|
+
Assert.Equal(new RationalNumber (0, 1), new RationalNumber(0, 6).Reduce());
|
209
|
+
}
|
210
|
+
|
211
|
+
[Fact(Skip = "Remove to run test")]
|
212
|
+
public void Reduce_an_integer_to_lowest_terms()
|
213
|
+
{
|
214
|
+
Assert.Equal(new RationalNumber (-2, 1), new RationalNumber(-14, 7).Reduce());
|
215
|
+
}
|
216
|
+
|
217
|
+
[Fact(Skip = "Remove to run test")]
|
218
|
+
public void Reduce_one_to_lowest_terms()
|
219
|
+
{
|
220
|
+
Assert.Equal(new RationalNumber (1, 1), new RationalNumber(13, 13).Reduce());
|
221
|
+
}
|
222
|
+
}
|
@@ -0,0 +1,5 @@
|
|
1
|
+
## Hints
|
2
|
+
This exercise requires you to write an extension method. For more information, see [this page](https://msdn.microsoft.com/en-us//library/bb383977.aspx).
|
3
|
+
|
4
|
+
This exercise also requires you to write operator overloading methods for +, -, * and / operators. For more information, see [this page](https://msdn.microsoft.com/en-us/library/5tk49fh2.aspx).
|
5
|
+
|
@@ -0,0 +1,73 @@
|
|
1
|
+
using Generators.Output;
|
2
|
+
|
3
|
+
namespace Generators.Exercises
|
4
|
+
{
|
5
|
+
public struct RationalNumber
|
6
|
+
{
|
7
|
+
public RationalNumber(int[] n)
|
8
|
+
{
|
9
|
+
this.Numerator = n[0];
|
10
|
+
this.Denominator = n[1];
|
11
|
+
}
|
12
|
+
|
13
|
+
public int Numerator { get; }
|
14
|
+
public int Denominator { get; }
|
15
|
+
}
|
16
|
+
|
17
|
+
public class RationalNumbers : GeneratorExercise
|
18
|
+
{
|
19
|
+
protected override string RenderTestMethodBodyAssert(TestMethodBody testMethodBody)
|
20
|
+
{
|
21
|
+
var input = testMethodBody.CanonicalDataCase.Properties["input"] as System.Collections.Generic.Dictionary<string, object>;
|
22
|
+
var operation = testMethodBody.CanonicalDataCase.Properties["property"].ToString();
|
23
|
+
var expected = testMethodBody.CanonicalDataCase.Properties["expected"];
|
24
|
+
var operationName = char.ToUpper(operation[0]) + operation.Substring(1);
|
25
|
+
string assertCodeLine = "";
|
26
|
+
string operationsWithOverloading = "add|+|sub|-|mul|*|div|/";
|
27
|
+
string operationCode = operationsWithOverloading.Substring(operationsWithOverloading.IndexOf(operation.ToLower()) + 4, 1);
|
28
|
+
|
29
|
+
switch (operation.ToLower())
|
30
|
+
{
|
31
|
+
case "add":
|
32
|
+
case "sub":
|
33
|
+
case "mul":
|
34
|
+
case "div":
|
35
|
+
{
|
36
|
+
var r1 = new RationalNumber((int[])input["r1"]);
|
37
|
+
var r2 = new RationalNumber((int[])input["r2"]);
|
38
|
+
var e = new RationalNumber((int[])expected);
|
39
|
+
assertCodeLine = "Assert.Equal(" + $"new RationalNumber ({e.Numerator}, {e.Denominator}), new RationalNumber({r1.Numerator}, {r1.Denominator}) {operationCode} (new RationalNumber({r2.Numerator}, {r2.Denominator})));";
|
40
|
+
}
|
41
|
+
break;
|
42
|
+
case "abs":
|
43
|
+
case "reduce":
|
44
|
+
{
|
45
|
+
var r = new RationalNumber((int[])input["r"]);
|
46
|
+
var e = new RationalNumber((int[])expected);
|
47
|
+
assertCodeLine = "Assert.Equal(" + $"new RationalNumber ({e.Numerator}, {e.Denominator}), new RationalNumber({r.Numerator}, {r.Denominator}).{operationName}());";
|
48
|
+
}
|
49
|
+
break;
|
50
|
+
case "exprational":
|
51
|
+
{
|
52
|
+
var r = new RationalNumber((int[])input["r"]);
|
53
|
+
var n = input["n"];
|
54
|
+
var e = new RationalNumber((int[])expected);
|
55
|
+
assertCodeLine = "Assert.Equal(" + $"new RationalNumber ({e.Numerator}, {e.Denominator}), new RationalNumber({r.Numerator}, {r.Denominator}).{operationName}({n}));";
|
56
|
+
}
|
57
|
+
break;
|
58
|
+
case "expreal":
|
59
|
+
{
|
60
|
+
var x = input["x"].ToString();
|
61
|
+
var r = new RationalNumber((int[])input["r"]);
|
62
|
+
var e = expected;
|
63
|
+
var p = precision(e);
|
64
|
+
assertCodeLine = "Assert.Equal(" + $"{e}, {x}.{operationName}(new RationalNumber({r.Numerator}, {r.Denominator})),{p});";
|
65
|
+
}
|
66
|
+
break;
|
67
|
+
}
|
68
|
+
return TemplateRenderer.RenderInline(assertCodeLine, testMethodBody.AssertTemplateParameters);
|
69
|
+
}
|
70
|
+
|
71
|
+
private static int precision(object rawValue) => rawValue.ToString().Split(new char[] { '.' }).Length <= 1 ? 0 : rawValue.ToString().Split(new char[] { '.' })[1].Length;
|
72
|
+
}
|
73
|
+
}
|
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.3.0
|
@@ -221,7 +221,7 @@ public class BaseConverterTest {
|
|
221
221
|
expectedException.expect(IllegalArgumentException.class);
|
222
222
|
expectedException.expectMessage("Bases must be at least 2.");
|
223
223
|
|
224
|
-
new BaseConverter(1, new int[]{});
|
224
|
+
new BaseConverter(1, new int[]{1});
|
225
225
|
}
|
226
226
|
|
227
227
|
@Ignore("Remove to run test")
|
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.2.0
|
@@ -68,6 +68,13 @@ public class RomanNumeralsTest {
|
|
68
68
|
romanNumeral = new RomanNumeral(48);
|
69
69
|
assertEquals("XLVIII", romanNumeral.getRomanNumeral());
|
70
70
|
}
|
71
|
+
|
72
|
+
@Ignore("Remove to run test")
|
73
|
+
@Test
|
74
|
+
public void test49ToRomanNumberXLIX() {
|
75
|
+
romanNumeral = new RomanNumeral(49);
|
76
|
+
assertEquals("XLIX", romanNumeral.getRomanNumeral());
|
77
|
+
}
|
71
78
|
|
72
79
|
@Ignore("Remove to run test")
|
73
80
|
@Test
|
@@ -45,11 +45,10 @@ The message above is coded as:
|
|
45
45
|
imtgdvsfearwermayoogoanouuiontnnlvtwttddesaohghnsseoau
|
46
46
|
```
|
47
47
|
|
48
|
-
Output the encoded text in chunks
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
`n` chunks.
|
48
|
+
Output the encoded text in chunks that fill perfect rectangles `(r X c)`,
|
49
|
+
with `c` chunks of `r` length, separated by spaces. For phrases that are
|
50
|
+
`n` characters short of the perfect rectangle, pad each of the last `n`
|
51
|
+
chunks with a single trailing space.
|
53
52
|
|
54
53
|
```text
|
55
54
|
imtgdvs fearwer mayoogo anouuio ntnnlvt wttddes aohghn sseoau
|
@@ -4,13 +4,13 @@ Given a tonic, or starting note, and a set of intervals, generate
|
|
4
4
|
the musical scale starting with the tonic and following the
|
5
5
|
specified interval pattern.
|
6
6
|
|
7
|
-
Scales in Western music are based on the chromatic (12-note) scale.This
|
7
|
+
Scales in Western music are based on the chromatic (12-note) scale. This
|
8
8
|
scale can be expressed as the following group of pitches:
|
9
9
|
|
10
10
|
A, A#, B, C, C#, D, D#, E, F, F#, G, G#
|
11
11
|
|
12
|
-
A given sharp note (indicated by a #)
|
13
|
-
of the note above it (indicated by a b)
|
12
|
+
A given sharp note (indicated by a #) can also be expressed as the flat
|
13
|
+
of the note above it (indicated by a b) so the chromatic scale can also be
|
14
14
|
written like this:
|
15
15
|
|
16
16
|
A, Bb, B, C, Db, D, Eb, E, F, Gb, G, Ab
|
@@ -20,9 +20,9 @@ collection. They have seven pitches, and are called diatonic scales.
|
|
20
20
|
The collection of notes in these scales is written with either sharps or
|
21
21
|
flats, depending on the tonic. Here is a list of which are which:
|
22
22
|
|
23
|
-
No
|
23
|
+
No Sharps or Flats:
|
24
24
|
C major
|
25
|
-
|
25
|
+
a minor
|
26
26
|
|
27
27
|
Use Sharps:
|
28
28
|
G, D, A, E, B, F# major
|
@@ -43,17 +43,10 @@ a "whole step" or "major second" (written as an upper-case "M"). The
|
|
43
43
|
diatonic scales are built using only these two intervals between
|
44
44
|
adjacent notes.
|
45
45
|
|
46
|
-
Non-diatonic scales can contain
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
Here is a table of pitches with the names of their interval distance from the tonic (A).
|
51
|
-
|
52
|
-
| A | A# | B | C | C# | D | D# | E | F | F# | G | G# | A |
|
53
|
-
|:------:|:-------:|:-------:|:-------:|:-------:|:-------:|:-------:|:-------:|:-------:|:-------:|:-------:|:-------:|:------:|
|
54
|
-
| Unison | Min 2nd | Maj 2nd | Min 3rd | Maj 3rd | Per 4th | Tritone | Per 5th | Min 6th | Maj 6th | Min 7th | Maj 7th | Octave |
|
55
|
-
| | | Dim 3rd | Aug 2nd | Dim 4th | | Aug 4th | Dim 5th | Aug 5th | Dim 7th | Aug 6th | Dim 8ve | |
|
56
|
-
| | | | | | | Dim 5th | | | | | | |
|
46
|
+
Non-diatonic scales can contain other intervals. An "augmented first"
|
47
|
+
interval, written "A", has two interceding notes (e.g., from A to C or
|
48
|
+
Db to E). There are also smaller and larger intervals, but they will not
|
49
|
+
figure into this exercise.
|
57
50
|
|
58
51
|
## Exception messages
|
59
52
|
|
data/tracks/swift/config.json
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: trackler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.2.1.
|
4
|
+
version: 2.2.1.134
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Katrina Owen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-04-
|
11
|
+
date: 2018-04-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubyzip
|
@@ -2938,6 +2938,12 @@ files:
|
|
2938
2938
|
- tracks/csharp/exercises/raindrops/Raindrops.cs
|
2939
2939
|
- tracks/csharp/exercises/raindrops/Raindrops.csproj
|
2940
2940
|
- tracks/csharp/exercises/raindrops/RaindropsTest.cs
|
2941
|
+
- tracks/csharp/exercises/rational-numbers/Example.cs
|
2942
|
+
- tracks/csharp/exercises/rational-numbers/README.md
|
2943
|
+
- tracks/csharp/exercises/rational-numbers/RationalNumbers.cs
|
2944
|
+
- tracks/csharp/exercises/rational-numbers/RationalNumbers.csproj
|
2945
|
+
- tracks/csharp/exercises/rational-numbers/RationalNumbersTest.cs
|
2946
|
+
- tracks/csharp/exercises/rational-numbers/hints.md
|
2941
2947
|
- tracks/csharp/exercises/react/.meta/hints.md
|
2942
2948
|
- tracks/csharp/exercises/react/Example.cs
|
2943
2949
|
- tracks/csharp/exercises/react/README.md
|
@@ -3200,6 +3206,7 @@ files:
|
|
3200
3206
|
- tracks/csharp/generators/Exercises/QueenAttack.cs
|
3201
3207
|
- tracks/csharp/generators/Exercises/RailFenceCipher.cs
|
3202
3208
|
- tracks/csharp/generators/Exercises/Raindrops.cs
|
3209
|
+
- tracks/csharp/generators/Exercises/RationalNumbers.cs
|
3203
3210
|
- tracks/csharp/generators/Exercises/ReverseString.cs
|
3204
3211
|
- tracks/csharp/generators/Exercises/RnaTranscription.cs
|
3205
3212
|
- tracks/csharp/generators/Exercises/RobotSimulator.cs
|