trackler 2.0.5.5 → 2.0.5.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/lib/trackler/version.rb +1 -1
  3. data/tracks/csharp/config.json +15 -0
  4. data/tracks/csharp/exercises/list-ops/Example.cs +77 -0
  5. data/tracks/csharp/exercises/list-ops/HINTS.md +2 -0
  6. data/tracks/csharp/exercises/list-ops/ListOpsTest.cs +195 -0
  7. data/tracks/csharp/exercises/two-bucket/Example.cs +109 -0
  8. data/tracks/csharp/exercises/two-bucket/TwoBucketTest.cs +71 -0
  9. data/tracks/ecmascript/config.json +13 -30
  10. data/tracks/ecmascript/exercises/all-your-base/all-your-base.spec.js +139 -0
  11. data/tracks/ecmascript/exercises/all-your-base/example.js +55 -0
  12. data/tracks/ecmascript/exercises/all-your-base/gulpfile.js +89 -0
  13. data/tracks/ecmascript/exercises/all-your-base/package.json +28 -0
  14. data/tracks/fsharp/exercises/diffie-hellman/HINTS.md +3 -0
  15. data/tracks/fsharp/exercises/gigasecond/HINTS.md +2 -0
  16. data/tracks/fsharp/exercises/palindrome-products/HINTS.md +2 -0
  17. data/tracks/java/config.json +6 -0
  18. data/tracks/java/docs/INSTALLATION.md +1 -0
  19. data/tracks/java/exercises/custom-set/build.gradle +18 -0
  20. data/tracks/java/exercises/custom-set/src/example/java/CustomSet.java +74 -0
  21. data/tracks/java/exercises/custom-set/src/main/java/.keep +0 -0
  22. data/tracks/java/exercises/custom-set/src/test/java/CustomSetTest.java +505 -0
  23. data/tracks/java/exercises/settings.gradle +1 -0
  24. data/tracks/purescript/config.json +25 -0
  25. data/tracks/purescript/exercises/accumulate/bower.json +16 -0
  26. data/tracks/purescript/exercises/accumulate/examples/src/Accumulate.purs +15 -0
  27. data/tracks/purescript/exercises/accumulate/src/Accumulate.purs +3 -0
  28. data/tracks/purescript/exercises/accumulate/test/Main.purs +41 -0
  29. data/tracks/purescript/exercises/acronym/bower.json +1 -1
  30. data/tracks/purescript/exercises/bob/bower.json +1 -1
  31. data/tracks/purescript/exercises/pangram/bower.json +1 -1
  32. data/tracks/purescript/exercises/raindrops/bower.json +1 -1
  33. data/tracks/purescript/exercises/scrabble-score/bower.json +16 -0
  34. data/tracks/purescript/exercises/scrabble-score/examples/src/ScrabbleScore.purs +47 -0
  35. data/tracks/purescript/exercises/scrabble-score/src/ScrabbleScore.purs +3 -0
  36. data/tracks/purescript/exercises/scrabble-score/test/Main.purs +45 -0
  37. data/tracks/purescript/exercises/triangle/bower.json +19 -0
  38. data/tracks/purescript/exercises/triangle/examples/src/Triangle.purs +40 -0
  39. data/tracks/purescript/exercises/triangle/src/Triangle.purs +4 -0
  40. data/tracks/purescript/exercises/triangle/test/Main.purs +66 -0
  41. data/tracks/ruby/.rubocop.yml +3 -0
  42. data/tracks/ruby/README.md +1 -1
  43. metadata +30 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8d5432bf225e49f96fd078ad1c2e11e82d291780
4
- data.tar.gz: 9ebb6ec88ed0bb64313051385c09b16e3a313f21
3
+ metadata.gz: 838fe7957432a1754b9feb3301d62ea08e130958
4
+ data.tar.gz: 3e4a657d880d96c9d725777036fb135e8cc41024
5
5
  SHA512:
