trackler 2.2.1.15 → 2.2.1.16
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/TOPICS.txt +8 -1
- data/tracks/c/docs/SNIPPET.txt +11 -0
- data/tracks/ceylon/docs/SNIPPET.txt +3 -0
- data/tracks/clojure/docs/SNIPPET.txt +5 -0
- data/tracks/csharp/build.cake +23 -16
- data/tracks/csharp/build.ps1 +1 -1
- data/tracks/csharp/build.sh +1 -1
- data/tracks/csharp/exercises/pangram/PangramTest.cs +9 -18
- data/tracks/csharp/generators/.gitignore +2 -1
- data/tracks/csharp/generators/Exercise.cs +11 -12
- data/tracks/csharp/generators/Exercises/AllYourBase.cs +2 -2
- data/tracks/csharp/generators/Exercises/Allergies.cs +1 -1
- data/tracks/csharp/generators/Exercises/Alphametics.cs +1 -1
- data/tracks/csharp/generators/Exercises/Anagram.cs +1 -1
- data/tracks/csharp/generators/Exercises/BeerSong.cs +1 -1
- data/tracks/csharp/generators/Exercises/BinarySearch.cs +1 -1
- data/tracks/csharp/generators/Exercises/BookStore.cs +1 -1
- data/tracks/csharp/generators/Exercises/BracketPush.cs +1 -1
- data/tracks/csharp/generators/Exercises/CollatzConjecture.cs +2 -2
- data/tracks/csharp/generators/Exercises/CryptoSquare.cs +1 -1
- data/tracks/csharp/generators/Exercises/FoodChain.cs +1 -1
- data/tracks/csharp/generators/Exercises/Gigasecond.cs +1 -1
- data/tracks/csharp/generators/Exercises/Hamming.cs +1 -1
- data/tracks/csharp/generators/Exercises/House.cs +1 -1
- data/tracks/csharp/generators/Exercises/Leap.cs +1 -1
- data/tracks/csharp/generators/Exercises/Luhn.cs +1 -1
- data/tracks/csharp/generators/Exercises/NthPrime.cs +1 -1
- data/tracks/csharp/generators/Exercises/Pangram.cs +1 -11
- data/tracks/csharp/generators/Exercises/PerfectNumbers.cs +1 -1
- data/tracks/csharp/generators/Exercises/PhoneNumber.cs +1 -1
- data/tracks/csharp/generators/Exercises/RailFenceCipher.cs +1 -1
- data/tracks/csharp/generators/Exercises/RnaTranscription.cs +1 -1
- data/tracks/csharp/generators/Exercises/RomanNumerals.cs +1 -1
- data/tracks/csharp/generators/Exercises/RunLengthEncoding.cs +1 -1
- data/tracks/csharp/generators/Exercises/Say.cs +2 -7
- data/tracks/csharp/generators/Exercises/SecretHandshake.cs +1 -1
- data/tracks/csharp/generators/Exercises/Sieve.cs +1 -1
- data/tracks/csharp/generators/Exercises/SpaceAge.cs +1 -1
- data/tracks/csharp/generators/Exercises/SumOfMultiples.cs +1 -1
- data/tracks/csharp/generators/Exercises/Transpose.cs +1 -1
- data/tracks/csharp/generators/Exercises/WordCount.cs +1 -1
- data/tracks/csharp/generators/Exercises/Wordy.cs +1 -1
- data/tracks/csharp/generators/Output/FormattingExtensions.cs +4 -2
- data/tracks/csharp/generators/Output/ValueFormatter.cs +1 -1
- data/tracks/delphi/docs/SNIPPET.txt +6 -13
- data/tracks/ecmascript/docs/SNIPPET.txt +7 -0
- data/tracks/elisp/docs/SNIPPET.txt +13 -0
- data/tracks/elixir/config.json +2 -2
- data/tracks/elixir/docs/SNIPPET.txt +10 -0
- data/tracks/erlang/docs/SNIPPET.txt +8 -0
- data/tracks/fsharp/docs/SNIPPET.txt +3 -0
- data/tracks/go/config.json +174 -174
- data/tracks/go/config/maintainers.json +6 -9
- data/tracks/go/docs/SNIPPET.txt +6 -0
- data/tracks/groovy/config.json +4 -4
- data/tracks/groovy/docs/SNIPPET.txt +12 -0
- data/tracks/haskell/config.json +2 -0
- data/tracks/haskell/docs/SNIPPET.txt +4 -0
- data/tracks/java/docs/SNIPPET.txt +7 -0
- data/tracks/java/exercises/robot-simulator/src/example/java/GridPosition.java +21 -16
- data/tracks/java/exercises/robot-simulator/src/test/java/RobotTest.java +24 -24
- data/tracks/javascript/docs/SNIPPET.txt +10 -0
- data/tracks/kotlin/docs/SNIPPET.txt +3 -0
- data/tracks/kotlin/exercises/change/src/example/kotlin/ChangeCalculator.kt +35 -0
- data/tracks/kotlin/exercises/change/src/test/kotlin/ChangeCalculatorTest.kt +105 -0
- data/tracks/lfe/docs/SNIPPET.txt +12 -0
- data/tracks/lua/docs/SNIPPET.txt +7 -0
- data/tracks/mips/docs/SNIPPET.txt +23 -0
- data/tracks/ocaml/docs/SNIPPET.txt +1 -0
- data/tracks/purescript/config.json +1 -1
- data/tracks/purescript/docs/SNIPPET.txt +8 -0
- data/tracks/python/exercises/saddle-points/README.md +1 -1
- data/tracks/racket/docs/SNIPPET.txt +6 -0
- data/tracks/ruby/docs/SNIPPET.txt +5 -0
- data/tracks/rust/docs/SNIPPET.txt +3 -0
- data/tracks/scala/docs/SNIPPET.txt +4 -0
- data/tracks/scala/exercises/ocr-numbers/example.scala +17 -11
- data/tracks/scala/exercises/ocr-numbers/src/test/scala/OcrNumbersTest.scala +153 -0
- data/tracks/scala/exercises/pig-latin/example.scala +11 -6
- data/tracks/scala/exercises/pig-latin/src/test/scala/PigLatinTest.scala +80 -10
- data/tracks/scala/testgen/src/main/scala/OcrNumbersTestGenerator.scala +34 -0
- data/tracks/scala/testgen/src/main/scala/PigLatinTestGenerator.scala +16 -0
- data/tracks/scheme/docs/SNIPPET.txt +7 -0
- data/tracks/sml/bin/generate +277 -0
- data/tracks/sml/config.json +30 -0
- data/tracks/sml/docs/ABOUT.md +32 -0
- data/tracks/sml/docs/LEARNING.md +37 -0
- data/tracks/sml/docs/SNIPPET.txt +3 -0
- data/tracks/sml/exercises/bob/README.md +48 -0
- data/tracks/sml/exercises/bob/bob.sml +2 -0
- data/tracks/sml/exercises/bob/example.sml +22 -0
- data/tracks/sml/exercises/bob/test.sml +87 -0
- data/tracks/sml/exercises/bob/testlib.sml +159 -0
- data/tracks/sml/exercises/difference-of-squares/README.md +49 -0
- data/tracks/sml/exercises/difference-of-squares/difference-of-squares.sml +8 -0
- data/tracks/sml/exercises/difference-of-squares/example.sml +11 -0
- data/tracks/sml/exercises/difference-of-squares/test.sml +45 -0
- data/tracks/sml/exercises/difference-of-squares/testlib.sml +159 -0
- data/tracks/sml/exercises/hello-world/README.md +51 -0
- data/tracks/sml/exercises/hello-world/example.sml +1 -0
- data/tracks/sml/exercises/hello-world/hello-world.sml +2 -0
- data/tracks/sml/exercises/hello-world/test.sml +15 -0
- data/tracks/sml/exercises/hello-world/testlib.sml +159 -0
- data/tracks/sml/lib/testlib.sml +159 -0
- data/tracks/swift/docs/SNIPPET.txt +9 -0
- data/tracks/typescript/docs/SNIPPET.txt +8 -0
- metadata +53 -6
- data/tracks/csharp/generators/Generators.csproj.user +0 -6
- data/tracks/kotlin/exercises/change/src/example/kotlin/Change.kt +0 -70
- data/tracks/kotlin/exercises/change/src/test/kotlin/ChangeTest.kt +0 -55
- data/tracks/scala/exercises/ocr-numbers/src/test/scala/OcrTest.scala +0 -138
@@ -1,70 +0,0 @@
|
|
1
|
-
class Change(private val coins: Set<Int>) {
|
2
|
-
|
3
|
-
private val NO_COINS_INDICATOR = listOf(-1)
|
4
|
-
|
5
|
-
private val coinsSortedAscending = coins.sorted()
|
6
|
-
|
7
|
-
val RESULTS_CACHE = mutableMapOf<Pair<Int, Int>, List<Int>>()
|
8
|
-
|
9
|
-
fun issue(target: Int): List<Int> {
|
10
|
-
require(target >= 0)
|
11
|
-
|
12
|
-
if(0 == target) {
|
13
|
-
return listOf()
|
14
|
-
}
|
15
|
-
|
16
|
-
require(target >= coinsSortedAscending.first())
|
17
|
-
|
18
|
-
return issueRec(target, coinsSortedAscending.size-1).sorted()
|
19
|
-
}
|
20
|
-
|
21
|
-
/**
|
22
|
-
* This is a Recursive solution using Top-Down dynamic programming
|
23
|
-
*
|
24
|
-
* It is however a poorman's 'memoized' solution because the memoization
|
25
|
-
* logic is scattered inside the function's body
|
26
|
-
* (a truly memoized solution would have no reference to variables outside the function's body)
|
27
|
-
*
|
28
|
-
* Although memoization can easily be implemented in Kotlin
|
29
|
-
* using Lambdas and Function References, the fact that the calls
|
30
|
-
* in this algorithm are recursive, screws up the simple implementation
|
31
|
-
*
|
32
|
-
*/
|
33
|
-
|
34
|
-
private fun issueRec(target: Int, maxIndex: Int) : List<Int> {
|
35
|
-
if(0 == target) {
|
36
|
-
return listOf()
|
37
|
-
}
|
38
|
-
|
39
|
-
if((target < 0) || (maxIndex < 0)) {
|
40
|
-
return NO_COINS_INDICATOR
|
41
|
-
}
|
42
|
-
|
43
|
-
val trimRightCoinResult = fromCacheOrCalculate(target, maxIndex-1)
|
44
|
-
val largestCoinOfPass = coinsSortedAscending[maxIndex]
|
45
|
-
val usingDiffResult = fromCacheOrCalculate(target- largestCoinOfPass, maxIndex)
|
46
|
-
|
47
|
-
if(usingDiffResult.isNoCoinsResult()) {
|
48
|
-
return trimRightCoinResult.safeResult()
|
49
|
-
}
|
50
|
-
else {
|
51
|
-
val usingDiffResultWithLargestCoin = usingDiffResult + largestCoinOfPass
|
52
|
-
if(trimRightCoinResult.isNoCoinsResult()) {
|
53
|
-
return usingDiffResultWithLargestCoin
|
54
|
-
}
|
55
|
-
else {
|
56
|
-
return if(usingDiffResultWithLargestCoin.size < trimRightCoinResult.size) usingDiffResultWithLargestCoin else trimRightCoinResult
|
57
|
-
}
|
58
|
-
}
|
59
|
-
|
60
|
-
}
|
61
|
-
|
62
|
-
private fun fromCacheOrCalculate(target: Int, maxIndex: Int) : List<Int> = RESULTS_CACHE.getOrPut(Pair(target, maxIndex)) {
|
63
|
-
issueRec(target, maxIndex)
|
64
|
-
}
|
65
|
-
|
66
|
-
private fun List<Int>.isNoCoinsResult() = (this == NO_COINS_INDICATOR)
|
67
|
-
|
68
|
-
private fun List<Int>.safeResult() = if(this.isNoCoinsResult()) listOf() else this
|
69
|
-
|
70
|
-
}
|
@@ -1,55 +0,0 @@
|
|
1
|
-
|
2
|
-
import org.assertj.core.api.Assertions.assertThat
|
3
|
-
import org.junit.Test
|
4
|
-
import org.junit.Ignore
|
5
|
-
|
6
|
-
class ChangeTest {
|
7
|
-
|
8
|
-
|
9
|
-
@Test
|
10
|
-
fun singleCoinChange() {
|
11
|
-
assertThat(Change(setOf(1, 5, 10, 25, 100)).issue(25)).containsExactly(25)
|
12
|
-
}
|
13
|
-
|
14
|
-
@Ignore
|
15
|
-
@Test
|
16
|
-
fun multipleCoinChange() {
|
17
|
-
assertThat(Change(setOf(1, 5, 10, 25, 100)).issue(15)).containsExactly(5, 10)
|
18
|
-
}
|
19
|
-
|
20
|
-
@Ignore
|
21
|
-
@Test
|
22
|
-
fun changeWithLilliputianCoins() {
|
23
|
-
assertThat(Change(setOf(1, 4, 15, 20, 50)).issue(23)).containsExactly(4, 4, 15)
|
24
|
-
}
|
25
|
-
|
26
|
-
@Ignore
|
27
|
-
@Test
|
28
|
-
fun changeWithLowerElboniaCoins() {
|
29
|
-
assertThat(Change(setOf(1, 5, 10, 21, 25)).issue(63)).containsExactly(21,21,21)
|
30
|
-
}
|
31
|
-
|
32
|
-
@Ignore
|
33
|
-
@Test
|
34
|
-
fun largeTargetValues() {
|
35
|
-
assertThat(Change(setOf(1, 2, 5, 10, 20, 50, 100)).issue(999)).containsExactly(2, 2, 5, 20, 20, 50, 100, 100, 100, 100, 100, 100, 100, 100, 100)
|
36
|
-
}
|
37
|
-
|
38
|
-
@Ignore
|
39
|
-
@Test
|
40
|
-
fun noCoinsMake0Change() {
|
41
|
-
assertThat(Change(setOf(1, 5, 10, 21, 25)).issue(0)).isEmpty()
|
42
|
-
}
|
43
|
-
|
44
|
-
@Ignore
|
45
|
-
@Test(expected = IllegalArgumentException::class)
|
46
|
-
fun errorTestingForChangeSmallerThanTheSmallestCoin() {
|
47
|
-
Change(setOf(5, 10)).issue(3)
|
48
|
-
}
|
49
|
-
|
50
|
-
@Ignore
|
51
|
-
@Test(expected = IllegalArgumentException::class)
|
52
|
-
fun cannotFindNegativeChangeValues() {
|
53
|
-
Change(setOf(1, 2, 5)).issue(-5)
|
54
|
-
}
|
55
|
-
}
|
@@ -1,138 +0,0 @@
|
|
1
|
-
import org.scalatest.{Matchers, FlatSpec}
|
2
|
-
|
3
|
-
class OcrTest extends FlatSpec with Matchers {
|
4
|
-
it should "recognize zero" in {
|
5
|
-
Ocr(List(" _ "
|
6
|
-
, "| |"
|
7
|
-
, "|_|"
|
8
|
-
, " ").mkString("\n")).convert should be ("0")
|
9
|
-
}
|
10
|
-
|
11
|
-
it should "recognize one" in {
|
12
|
-
pending
|
13
|
-
Ocr(List(" "
|
14
|
-
, " |"
|
15
|
-
, " |"
|
16
|
-
, " ").mkString("\n")).convert should be ("1")
|
17
|
-
}
|
18
|
-
|
19
|
-
it should "recognize two" in {
|
20
|
-
pending
|
21
|
-
Ocr(List(" _ "
|
22
|
-
, " _|"
|
23
|
-
, "|_ "
|
24
|
-
, " ").mkString("\n")).convert should be ("2")
|
25
|
-
}
|
26
|
-
|
27
|
-
it should "recognize three" in {
|
28
|
-
pending
|
29
|
-
Ocr(List(" _ "
|
30
|
-
, " _|"
|
31
|
-
, " _|"
|
32
|
-
, " ").mkString("\n")).convert should be ("3")
|
33
|
-
}
|
34
|
-
|
35
|
-
it should "recognize four" in {
|
36
|
-
pending
|
37
|
-
Ocr(List(" "
|
38
|
-
, "|_|"
|
39
|
-
, " |"
|
40
|
-
, " ").mkString("\n")).convert should be ("4")
|
41
|
-
}
|
42
|
-
|
43
|
-
it should "recognize five" in {
|
44
|
-
pending
|
45
|
-
Ocr(List(" _ "
|
46
|
-
, "|_ "
|
47
|
-
, " _|"
|
48
|
-
, " ").mkString("\n")).convert should be ("5")
|
49
|
-
}
|
50
|
-
|
51
|
-
it should "recognize six" in {
|
52
|
-
pending
|
53
|
-
Ocr(List(" _ "
|
54
|
-
, "|_ "
|
55
|
-
, "|_|"
|
56
|
-
, " ").mkString("\n")).convert should be ("6")
|
57
|
-
}
|
58
|
-
|
59
|
-
it should "recognize seven" in {
|
60
|
-
pending
|
61
|
-
Ocr(List(" _ "
|
62
|
-
, " |"
|
63
|
-
, " |"
|
64
|
-
, " ").mkString("\n")).convert should be ("7")
|
65
|
-
}
|
66
|
-
|
67
|
-
it should "recognize eight" in {
|
68
|
-
pending
|
69
|
-
Ocr(List(" _ "
|
70
|
-
, "|_|"
|
71
|
-
, "|_|"
|
72
|
-
, " ").mkString("\n")).convert should be ("8")
|
73
|
-
}
|
74
|
-
|
75
|
-
it should "recognize nine" in {
|
76
|
-
pending
|
77
|
-
Ocr(List(" _ "
|
78
|
-
, "|_|"
|
79
|
-
, " _|"
|
80
|
-
, " ").mkString("\n")).convert should be ("9")
|
81
|
-
}
|
82
|
-
|
83
|
-
it should "recognize garble" in {
|
84
|
-
pending
|
85
|
-
Ocr(List(" "
|
86
|
-
, "| |"
|
87
|
-
, "| |"
|
88
|
-
, " ").mkString("\n")).convert should be ("?")
|
89
|
-
}
|
90
|
-
|
91
|
-
it should "recognize ten" in {
|
92
|
-
pending
|
93
|
-
Ocr(List(" _ "
|
94
|
-
, " || |"
|
95
|
-
, " ||_|"
|
96
|
-
, " ").mkString("\n")).convert should be ("10")
|
97
|
-
}
|
98
|
-
|
99
|
-
it should "recognize 110101100" in {
|
100
|
-
pending
|
101
|
-
Ocr(List(" _ _ _ _ "
|
102
|
-
, " | || | || | | || || |"
|
103
|
-
, " | ||_| ||_| | ||_||_|"
|
104
|
-
, " ").mkString("\n")).convert should be ("110101100")
|
105
|
-
}
|
106
|
-
|
107
|
-
it should "recognize garbled multi digit ocr" in {
|
108
|
-
pending
|
109
|
-
Ocr(List(" _ _ _ "
|
110
|
-
, " | || | || | || || |"
|
111
|
-
, " | | _| ||_| | ||_||_|"
|
112
|
-
, " ").mkString("\n")).convert should be ("11?10?1?0")
|
113
|
-
}
|
114
|
-
|
115
|
-
it should "recognize 1234567890" in {
|
116
|
-
pending
|
117
|
-
Ocr(List(" _ _ _ _ _ _ _ _ "
|
118
|
-
, " | _| _||_||_ |_ ||_||_|| |"
|
119
|
-
, " ||_ _| | _||_| ||_| _||_|"
|
120
|
-
, " ").mkString("\n")).convert should be ("1234567890")
|
121
|
-
}
|
122
|
-
|
123
|
-
it should "recognize 123,456,789" in {
|
124
|
-
pending
|
125
|
-
Ocr(List(" _ _ "
|
126
|
-
, " | _| _|"
|
127
|
-
, " ||_ _|"
|
128
|
-
, " "
|
129
|
-
, " _ _ "
|
130
|
-
, "|_||_ |_ "
|
131
|
-
, " | _||_|"
|
132
|
-
, " "
|
133
|
-
, " _ _ _ "
|
134
|
-
, " ||_||_|"
|
135
|
-
, " ||_| _|"
|
136
|
-
, " ").mkString("\n")).convert should be ("123,456,789")
|
137
|
-
}
|
138
|
-
}
|