trackler 2.0.7.0 → 2.0.8.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/common/exercises/counter/metadata.yml +0 -4
- data/common/exercises/error-handling/metadata.yml +0 -4
- data/common/exercises/etl/canonical-data.json +1 -1
- data/common/exercises/hello-world/canonical-data.json +9 -21
- data/common/exercises/hello-world/description.md +7 -42
- data/common/exercises/hello-world/metadata.yml +1 -1
- data/common/exercises/lens-person/metadata.yml +0 -3
- data/common/exercises/luhn/canonical-data.json +17 -17
- data/common/exercises/nucleotide-codons/metadata.yml +0 -2
- data/common/exercises/react/metadata.yml +0 -2
- data/common/exercises/rectangles/metadata.yml +0 -3
- data/common/exercises/variable-length-quantity/metadata.yml +0 -2
- data/fixtures/tracks/snowflake/config.json +17 -0
- data/fixtures/tracks/snowflake/exercises/snowflake-only/description.md +1 -0
- data/fixtures/tracks/snowflake/exercises/snowflake-only/metadata.yml +4 -0
- data/lib/trackler/description.rb +27 -0
- data/lib/trackler/guaranteed_file.rb +77 -0
- data/lib/trackler/implementations.rb +5 -5
- data/lib/trackler/metadata.rb +27 -0
- data/lib/trackler/null_track.rb +22 -0
- data/lib/trackler/problem.rb +32 -34
- data/lib/trackler/track.rb +1 -1
- data/lib/trackler/version.rb +1 -1
- data/tracks/csharp/exercises/hello-world/Example.cs +2 -5
- data/tracks/csharp/exercises/hello-world/HelloWorldTest.cs +2 -16
- data/tracks/elixir/config.json +7 -0
- data/tracks/elixir/exercises/series/example.exs +13 -0
- data/tracks/elixir/exercises/series/series.exs +11 -0
- data/tracks/elixir/exercises/series/series_test.exs +53 -0
- data/tracks/erlang/README.md +3 -3
- data/tracks/erlang/config.json +15 -11
- data/tracks/erlang/exercises/{binary → all-your-base}/include/exercism.hrl +0 -0
- data/tracks/erlang/exercises/{binary → all-your-base}/rebar.config +0 -0
- data/tracks/erlang/exercises/{trinary/src/trinary.app.src → all-your-base/src/all_your_base.app.src} +2 -2
- data/tracks/erlang/exercises/all-your-base/src/example.erl +33 -0
- data/tracks/erlang/exercises/all-your-base/test/all_your_base_tests.erl +69 -0
- data/tracks/erlang/exercises/hello-world/src/example.erl +4 -4
- data/tracks/erlang/exercises/hello-world/test/hello_world_tests.erl +3 -12
- data/tracks/erlang/exercises/{trinary → rotational-cipher}/include/exercism.hrl +0 -0
- data/tracks/erlang/exercises/{trinary → rotational-cipher}/rebar.config +8 -1
- data/tracks/erlang/exercises/rotational-cipher/src/example.erl +19 -0
- data/tracks/erlang/exercises/{binary/src/binary.app.src → rotational-cipher/src/rotational_cipher.app.src} +2 -2
- data/tracks/erlang/exercises/rotational-cipher/test/rotational_cipher_tests.erl +98 -0
- data/tracks/fsharp/exercises/grep/GrepTest.fs +57 -0
- data/tracks/fsharp/exercises/hello-world/Example.fs +1 -1
- data/tracks/fsharp/exercises/hello-world/HelloWorldTest.fs +2 -12
- data/tracks/go/.travis.yml +7 -15
- data/tracks/go/exercises/hello-world/example.go +4 -8
- data/tracks/go/exercises/hello-world/hello_test.go +20 -16
- data/tracks/go/exercises/hello-world/hello_world.go +12 -2
- data/tracks/groovy/exercises/hello-world/Example.groovy +2 -2
- data/tracks/groovy/exercises/hello-world/HelloWorld.groovy +1 -1
- data/tracks/groovy/exercises/hello-world/HelloWorldSpec.groovy +1 -14
- data/tracks/haskell/config.json +6 -0
- data/tracks/haskell/exercises/hello-world/HINTS.md +6 -0
- data/tracks/haskell/exercises/hello-world/examples/success-standard/package.yaml +16 -0
- data/tracks/haskell/exercises/hello-world/examples/success-standard/src/HelloWorld.hs +4 -0
- data/tracks/haskell/exercises/hello-world/package.yaml +19 -0
- data/tracks/haskell/exercises/hello-world/src/HelloWorld.hs +4 -0
- data/tracks/haskell/exercises/hello-world/stack.yaml +1 -0
- data/tracks/haskell/exercises/hello-world/test/Tests.hs +13 -0
- data/tracks/idris/config.json +9 -0
- data/tracks/idris/exercises/leap/Leap.ipkg +5 -0
- data/tracks/idris/exercises/leap/Makefile +23 -0
- data/tracks/idris/exercises/leap/src/Leap.idr +5 -0
- data/tracks/idris/exercises/leap/src/Test/Leap.idr +37 -0
- data/tracks/idris/exercises/leap/src/example.idr +8 -0
- data/tracks/{typescript/exercises → java}/.keep +0 -0
- data/tracks/java/config.json +115 -172
- data/tracks/java/exercises/anagram/src/test/java/AnagramTest.java +41 -13
- data/tracks/java/exercises/list-ops/build.gradle +18 -0
- data/tracks/java/exercises/list-ops/src/example/java/ListOps.java +51 -0
- data/tracks/java/exercises/list-ops/src/main/java/.keep +0 -0
- data/tracks/java/exercises/list-ops/src/test/java/ListOpsTest.java +316 -0
- data/tracks/java/exercises/palindrome-products/src/example/java/Palindromes.java +28 -62
- data/tracks/java/exercises/palindrome-products/src/test/java/PalindromesTest.java +26 -83
- data/tracks/java/exercises/settings.gradle +1 -0
- data/tracks/julia/config.json +1 -2
- data/tracks/julia/exercises/hello-world/example.jl +2 -2
- data/tracks/julia/exercises/hello-world/runtests.jl +1 -6
- data/tracks/lua/exercises/TRACK_HINTS.md +8 -0
- data/tracks/lua/exercises/hello-world/example.lua +2 -3
- data/tracks/lua/exercises/hello-world/hello-world.lua +18 -0
- data/tracks/lua/exercises/hello-world/hello-world_spec.lua +6 -12
- data/tracks/ocaml/exercises/phone-number/example.ml +8 -18
- data/tracks/ocaml/exercises/phone-number/phone_number.mli +1 -7
- data/tracks/ocaml/exercises/phone-number/test.ml +24 -23
- data/tracks/ocaml/tools/test-generator/src/special_cases.ml +6 -0
- data/tracks/ocaml/tools/test-generator/templates/phone-number/template.ml +21 -0
- data/tracks/pony/config.json +2 -2
- data/tracks/pony/exercises/hello-world/example.pony +1 -2
- data/tracks/pony/exercises/hello-world/test.pony +0 -1
- data/tracks/rust/config.json +0 -1
- data/tracks/rust/exercises/hello-world/example.rs +2 -5
- data/tracks/rust/exercises/hello-world/tests/hello-world.rs +2 -14
- data/tracks/scala/config.json +11 -2
- data/tracks/scala/docs/LEARNING.md +10 -2
- data/tracks/scala/docs/RESOURCES.md +0 -1
- data/tracks/scala/docs/TESTS.md +10 -6
- data/tracks/scala/exercises/rail-fence-cipher/build.sbt +3 -0
- data/tracks/scala/exercises/rail-fence-cipher/example.scala +46 -0
- data/tracks/scala/exercises/rail-fence-cipher/src/main/scala/RailFenceCipher.scala +0 -0
- data/tracks/scala/exercises/rail-fence-cipher/src/test/scala/RailFenceCipherTest.scala +42 -0
- data/tracks/scala/testgen/src/main/scala/RailFenceCipherTestGenerator.scala +59 -0
- data/tracks/typescript/.gitignore +7 -0
- data/tracks/typescript/.travis.yml +18 -1
- data/tracks/typescript/Dangerfile +43 -0
- data/tracks/typescript/Makefile +57 -0
- data/tracks/typescript/README.md +38 -5
- data/tracks/typescript/SETUP.md +24 -0
- data/tracks/typescript/common/package.json +37 -0
- data/tracks/typescript/common/tsconfig.json +21 -0
- data/tracks/typescript/common/tslint.json +127 -0
- data/tracks/typescript/common/yarn.lock +2697 -0
- data/tracks/typescript/config.json +82 -2
- data/tracks/typescript/docs/ABOUT.md +1 -0
- data/tracks/typescript/docs/INSTALLATION.md +17 -0
- data/tracks/typescript/docs/LEARNING.md +8 -0
- data/tracks/typescript/docs/RESOURCES.md +7 -0
- data/tracks/typescript/docs/TESTS.md +36 -0
- data/tracks/typescript/exercises/anagram/anagram.example.ts +23 -0
- data/tracks/typescript/exercises/anagram/anagram.test.ts +82 -0
- data/tracks/typescript/exercises/anagram/package.json +37 -0
- data/tracks/typescript/exercises/anagram/tsconfig.json +21 -0
- data/tracks/typescript/exercises/anagram/tslint.json +127 -0
- data/tracks/typescript/exercises/anagram/yarn.lock +2697 -0
- data/tracks/typescript/exercises/beer-song/beer-song.example.ts +36 -0
- data/tracks/typescript/exercises/beer-song/beer-song.test.ts +360 -0
- data/tracks/typescript/exercises/beer-song/package.json +37 -0
- data/tracks/typescript/exercises/beer-song/tsconfig.json +21 -0
- data/tracks/typescript/exercises/beer-song/tslint.json +127 -0
- data/tracks/typescript/exercises/beer-song/yarn.lock +2697 -0
- data/tracks/typescript/exercises/bob/bob.example.ts +24 -0
- data/tracks/typescript/exercises/bob/bob.test.ts +92 -0
- data/tracks/typescript/exercises/bob/package.json +37 -0
- data/tracks/typescript/exercises/bob/tsconfig.json +21 -0
- data/tracks/typescript/exercises/bob/tslint.json +127 -0
- data/tracks/typescript/exercises/bob/yarn.lock +2697 -0
- data/tracks/typescript/exercises/gigasecond/gigasecond.example.ts +11 -0
- data/tracks/typescript/exercises/gigasecond/gigasecond.test.ts +29 -0
- data/tracks/typescript/exercises/gigasecond/package.json +37 -0
- data/tracks/typescript/exercises/gigasecond/tsconfig.json +21 -0
- data/tracks/typescript/exercises/gigasecond/tslint.json +127 -0
- data/tracks/typescript/exercises/gigasecond/yarn.lock +2697 -0
- data/tracks/typescript/exercises/hamming/hamming.example.ts +19 -0
- data/tracks/typescript/exercises/hamming/hamming.test.ts +39 -0
- data/tracks/typescript/exercises/hamming/package.json +37 -0
- data/tracks/typescript/exercises/hamming/tsconfig.json +21 -0
- data/tracks/typescript/exercises/hamming/tslint.json +127 -0
- data/tracks/typescript/exercises/hamming/yarn.lock +2697 -0
- data/tracks/typescript/exercises/hello-world/hello-world.example.ts +8 -0
- data/tracks/typescript/exercises/hello-world/hello-world.test.ts +17 -0
- data/tracks/typescript/exercises/hello-world/package.json +37 -0
- data/tracks/typescript/exercises/hello-world/tsconfig.json +21 -0
- data/tracks/typescript/exercises/hello-world/tslint.json +127 -0
- data/tracks/typescript/exercises/hello-world/yarn.lock +2697 -0
- data/tracks/typescript/exercises/leap/leap.example.ts +6 -0
- data/tracks/typescript/exercises/leap/leap.test.ts +39 -0
- data/tracks/typescript/exercises/leap/package.json +37 -0
- data/tracks/typescript/exercises/leap/tsconfig.json +21 -0
- data/tracks/typescript/exercises/leap/tslint.json +127 -0
- data/tracks/typescript/exercises/leap/yarn.lock +2697 -0
- data/tracks/typescript/exercises/pangram/package.json +37 -0
- data/tracks/typescript/exercises/pangram/pangram.example.ts +32 -0
- data/tracks/typescript/exercises/pangram/pangram.test.ts +50 -0
- data/tracks/typescript/exercises/pangram/tsconfig.json +21 -0
- data/tracks/typescript/exercises/pangram/tslint.json +127 -0
- data/tracks/typescript/exercises/pangram/yarn.lock +2697 -0
- data/tracks/typescript/exercises/phone-number/package.json +37 -0
- data/tracks/typescript/exercises/phone-number/phone-number.example.ts +21 -0
- data/tracks/typescript/exercises/phone-number/phone-number.test.ts +55 -0
- data/tracks/typescript/exercises/phone-number/tsconfig.json +21 -0
- data/tracks/typescript/exercises/phone-number/tslint.json +127 -0
- data/tracks/typescript/exercises/phone-number/yarn.lock +2697 -0
- data/tracks/typescript/exercises/rna-transcription/package.json +37 -0
- data/tracks/typescript/exercises/rna-transcription/rna-transcription.example.ts +13 -0
- data/tracks/typescript/exercises/rna-transcription/rna-transcription.test.ts +45 -0
- data/tracks/typescript/exercises/rna-transcription/tsconfig.json +21 -0
- data/tracks/typescript/exercises/rna-transcription/tslint.json +127 -0
- data/tracks/typescript/exercises/rna-transcription/yarn.lock +2697 -0
- data/tracks/typescript/exercises/say/package.json +37 -0
- data/tracks/typescript/exercises/say/say.example.ts +95 -0
- data/tracks/typescript/exercises/say/say.test.ts +78 -0
- data/tracks/typescript/exercises/say/tsconfig.json +21 -0
- data/tracks/typescript/exercises/say/tslint.json +127 -0
- data/tracks/typescript/exercises/say/yarn.lock +2697 -0
- data/tracks/typescript/exercises/word-count/package.json +37 -0
- data/tracks/typescript/exercises/word-count/tsconfig.json +21 -0
- data/tracks/typescript/exercises/word-count/tslint.json +127 -0
- data/tracks/typescript/exercises/word-count/word-count.example.ts +16 -0
- data/tracks/typescript/exercises/word-count/word-count.test.ts +65 -0
- data/tracks/typescript/exercises/word-count/yarn.lock +2697 -0
- data/tracks/typescript/exercises/wordy/package.json +37 -0
- data/tracks/typescript/exercises/wordy/tsconfig.json +21 -0
- data/tracks/typescript/exercises/wordy/tslint.json +127 -0
- data/tracks/typescript/exercises/wordy/wordy.example.ts +40 -0
- data/tracks/typescript/exercises/wordy/wordy.test.ts +89 -0
- data/tracks/typescript/exercises/wordy/yarn.lock +2697 -0
- data/tracks/typescript/img/icon.png +0 -0
- data/tracks/typescript/img/icon.svg +10 -0
- metadata +134 -15
- data/tracks/erlang/exercises/binary/src/example.erl +0 -20
- data/tracks/erlang/exercises/binary/test/binary_string_tests.erl +0 -26
- data/tracks/erlang/exercises/trinary/Makefile +0 -10
- data/tracks/erlang/exercises/trinary/src/example.erl +0 -66
- data/tracks/erlang/exercises/trinary/test/trinary_tests.erl +0 -36
- data/tracks/fsharp/exercises/hello-world/HINTS.md +0 -5
@@ -1,77 +1,43 @@
|
|
1
|
-
|
2
|
-
import java.util.ArrayList;
|
3
|
-
import java.util.Arrays;
|
4
|
-
import java.util.Collections;
|
5
|
-
import java.util.List;
|
6
|
-
import java.util.SortedMap;
|
7
|
-
import java.util.TreeMap;
|
1
|
+
import java.util.*;
|
8
2
|
|
9
3
|
public class Palindromes {
|
10
4
|
|
11
|
-
public static
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
return this;
|
23
|
-
}
|
24
|
-
|
25
|
-
public PalindromeSortedSetBuilder withFactorsGreaterThanOrEqualTo(
|
26
|
-
final int minFactor) {
|
27
|
-
this.minFactor = minFactor;
|
28
|
-
return this;
|
29
|
-
}
|
30
|
-
|
31
|
-
public SortedMap<Long, List<List<Integer>>> build() {
|
32
|
-
SortedMap<Long, List<List<Integer>>> palindromes = new TreeMap<>();
|
33
|
-
long num;
|
34
|
-
List<List<Integer>> factors;
|
35
|
-
for (int i = this.maxFactor; i >= this.minFactor; i--) {
|
36
|
-
for (int j = this.maxFactor; j >= i; j--) {
|
37
|
-
num = i * j;
|
38
|
-
if (isPalindrome(num)) {
|
39
|
-
factors = palindromes.get(num);
|
40
|
-
if (factors == null) {
|
41
|
-
factors = new ArrayList<>();
|
42
|
-
}
|
43
|
-
factors.add(Arrays.asList(i, j));
|
44
|
-
palindromes.put(num, factors);
|
5
|
+
public static SortedMap<Long, List<List<Integer>>> getPalindromeProductsWithFactors(int minFactor, int maxFactor) {
|
6
|
+
SortedMap<Long, List<List<Integer>>> palindromeSortedList = new TreeMap<>();
|
7
|
+
long num;
|
8
|
+
List<List<Integer>> factors;
|
9
|
+
for (int i = maxFactor; i >= minFactor; i--) {
|
10
|
+
for (int j = maxFactor; j >= i; j--) {
|
11
|
+
num = i * j;
|
12
|
+
if (isPalindrome(num)) {
|
13
|
+
factors = palindromeSortedList.get(num);
|
14
|
+
if (factors == null) {
|
15
|
+
factors = new ArrayList<>();
|
45
16
|
}
|
17
|
+
factors.add(Arrays.asList(i, j));
|
18
|
+
palindromeSortedList.put(num, factors);
|
46
19
|
}
|
47
20
|
}
|
48
|
-
return Collections.unmodifiableSortedMap(palindromes);
|
49
21
|
}
|
22
|
+
return Collections.unmodifiableSortedMap(palindromeSortedList);
|
23
|
+
}
|
50
24
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
}
|
56
|
-
long result = 0;
|
57
|
-
long tmp = number;
|
58
|
-
while (tmp > 0) {
|
59
|
-
result = result * 10 + (tmp % 10);
|
60
|
-
tmp /= 10;
|
61
|
-
|
62
|
-
}
|
63
|
-
return result;
|
25
|
+
// http://stackoverflow.com/questions/23984654/how-to-print-all-palindromes-upto-1000-without-using-any-string-stringbuilder
|
26
|
+
private static long reverseNumber(long number) {
|
27
|
+
if (number < 10l) {
|
28
|
+
return number;
|
64
29
|
}
|
30
|
+
long result = 0;
|
31
|
+
long tmp = number;
|
32
|
+
while (tmp > 0) {
|
33
|
+
result = result * 10 + (tmp % 10);
|
34
|
+
tmp /= 10;
|
65
35
|
|
66
|
-
private boolean isPalindrome(long number) {
|
67
|
-
return number == reverseNumber(number);
|
68
36
|
}
|
37
|
+
return result;
|
69
38
|
}
|
70
39
|
|
71
|
-
private
|
72
|
-
|
73
|
-
|
74
|
-
public static PalindromeSortedSetBuilder getPalindromeSortedListBuilder() {
|
75
|
-
return new PalindromeSortedSetBuilder();
|
40
|
+
private static boolean isPalindrome(long number) {
|
41
|
+
return number == reverseNumber(number);
|
76
42
|
}
|
77
43
|
}
|
@@ -1,14 +1,13 @@
|
|
1
|
+
import org.junit.Ignore;
|
2
|
+
import org.junit.Test;
|
1
3
|
|
2
4
|
import java.util.Arrays;
|
3
5
|
import java.util.Collections;
|
4
6
|
import java.util.List;
|
5
7
|
import java.util.SortedMap;
|
6
8
|
import java.util.stream.Collectors;
|
7
|
-
|
8
|
-
import static junit.framework.TestCase
|
9
|
-
import static junit.framework.TestCase.assertNotNull;
|
10
|
-
import org.junit.Ignore;
|
11
|
-
import org.junit.Test;
|
9
|
+
|
10
|
+
import static junit.framework.TestCase.*;
|
12
11
|
|
13
12
|
public class PalindromesTest {
|
14
13
|
|
@@ -22,22 +21,9 @@ public class PalindromesTest {
|
|
22
21
|
);
|
23
22
|
final long expectedValue = 9l;
|
24
23
|
|
25
|
-
final SortedMap<Long, List<List<Integer>>> palindromes
|
26
|
-
= Palindromes.getPalindromeSortedListBuilder()
|
27
|
-
.withFactorsLessThanOrEqualTo(9).build();
|
28
|
-
|
29
|
-
assertNotNull(palindromes);
|
30
|
-
assertFalse(palindromes.isEmpty());
|
31
|
-
|
32
|
-
long actualValue = palindromes.lastKey();
|
33
|
-
assertEquals(expectedValue, actualValue);
|
24
|
+
final SortedMap<Long, List<List<Integer>>> palindromes = Palindromes.getPalindromeProductsWithFactors(1, 9);
|
34
25
|
|
35
|
-
|
36
|
-
.get(palindromes.lastKey())
|
37
|
-
.stream()
|
38
|
-
.sorted((a, b) -> Integer.compare(a.get(0), b.get(0)))
|
39
|
-
.collect(Collectors.toList());
|
40
|
-
assertEquals(expected, actual);
|
26
|
+
checkPalindromeWithFactorsMatchesExpected(expected, expectedValue, palindromes, palindromes.lastKey());
|
41
27
|
}
|
42
28
|
|
43
29
|
@Test
|
@@ -50,24 +36,9 @@ public class PalindromesTest {
|
|
50
36
|
);
|
51
37
|
final long expectedValue = 9009l;
|
52
38
|
|
53
|
-
final SortedMap<Long, List<List<Integer>>> palindromes
|
54
|
-
= Palindromes.getPalindromeSortedListBuilder()
|
55
|
-
.withFactorsLessThanOrEqualTo(99)
|
56
|
-
.withFactorsGreaterThanOrEqualTo(10)
|
57
|
-
.build();
|
58
|
-
|
59
|
-
assertNotNull(palindromes);
|
60
|
-
assertFalse(palindromes.isEmpty());
|
39
|
+
final SortedMap<Long, List<List<Integer>>> palindromes = Palindromes.getPalindromeProductsWithFactors(10, 99);
|
61
40
|
|
62
|
-
|
63
|
-
assertEquals(expectedValue, actualValue);
|
64
|
-
|
65
|
-
List<List<Integer>> actual = palindromes
|
66
|
-
.get(palindromes.lastKey())
|
67
|
-
.stream()
|
68
|
-
.sorted((a, b) -> Integer.compare(a.get(0), b.get(0)))
|
69
|
-
.collect(Collectors.toList());
|
70
|
-
assertEquals(expected, actual);
|
41
|
+
checkPalindromeWithFactorsMatchesExpected(expected, expectedValue, palindromes, palindromes.lastKey());
|
71
42
|
}
|
72
43
|
|
73
44
|
@Test
|
@@ -80,24 +51,9 @@ public class PalindromesTest {
|
|
80
51
|
);
|
81
52
|
final long expectedValue = 121l;
|
82
53
|
|
83
|
-
final SortedMap<Long, List<List<Integer>>> palindromes
|
84
|
-
= Palindromes.getPalindromeSortedListBuilder()
|
85
|
-
.withFactorsLessThanOrEqualTo(99)
|
86
|
-
.withFactorsGreaterThanOrEqualTo(10)
|
87
|
-
.build();
|
88
|
-
|
89
|
-
assertNotNull(palindromes);
|
90
|
-
assertFalse(palindromes.isEmpty());
|
54
|
+
final SortedMap<Long, List<List<Integer>>> palindromes = Palindromes.getPalindromeProductsWithFactors(10, 99);
|
91
55
|
|
92
|
-
|
93
|
-
assertEquals(expectedValue, actualValue);
|
94
|
-
|
95
|
-
List<List<Integer>> actual = palindromes
|
96
|
-
.get(palindromes.firstKey())
|
97
|
-
.stream()
|
98
|
-
.sorted((a, b) -> Integer.compare(a.get(0), b.get(0)))
|
99
|
-
.collect(Collectors.toList());
|
100
|
-
assertEquals(expected, actual);
|
56
|
+
checkPalindromeWithFactorsMatchesExpected(expected, expectedValue, palindromes, palindromes.firstKey());
|
101
57
|
}
|
102
58
|
|
103
59
|
@Test
|
@@ -110,24 +66,9 @@ public class PalindromesTest {
|
|
110
66
|
);
|
111
67
|
final long expectedValue = 906609l;
|
112
68
|
|
113
|
-
final SortedMap<Long, List<List<Integer>>> palindromes
|
114
|
-
= Palindromes.getPalindromeSortedListBuilder()
|
115
|
-
.withFactorsLessThanOrEqualTo(999)
|
116
|
-
.withFactorsGreaterThanOrEqualTo(100)
|
117
|
-
.build();
|
118
|
-
|
119
|
-
assertNotNull(palindromes);
|
120
|
-
assertFalse(palindromes.isEmpty());
|
69
|
+
final SortedMap<Long, List<List<Integer>>> palindromes = Palindromes.getPalindromeProductsWithFactors(100, 999);
|
121
70
|
|
122
|
-
|
123
|
-
assertEquals(expectedValue, actualValue);
|
124
|
-
|
125
|
-
List<List<Integer>> actual = palindromes
|
126
|
-
.get(palindromes.lastKey())
|
127
|
-
.stream()
|
128
|
-
.sorted((a, b) -> Integer.compare(a.get(0), b.get(0)))
|
129
|
-
.collect(Collectors.toList());
|
130
|
-
assertEquals(expected, actual);
|
71
|
+
checkPalindromeWithFactorsMatchesExpected(expected, expectedValue, palindromes, palindromes.lastKey());
|
131
72
|
}
|
132
73
|
|
133
74
|
@Test
|
@@ -140,23 +81,25 @@ public class PalindromesTest {
|
|
140
81
|
);
|
141
82
|
final long expectedValue = 10201l;
|
142
83
|
|
143
|
-
final SortedMap<Long, List<List<Integer>>> palindromes
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
.build();
|
84
|
+
final SortedMap<Long, List<List<Integer>>> palindromes = Palindromes.getPalindromeProductsWithFactors(100, 999);
|
85
|
+
|
86
|
+
checkPalindromeWithFactorsMatchesExpected(expected, expectedValue, palindromes, palindromes.firstKey());
|
87
|
+
}
|
148
88
|
|
149
|
-
|
150
|
-
|
89
|
+
private void checkPalindromeWithFactorsMatchesExpected(List<List<Integer>> expectedPalindromeFactors,
|
90
|
+
long expectedValueOfPalindrome,
|
91
|
+
SortedMap<Long, List<List<Integer>>> actualPalindromes,
|
92
|
+
long actualValueOfPalindrome) {
|
93
|
+
assertNotNull(actualPalindromes);
|
94
|
+
assertFalse(actualPalindromes.isEmpty());
|
151
95
|
|
152
|
-
|
153
|
-
assertEquals(expectedValue, actualValue);
|
96
|
+
assertEquals(expectedValueOfPalindrome, actualValueOfPalindrome);
|
154
97
|
|
155
|
-
List<List<Integer>>
|
156
|
-
.get(
|
98
|
+
List<List<Integer>> actualPalindromeFactors = actualPalindromes
|
99
|
+
.get(actualValueOfPalindrome)
|
157
100
|
.stream()
|
158
101
|
.sorted((a, b) -> Integer.compare(a.get(0), b.get(0)))
|
159
102
|
.collect(Collectors.toList());
|
160
|
-
assertEquals(
|
103
|
+
assertEquals(expectedPalindromeFactors, actualPalindromeFactors);
|
161
104
|
}
|
162
105
|
}
|
data/tracks/julia/config.json
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
function hello(
|
2
|
-
return "Hello,
|
1
|
+
function hello()
|
2
|
+
return "Hello, World!"
|
3
3
|
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
## Running the tests
|
2
|
+
|
3
|
+
To run the tests, run the command `busted .` from within the exercise directory.
|
4
|
+
|
5
|
+
## Further information
|
6
|
+
|
7
|
+
For more detailed information about the Lua track, including how to get help if
|
8
|
+
you're having trouble, please visit the exercism.io [Lua language page](http://exercism.io/languages/lua/about).
|
@@ -0,0 +1,18 @@
|
|
1
|
+
-- This is a "stub" file. It's a little start on your solution.
|
2
|
+
-- It's not a complete solution though; you have to write some code.
|
3
|
+
|
4
|
+
-- Table to be returned by the hello-world module.
|
5
|
+
local hello_world = {}
|
6
|
+
|
7
|
+
-- Add the hello() function to the table returned by this module.
|
8
|
+
function hello_world.hello()
|
9
|
+
-- Write some code here to pass the test suite.
|
10
|
+
|
11
|
+
-- When you have a working solution, REMOVE ALL THE STOCK COMMENTS.
|
12
|
+
-- They're here to help you get started but they only clutter a finished solution.
|
13
|
+
-- If you leave them in, reviewers will protest!
|
14
|
+
return ''
|
15
|
+
end
|
16
|
+
|
17
|
+
-- Return the hello_world table to make it accessible as a module.
|
18
|
+
return hello_world
|
@@ -1,18 +1,12 @@
|
|
1
|
+
-- Require the hello-world module
|
1
2
|
local hello_world = require('hello-world')
|
2
3
|
|
4
|
+
-- Define a module named hello-world. This module should return a single
|
5
|
+
-- function named hello that takes no arguments and returns a string.
|
6
|
+
|
3
7
|
describe('hello-world', function()
|
4
|
-
it('says hello world
|
8
|
+
it('says hello world', function()
|
5
9
|
local result = hello_world.hello()
|
6
|
-
assert.are.equal('Hello,
|
7
|
-
end)
|
8
|
-
|
9
|
-
it('says hello to Bob', function()
|
10
|
-
local result = hello_world.hello('Bob')
|
11
|
-
assert.are.equal('Hello, Bob!', result)
|
12
|
-
end)
|
13
|
-
|
14
|
-
it('says hello to Sally', function()
|
15
|
-
local result = hello_world.hello('Sally')
|
16
|
-
assert.are.equal('Hello, Sally!', result)
|
10
|
+
assert.are.equal('Hello, World!', result)
|
17
11
|
end)
|
18
12
|
end)
|
@@ -1,21 +1,11 @@
|
|
1
1
|
open Core.Std
|
2
2
|
|
3
3
|
let number s =
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
let area_code s =
|
14
|
-
let open Option in (* >>| for Option *)
|
15
|
-
number s >>| split_number >>| (fun (area, _, _) -> area)
|
16
|
-
|
17
|
-
let pretty s =
|
18
|
-
let open Option in
|
19
|
-
number s
|
20
|
-
>>| split_number
|
21
|
-
>>| fun (area, exch, subscr) -> sprintf "(%s) %s-%s" area exch subscr
|
4
|
+
if not @@ String.is_empty (String.filter ~f:(Char.is_alpha) s)
|
5
|
+
then None
|
6
|
+
else
|
7
|
+
let s = String.filter ~f:(Char.is_digit) s in
|
8
|
+
match String.length s with
|
9
|
+
| 10 -> Some s
|
10
|
+
| 11 when String.get s 0 = '1' -> Some (String.drop_prefix s 1)
|
11
|
+
| _ -> None
|
@@ -1,8 +1,2 @@
|
|
1
1
|
(** Extract the digits from a valid phone number. *)
|
2
|
-
val number : string -> string option
|
3
|
-
|
4
|
-
(** Extract the area code from a valid phone number. *)
|
5
|
-
val area_code : string -> string option
|
6
|
-
|
7
|
-
(** Pretty print a valid phone number. *)
|
8
|
-
val pretty : string -> string option
|
2
|
+
val number : string -> string option
|
@@ -1,5 +1,6 @@
|
|
1
1
|
open Core.Std
|
2
2
|
open OUnit2
|
3
|
+
open Phone_number
|
3
4
|
|
4
5
|
let option_to_string f = function
|
5
6
|
| None -> "None"
|
@@ -8,28 +9,28 @@ let option_to_string f = function
|
|
8
9
|
let ae exp got _test_ctxt =
|
9
10
|
assert_equal ~printer:(option_to_string String.to_string) exp got
|
10
11
|
|
11
|
-
let
|
12
|
-
|
13
|
-
|
14
|
-
"cleans
|
15
|
-
|
16
|
-
"
|
17
|
-
|
18
|
-
"invalid when
|
19
|
-
|
20
|
-
"invalid when
|
21
|
-
|
22
|
-
"
|
23
|
-
|
24
|
-
"
|
25
|
-
|
26
|
-
"
|
27
|
-
|
28
|
-
"
|
29
|
-
|
30
|
-
"
|
31
|
-
|
32
|
-
|
12
|
+
let number_tests = [
|
13
|
+
"cleans the number" >::
|
14
|
+
ae (Some "1234567890") (number "(123) 456-7890");
|
15
|
+
"cleans numbers with dots" >::
|
16
|
+
ae (Some "1234567890") (number "123.456.7890");
|
17
|
+
"cleans numbers with multiple spaces" >::
|
18
|
+
ae (Some "1234567890") (number "123 456 7890 ");
|
19
|
+
"invalid when 9 digits" >::
|
20
|
+
ae None (number "123456789");
|
21
|
+
"invalid when 11 digits" >::
|
22
|
+
ae None (number "21234567890");
|
23
|
+
"valid when 11 digits and starting with 1" >::
|
24
|
+
ae (Some "1234567890") (number "11234567890");
|
25
|
+
"invalid when 12 digits" >::
|
26
|
+
ae None (number "321234567890");
|
27
|
+
"invalid with letters" >::
|
28
|
+
ae None (number "123-abc-7890");
|
29
|
+
"invalid with punctuations" >::
|
30
|
+
ae None (number "123-@:!-7890");
|
31
|
+
"invalid with right number of digits but letters mixed in" >::
|
32
|
+
ae None (number "1a2b3c4d5e6f7g8h9i0j");
|
33
|
+
]
|
33
34
|
|
34
35
|
let () =
|
35
|
-
run_test_tt_main ("phone-number tests" >:::
|
36
|
+
run_test_tt_main ("phone-number tests" >::: number_tests)
|