6
- metadata.gz: faf9bf3ac196a3c1f3cd6ee3ba48e31e182eb6176fea567ef641b4e2b941a671f77d6df6433a3393735c450a41a17236ba3d83ff20701db3aaa140963d32b967
7
- data.tar.gz: ced5a0f1c865bb6322d2c2efd31720a545f9551630732ee6e5bf2bfc1a7a2660a860eab9ad2804600b7e7795c1eaabc2ad2de55fe3c7e07a618797249e9d5dc4
6
+ metadata.gz: 3ee120f448ed1307b7ed74945776f1e4e9d771bbbc435e6de07f08e253b30595ba534bbac2e483bb80e9539aba1d0d7085c22c125c0313e6f6e9539e9864d7ca
7
+ data.tar.gz: 459c7b9d7a799eafe0dab3f210000160346fb953ea6bff098148581788d1c3ceac4842710086b8b1700840b46c2d9437e132e267ffa064d15401ca7a9e7ec129
@@ -1,3 +1,3 @@
1
1
  module Trackler
2
- VERSION = "2.0.5.5"
2
+ VERSION = "2.0.5.6"
3
3
  end
@@ -403,6 +403,14 @@
403
403
  "Mathematics"
404
404
  ]
405
405
  },
406
+ {
407
+ "slug": "list-ops",
408
+ "difficulty": 5,
409
+ "topics": [
410
+ "Lists",
411
+ "Recursion"
412
+ ]
413
+ },
406
414
  {
407
415
  "slug": "simple-cipher",
408
416
  "difficulty": 5,
@@ -691,6 +699,13 @@
691
699
  "Algorithms"
692
700
  ]
693
701
  },
702
+ {
703
+ "slug": "two-bucket",
704
+ "difficulty": 8,
705
+ "topics": [
706
+ "Logic"
707
+ ]
708
+ },
694
709
  {
695
710
  "slug": "say",
696
711
  "difficulty": 8,
@@ -0,0 +1,77 @@
1
+ using System;
2
+ using System.Collections.Generic;
3
+ using System.Linq;
4
+
5
+ public static class ListOps
6
+ {
7
+ private static List<T> Cons<T>(T x, List<T> input)
8
+ {
9
+ var list = new List<T>(input);
10
+ list.Insert(0, x);
11
+
12
+ return list;
13
+ }
14
+
15
+ public static int Length<T>(List<T> input)
16
+ {
17
+ return Foldl((acc, x) => acc + 1, 0, input);
18
+ }
19
+
20
+ public static List<T> Reverse<T>(List<T> input)
21
+ {
22
+ return Foldl((acc, x) => Cons(x, acc), new List<T>(), input);
23
+ }
24
+
25
+ public static List<TOut> Map<TIn, TOut>(Func<TIn, TOut> map, List<TIn> input)
26
+ {
27
+ return Foldr((x, acc) => Cons(map(x), acc), new List<TOut>(), input);
28
+ }
29
+
30
+ public static List<T> Filter<T>(Func<T, bool> predicate, List<T> input)
31
+ {
32
+ return Foldr((x, acc) => predicate(x) ? Cons(x, acc) : acc, new List<T>(), input);
33
+ }
34
+
35
+ public static TOut Foldl<TIn, TOut>(Func<TOut, TIn, TOut> func, TOut start, List<TIn> input)
36
+ {
37
+ var acc = start;
38
+
39
+ foreach (var item in input)
40
+ acc = func(acc, item);
41
+
42
+ return acc;
43
+ }
44
+
45
+ public static TOut Foldr<TIn, TOut>(Func<TIn, TOut, TOut> func, TOut start, List<TIn> input)
46
+ {
47
+ var acc = start;
48
+
49
+ for (var i = input.Count - 1; i >= 0; i--)
50
+ acc = func(input[i], acc);
51
+
52
+ return acc;
53
+ }
54
+
55
+ public static List<T> Concat<T>(List<List<T>> input)
56
+ {
57
+ var concatenated = new List<T>();
58
+
59
+ foreach (var list in input)
60
+ concatenated = Append(concatenated, list);
61
+
62
+ return concatenated;
63
+ }
64
+
65
+ public static List<T> Append<T>(List<T> left, List<T> right)
66
+ {
67
+ var appended = new T[left.Count + right.Count];
68
+
69
+ for (var i = 0; i < left.Count; i++)
70
+ appended[i] = left[i];
71
+
72
+ for (var j = 0; j < right.Count; j++)
73
+ appended[left.Count + j] = right[j];
74
+
75
+ return appended.ToList();
76
+ }
77
+ }
@@ -0,0 +1,2 @@
1
+ ## Hints
2
+ The `Foldl` andf `Foldr` methods are "fold" functions, which is a concept well-known in the functional programming world, but less so in the object-oriented one. If you'd like more background information, check out this[fold](https://en.wikipedia.org/wiki/Fold_(higher-order_function)) page.
@@ -0,0 +1,195 @@
1
+ using System.Collections.Generic;
2
+ using System.Linq;
3
+ using NUnit.Framework;
4
+
5
+ public class ListOpsTest
6
+ {
7
+ private const int Big = 10000;
8
+ private static readonly List<int> BigList = Range(1, Big);
9
+ private static readonly List<int> EmptyList = new List<int>();
10
+
11
+ private static List<int> Range(int from, int until) => new List<int>(Enumerable.Range(from, (until - from) + 1));
12
+ private static bool Odd(int x) => x % 2 == 1;
13
+
14
+ private static List<T> Cons<T>(T x, List<T> input)
15
+ {
16
+ var list = new List<T>(input);
17
+ list.Insert(0, x);
18
+
19
+ return list;
20
+ }
21
+
22
+ [Test]
23
+ public void LengthOfEmptyList()
24
+ {
25
+ Assert.That(ListOps.Length(EmptyList), Is.EqualTo(0));
26
+ }
27
+
28
+ [Ignore("Remove to run test")]
29
+ [Test]
30
+ public void LengthOfNonEmptyList()
31
+ {
32
+ Assert.That(ListOps.Length(Range(1, 4)), Is.EqualTo(4));
33
+ }
34
+
35
+ [Ignore("Remove to run test")]
36
+ [Test]
37
+ public void LengthOfLargeList()
38
+ {
39
+ Assert.That(ListOps.Length(Range(1, Big)), Is.EqualTo(Big));
40
+ }
41
+
42
+ [Ignore("Remove to run test")]
43
+ [Test]
44
+ public void ReverseOfEmptylist()
45
+ {
46
+ Assert.That(ListOps.Reverse(EmptyList), Is.EquivalentTo(EmptyList));
47
+ }
48
+
49
+ [Ignore("Remove to run test")]
50
+ [Test]
51
+ public void ReverseOfNonEmptyList()
52
+ {
53
+ Assert.That(ListOps.Reverse(Range(1, 100)), Is.EquivalentTo(Range(1, 100).OrderByDescending(x => x).ToList()));
54
+ }
55
+
56
+ [Ignore("Remove to run test")]
57
+ [Test]
58
+ public void MapOfEmptylist()
59
+ {
60
+ Assert.That(ListOps.Map(x => x + 1, EmptyList), Is.EquivalentTo(EmptyList));
61
+ }
62
+
63
+ [Ignore("Remove to run test")]
64
+ [Test]
65
+ public void MapOfNonEmptyList()
66
+ {
67
+ Assert.That(ListOps.Map(x => x + 1, new List<int> {1, 3, 5, 7}), Is.EquivalentTo(new List<int> {2, 4, 6, 8}));
68
+ }
69
+
70
+ [Ignore("Remove to run test")]
71
+ [Test]
72
+ public void FilterOfEmptylist()
73
+ {
74
+ Assert.That(ListOps.Filter(x => true, EmptyList), Is.EquivalentTo(EmptyList));
75
+ }
76
+
77
+ [Ignore("Remove to run test")]
78
+ [Test]
79
+ public void FilterOfNormalList()
80
+ {
81
+ Assert.That(ListOps.Filter(Odd, Range(1, 4)), Is.EquivalentTo(new List<int> {1, 3}));
82
+ }
83
+
84
+ [Ignore("Remove to run test")]
85
+ [Test]
86
+ public void FoldlOfEmptylist()
87
+ {
88
+ Assert.That(ListOps.Foldl((acc, x) => acc + x, 0, EmptyList), Is.EqualTo(0));
89
+ }
90
+
91
+ [Ignore("Remove to run test")]
92
+ [Test]
93
+ public void FoldlOfNonEmptyList()
94
+ {
95
+ Assert.That(ListOps.Foldl((acc, x) => acc + x, -3, Range(1, 4)), Is.EqualTo(7));
96
+ }
97
+
98
+ [Ignore("Remove to run test")]
99
+ [Test]
100
+ public void FoldlOfHugeList()
101
+ {
102
+ Assert.That(ListOps.Foldl((acc, x) => acc + x, 0L, Range(1, Big)), Is.EqualTo(Big * (Big + 1L) / 2L));
103
+ }
104
+
105
+ [Ignore("Remove to run test")]
106
+ [Test]
107
+ public void FoldlWithNonCommutativeFunction()
108
+ {
109
+ Assert.That(ListOps.Foldl((acc, x) => acc - x, 10, Range(1, 4)), Is.EqualTo(0));
110
+ }
111
+
112
+ [Ignore("Remove to run test")]
113
+ [Test]
114
+ public void FoldlIsNotJustFoldrFlip()
115
+ {
116
+ Assert.That(ListOps.Foldl((acc, x) => Cons(x, acc), EmptyList, "asdf".ToList()), Is.EqualTo("fdsa".ToList()));
117
+ }
118
+
119
+ [Ignore("Remove to run test")]
120
+ [Test]
121
+ public void FoldrAsId()
122
+ {
123
+ Assert.That(ListOps.Foldr((x, acc) => Cons(x, acc), EmptyList, Range(1, Big)), Is.EquivalentTo(BigList));
124
+ }
125
+
126
+ [Ignore("Remove to run test")]
127
+ [Test]
128
+ public void FoldrAsAppend()
129
+ {
130
+ Assert.That(ListOps.Foldr((x, acc) => Cons(x, acc), Range(100, Big), Range(1, 99)), Is.EquivalentTo(BigList));
131
+ }
132
+
133
+ [Ignore("Remove to run test")]
134
+ [Test]
135
+ public void AppendOfEmptylists()
136
+ {
137
+ Assert.That(ListOps.Append(EmptyList, EmptyList), Is.EqualTo(EmptyList));
138
+ }
139
+
140
+ [Ignore("Remove to run test")]
141
+ [Test]
142
+ public void AppendOfEmptyAndNonEmptyLists()
143
+ {
144
+ Assert.That(ListOps.Append(EmptyList, Range(1, 4)), Is.EqualTo(Range(1, 4)));
145
+ }
146
+
147
+ [Ignore("Remove to run test")]
148
+ [Test]
149
+ public void AppendOfNonEmptyAndEmptyLists()
150
+ {
151
+ Assert.That(ListOps.Append(Range(1, 4), EmptyList), Is.EqualTo(Range(1, 4)));
152
+ }
153
+
154
+ [Ignore("Remove to run test")]
155
+ [Test]
156
+ public void AppendOfNonEmptylists()
157
+ {
158
+ Assert.That(ListOps.Append(Range(1, 3), new List<int> {4, 5}), Is.EqualTo(Range(1, 5)));
159
+ }
160
+
161
+ [Ignore("Remove to run test")]
162
+ [Test]
163
+ public void AppendOfLargeLists()
164
+ {
165
+ Assert.That(ListOps.Append(Range(1, Big / 2), Range(1 + Big / 2, Big)), Is.EquivalentTo(BigList));
166
+ }
167
+
168
+ [Ignore("Remove to run test")]
169
+ [Test]
170
+ public void ConcatOfNoLists()
171
+ {
172
+ Assert.That(ListOps.Concat(new List<List<int>>()), Is.EqualTo(EmptyList));
173
+ }
174
+
175
+ [Ignore("Remove to run test")]
176
+ [Test]
177
+ public void ConcatOfListOfLists()
178
+ {
179
+ Assert.That(
180
+ ListOps.Concat(new List<List<int>>
181
+ {
182
+ new List<int> {1, 2},
183
+ new List<int> {3},
184
+ EmptyList,
185
+ new List<int> {4, 5, 6}
186
+ }), Is.EqualTo(Range(1, 6)));
187
+ }
188
+
189
+ [Ignore("Remove to run test")]
190
+ [Test]
191
+ public void ConcatOfLargeListOfSmallLists()
192
+ {
193
+ Assert.That(ListOps.Concat(ListOps.Map(x => new List<int> {x}, Range(1, Big))), Is.EquivalentTo(BigList));
194
+ }
195
+ }
@@ -0,0 +1,109 @@
1
+ using System;
2
+
3
+ public enum Bucket
4
+ {
5
+ One,
6
+ Two
7
+ }
8
+
9
+ public class TwoBucketResult
10
+ {
11
+ public int Moves { get; set; }
12
+ public Bucket GoalBucket { get; set; }
13
+ public int OtherBucketContents { get; set; }
14
+ }
15
+
16
+ public class BucketContainer
17
+ {
18
+ public BucketContainer(int contents, int capacity)
19
+ {
20
+ Contents = contents;
21
+ Capacity = capacity;
22
+ }
23
+
24
+ public int Contents { get; set; }
25
+
26
+ public int Capacity { get; }
27
+
28
+ public bool IsEmpty => Contents == 0;
29
+
30
+ public bool IsFull => Contents == Capacity;
31
+
32
+ public void Fill()
33
+ {
34
+ Contents = Capacity;
35
+ }
36
+
37
+ public void Empty()
38
+ {
39
+ Contents = 0;
40
+ }
41
+
42
+ public void PourTo(BucketContainer other)
43
+ {
44
+ var amount = Math.Min(other.Capacity - other.Contents, Contents);
45
+ Contents -= amount;
46
+ other.Contents += amount;
47
+ }
48
+
49
+ public bool CanPourTo(BucketContainer other) => !IsEmpty && !other.IsFull;
50
+ }
51
+
52
+ public class TwoBuckets
53
+ {
54
+ private readonly BucketContainer bucketOne;
55
+ private readonly BucketContainer bucketTwo;
56
+ private readonly Action strategy;
57
+
58
+ public TwoBuckets(int bucketOneSize, int bucketTwoSize, Bucket startBucket)
59
+ {
60
+ bucketOne = new BucketContainer(startBucket == Bucket.One ? bucketOneSize : 0, bucketOneSize);
61
+ bucketTwo = new BucketContainer(startBucket == Bucket.Two ? bucketTwoSize : 0, bucketTwoSize);
62
+ strategy = startBucket == Bucket.One ? (Action)StartFromFirstBucket : StartFromSecondBucket;
63
+
64
+ }
65
+
66
+ public TwoBucketResult Solve(int goal)
67
+ {
68
+ var moves = 0;
69
+
70
+ while (true)
71
+ {
72
+ moves++;
73
+
74
+ if (bucketOne.Contents == goal)
75
+ return new TwoBucketResult { Moves = moves, GoalBucket = Bucket.One, OtherBucketContents = bucketTwo.Contents };
76
+
77
+ if (bucketTwo.Contents == goal)
78
+ return new TwoBucketResult { Moves = moves, GoalBucket = Bucket.Two, OtherBucketContents = bucketOne.Contents };
79
+
80
+ strategy();
81
+ }
82
+
83
+ throw new NotImplementedException();
84
+ }
85
+
86
+ public void StartFromFirstBucket()
87
+ {
88
+ if (bucketOne.IsEmpty)
89
+ bucketOne.Fill();
90
+ else if (bucketTwo.IsFull)
91
+ bucketTwo.Empty();
92
+ else if (bucketOne.CanPourTo(bucketTwo))
93
+ bucketOne.PourTo(bucketTwo);
94
+ else
95
+ throw new InvalidOperationException("Cannot transition from current state.");
96
+ }
97
+
98
+ public void StartFromSecondBucket()
99
+ {
100
+ if (bucketOne.IsFull)
101
+ bucketOne.Empty();
102
+ else if (bucketTwo.IsEmpty)
103
+ bucketTwo.Fill();
104
+ else if (bucketTwo.CanPourTo(bucketOne))
105
+ bucketTwo.PourTo(bucketOne);
106
+ else
107
+ throw new InvalidOperationException("Cannot transition from current state.");
108
+ }
109
+ }
@@ -0,0 +1,71 @@
1
+ using NUnit.Framework;
2
+
3
+ public class TwoBucketTest
4
+ {
5
+ [Test]
6
+ public void First_example()
7
+ {
8
+ var bucketOneSize = 3;
9
+ var bucketTwoSize = 5;
10
+ var goal = 1;
11
+ var startBucket = Bucket.One;
12
+ var twoBuckets = new TwoBuckets(bucketOneSize, bucketTwoSize, startBucket);
13
+
14
+ var actual = twoBuckets.Solve(goal);
15
+
16
+ Assert.That(actual.Moves, Is.EqualTo(4));
17
+ Assert.That(actual.GoalBucket, Is.EqualTo(Bucket.One));
18
+ Assert.That(actual.OtherBucketContents, Is.EqualTo(5));
19
+ }
20
+
21
+ [Ignore("Remove to run test")]
22
+ [Test]
23
+ public void Second_example()
24
+ {
25
+ var bucketOneSize = 3;
26
+ var bucketTwoSize = 5;
27
+ var goal = 1;
28
+ var startBucket = Bucket.Two;
29
+ var twoBuckets = new TwoBuckets(bucketOneSize, bucketTwoSize, startBucket);
30
+
31
+ var actual = twoBuckets.Solve(goal);
32
+
33
+ Assert.That(actual.Moves, Is.EqualTo(8));
34
+ Assert.That(actual.GoalBucket, Is.EqualTo(Bucket.Two));
35
+ Assert.That(actual.OtherBucketContents, Is.EqualTo(3));
36
+ }
37
+
38
+ [Ignore("Remove to run test")]
39
+ [Test]
40
+ public void Third_example()
41
+ {
42
+ var bucketOneSize = 7;
43
+ var bucketTwoSize = 11;
44
+ var goal = 2;
45
+ var startBucket = Bucket.One;
46
+ var twoBuckets = new TwoBuckets(bucketOneSize, bucketTwoSize, startBucket);
47
+
48
+ var actual = twoBuckets.Solve(goal);
49
+
50
+ Assert.That(actual.Moves, Is.EqualTo(14));
51
+ Assert.That(actual.GoalBucket, Is.EqualTo(Bucket.One));
52
+ Assert.That(actual.OtherBucketContents, Is.EqualTo(11));
53
+ }
54
+
55
+ [Ignore("Remove to run test")]
56
+ [Test]
57
+ public void Fourth_example()
58
+ {
59
+ var bucketOneSize = 7;
60
+ var bucketTwoSize = 11;
61
+ var goal = 2;
62
+ var startBucket = Bucket.Two;
63
+ var twoBuckets = new TwoBuckets(bucketOneSize, bucketTwoSize, startBucket);
64
+
65
+ var actual = twoBuckets.Solve(goal);
66
+
67
+ Assert.That(actual.Moves, Is.EqualTo(18));
68
+ Assert.That(actual.GoalBucket, Is.EqualTo(Bucket.Two));
69
+ Assert.That(actual.OtherBucketContents, Is.EqualTo(7));
70
+ }
71
+ }