trackler 2.0.5.4 → 2.0.5.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/trackler/version.rb +1 -1
- data/tracks/csharp/exercises/grep/GrepTest.cs +2 -0
- data/tracks/java/exercises/nucleotide-count/build.gradle +1 -1
- data/tracks/java/exercises/nucleotide-count/src/test/java/NucleotideTest.java +42 -32
- data/tracks/java/exercises/series/build.gradle +0 -1
- data/tracks/java/exercises/simple-linked-list/build.gradle +0 -1
- data/tracks/java/exercises/simple-linked-list/src/test/java/SimpleLinkedListTest.java +18 -16
- data/tracks/javascript/docs/INSTALLATION.md +1 -1
- data/tracks/purescript/config.json +8 -0
- data/tracks/purescript/exercises/acronym/bower.json +17 -0
- data/tracks/purescript/exercises/acronym/examples/src/Acronym.purs +46 -0
- data/tracks/purescript/exercises/acronym/src/Acronym.purs +3 -0
- data/tracks/purescript/exercises/acronym/test/Main.purs +37 -0
- data/tracks/r/exercises/space-age/example.R +11 -2
- data/tracks/r/exercises/space-age/test_space-age.R +9 -25
- data/tracks/rust/config.json +8 -0
- data/tracks/rust/docs/INSTALLATION.md +1 -1
- data/tracks/rust/docs/TESTS.md +3 -10
- data/tracks/rust/exercises/sum-of-multiples/.gitignore +7 -0
- data/tracks/rust/exercises/sum-of-multiples/Cargo.toml +3 -0
- data/tracks/rust/exercises/sum-of-multiples/example.rs +17 -0
- data/tracks/rust/exercises/sum-of-multiples/tests/sum-of-multiples.rs +74 -0
- data/tracks/rust/problems.md +1 -0
- data/tracks/scala/exercises/difference-of-squares/example.scala +1 -5
- data/tracks/scala/exercises/difference-of-squares/src/test/scala/SquaresTest.scala +9 -9
- data/tracks/scala/exercises/robot-name/example.scala +13 -16
- data/tracks/scala/exercises/robot-name/src/test/scala/RobotNameTest.scala +21 -4
- data/tracks/swift/docs/TESTS.md +3 -3
- metadata +10 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8d5432bf225e49f96fd078ad1c2e11e82d291780
|
4
|
+
data.tar.gz: 9ebb6ec88ed0bb64313051385c09b16e3a313f21
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: faf9bf3ac196a3c1f3cd6ee3ba48e31e182eb6176fea567ef641b4e2b941a671f77d6df6433a3393735c450a41a17236ba3d83ff20701db3aaa140963d32b967
|
7
|
+
data.tar.gz: ced5a0f1c865bb6322d2c2efd31720a545f9551630732ee6e5bf2bfc1a7a2660a860eab9ad2804600b7e7795c1eaabc2ad2de55fe3c7e07a618797249e9d5dc4
|
data/lib/trackler/version.rb
CHANGED
@@ -42,6 +42,7 @@ That Shepherd, who first taught the chosen Seed
|
|
42
42
|
[OneTimeSetUp]
|
43
43
|
public void SetUp()
|
44
44
|
{
|
45
|
+
Directory.SetCurrentDirectory(Path.GetTempPath());
|
45
46
|
File.WriteAllText(IliadFileName, IliadContents);
|
46
47
|
File.WriteAllText(MidsummerNightFileName, MidsummerNightContents);
|
47
48
|
File.WriteAllText(ParadiseLostFileName, ParadiseLostContents);
|
@@ -50,6 +51,7 @@ That Shepherd, who first taught the chosen Seed
|
|
50
51
|
[OneTimeTearDown]
|
51
52
|
public void TearDown()
|
52
53
|
{
|
54
|
+
Directory.SetCurrentDirectory(Path.GetTempPath());
|
53
55
|
File.Delete(IliadFileName);
|
54
56
|
File.Delete(MidsummerNightFileName);
|
55
57
|
File.Delete(ParadiseLostFileName);
|
@@ -1,53 +1,59 @@
|
|
1
|
-
import static org.assertj.core.api.Assertions.assertThat;
|
2
|
-
import static org.assertj.core.api.Assertions.entry;
|
3
|
-
|
4
|
-
import org.junit.Test;
|
5
1
|
import org.junit.Ignore;
|
2
|
+
import org.junit.Test;
|
3
|
+
|
4
|
+
import java.util.Map;
|
5
|
+
|
6
|
+
import static org.hamcrest.Matchers.*;
|
7
|
+
import static org.junit.Assert.*;
|
6
8
|
|
7
9
|
public class NucleotideTest {
|
8
10
|
|
9
11
|
@Test
|
10
12
|
public void testEmptyDnaStringHasNoAdenosine() {
|
11
13
|
DNA dna = new DNA("");
|
12
|
-
assertThat(dna.count('A')
|
14
|
+
assertThat(dna.count('A'), is(0));
|
13
15
|
}
|
14
16
|
|
15
17
|
@Ignore
|
16
18
|
@Test
|
17
19
|
public void testEmptyDnaStringHasNoNucleotides() {
|
18
20
|
DNA dna = new DNA("");
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
21
|
+
Map<Character, Integer> counts = dna.nucleotideCounts();
|
22
|
+
assertThat(counts.size(), is(4));
|
23
|
+
assertThat(counts, allOf(
|
24
|
+
hasEntry('A', 0),
|
25
|
+
hasEntry('C', 0),
|
26
|
+
hasEntry('G', 0),
|
27
|
+
hasEntry('T', 0)
|
28
|
+
));
|
25
29
|
}
|
26
30
|
|
27
31
|
@Ignore
|
28
32
|
@Test
|
29
33
|
public void testRepetitiveCytidineGetsCounted() {
|
30
34
|
DNA dna = new DNA("CCCCC");
|
31
|
-
assertThat(dna.count('C')
|
35
|
+
assertThat(dna.count('C'), is(5));
|
32
36
|
}
|
33
37
|
|
34
38
|
@Ignore
|
35
39
|
@Test
|
36
40
|
public void testRepetitiveSequenceWithOnlyGuanosine() {
|
37
41
|
DNA dna = new DNA("GGGGGGGG");
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
42
|
+
Map<Character, Integer> counts = dna.nucleotideCounts();
|
43
|
+
assertThat(counts.size(), is(4));
|
44
|
+
assertThat(counts, allOf(
|
45
|
+
hasEntry('A', 0),
|
46
|
+
hasEntry('C', 0),
|
47
|
+
hasEntry('G', 8),
|
48
|
+
hasEntry('T', 0)
|
49
|
+
));
|
44
50
|
}
|
45
51
|
|
46
52
|
@Ignore
|
47
53
|
@Test
|
48
54
|
public void testCountsOnlyThymidine() {
|
49
55
|
DNA dna = new DNA("GGGGGTAACCCGG");
|
50
|
-
assertThat(dna.count('T')
|
56
|
+
assertThat(dna.count('T'), is(1));
|
51
57
|
}
|
52
58
|
|
53
59
|
@Ignore
|
@@ -55,7 +61,7 @@ public class NucleotideTest {
|
|
55
61
|
public void testCountsANucleotideOnlyOnce() {
|
56
62
|
DNA dna = new DNA("CGATTGGG");
|
57
63
|
dna.count('T');
|
58
|
-
assertThat(dna.count('T')
|
64
|
+
assertThat(dna.count('T'), is(2));
|
59
65
|
}
|
60
66
|
|
61
67
|
@Ignore
|
@@ -63,12 +69,14 @@ public class NucleotideTest {
|
|
63
69
|
public void testDnaCountsDoNotChangeAfterCountingAdenosine() {
|
64
70
|
DNA dna = new DNA("GATTACA");
|
65
71
|
dna.count('A');
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
+
Map<Character, Integer> counts = dna.nucleotideCounts();
|
73
|
+
assertThat(counts.size(), is(4));
|
74
|
+
assertThat(counts, allOf(
|
75
|
+
hasEntry('A', 3),
|
76
|
+
hasEntry('C', 1),
|
77
|
+
hasEntry('G', 1),
|
78
|
+
hasEntry('T', 2)
|
79
|
+
));
|
72
80
|
}
|
73
81
|
|
74
82
|
@Ignore
|
@@ -83,11 +91,13 @@ public class NucleotideTest {
|
|
83
91
|
public void testCountsAllNucleotides() {
|
84
92
|
String s = "AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC";
|
85
93
|
DNA dna = new DNA(s);
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
94
|
+
Map<Character, Integer> counts = dna.nucleotideCounts();
|
95
|
+
assertThat(counts.size(), is(4));
|
96
|
+
assertThat(counts, allOf(
|
97
|
+
hasEntry('A', 20),
|
98
|
+
hasEntry('C', 12),
|
99
|
+
hasEntry('G', 17),
|
100
|
+
hasEntry('T', 21)
|
101
|
+
));
|
92
102
|
}
|
93
103
|
}
|
@@ -1,8 +1,10 @@
|
|
1
|
+
import org.junit.Ignore;
|
2
|
+
import org.junit.Test;
|
1
3
|
|
2
4
|
import java.util.NoSuchElementException;
|
3
|
-
|
4
|
-
import org.
|
5
|
-
import org.junit.
|
5
|
+
|
6
|
+
import static org.hamcrest.CoreMatchers.*;
|
7
|
+
import static org.junit.Assert.*;
|
6
8
|
|
7
9
|
public class SimpleLinkedListTest {
|
8
10
|
|
@@ -10,7 +12,7 @@ public class SimpleLinkedListTest {
|
|
10
12
|
@Test
|
11
13
|
public void aNewListIsEmpty() {
|
12
14
|
SimpleLinkedList list = new SimpleLinkedList();
|
13
|
-
assertThat(list.size()
|
15
|
+
assertThat(list.size(), is(0));
|
14
16
|
}
|
15
17
|
|
16
18
|
@Ignore
|
@@ -18,7 +20,7 @@ public class SimpleLinkedListTest {
|
|
18
20
|
public void canCreateFromArray() {
|
19
21
|
Integer[] values = new Integer[]{1, 2, 3};
|
20
22
|
SimpleLinkedList list = new SimpleLinkedList(values);
|
21
|
-
assertThat(list.size()
|
23
|
+
assertThat(list.size(), is(3));
|
22
24
|
}
|
23
25
|
|
24
26
|
@Ignore
|
@@ -34,10 +36,10 @@ public class SimpleLinkedListTest {
|
|
34
36
|
SimpleLinkedList list = new SimpleLinkedList();
|
35
37
|
list.push(9);
|
36
38
|
list.push(8);
|
37
|
-
assertThat(list.size()
|
38
|
-
assertThat(list.pop()
|
39
|
-
assertThat(list.pop()
|
40
|
-
assertThat(list.size()
|
39
|
+
assertThat(list.size(), is(2));
|
40
|
+
assertThat(list.pop(), is(8));
|
41
|
+
assertThat(list.pop(), is(9));
|
42
|
+
assertThat(list.size(), is(0));
|
41
43
|
}
|
42
44
|
|
43
45
|
@Ignore
|
@@ -50,11 +52,11 @@ public class SimpleLinkedListTest {
|
|
50
52
|
list.push(6);
|
51
53
|
list.push(5);
|
52
54
|
list.reverse();
|
53
|
-
assertThat(list.pop()
|
54
|
-
assertThat(list.pop()
|
55
|
-
assertThat(list.pop()
|
56
|
-
assertThat(list.pop()
|
57
|
-
assertThat(list.pop()
|
55
|
+
assertThat(list.pop(), is(9));
|
56
|
+
assertThat(list.pop(), is(8));
|
57
|
+
assertThat(list.pop(), is(7));
|
58
|
+
assertThat(list.pop(), is(6));
|
59
|
+
assertThat(list.pop(), is(5));
|
58
60
|
}
|
59
61
|
|
60
62
|
@Ignore
|
@@ -67,7 +69,7 @@ public class SimpleLinkedListTest {
|
|
67
69
|
list.push(6);
|
68
70
|
list.push(5);
|
69
71
|
Integer[] expected = {5, 6, 7, 8, 9};
|
70
|
-
|
72
|
+
assertEquals(list.asArray(Integer.class), expected);
|
71
73
|
}
|
72
74
|
|
73
75
|
@Ignore
|
@@ -75,7 +77,7 @@ public class SimpleLinkedListTest {
|
|
75
77
|
public void canReturnEmptyListAsEmptyArray() {
|
76
78
|
SimpleLinkedList list = new SimpleLinkedList();
|
77
79
|
Object[] expected = {};
|
78
|
-
|
80
|
+
assertEquals(list.asArray(Object.class), expected);
|
79
81
|
}
|
80
82
|
|
81
83
|
}
|
@@ -6,7 +6,7 @@ There are at least two common options to run JavaScript code: the browsers and [
|
|
6
6
|
|
7
7
|
**Mac OS X users**: same as Windows users, you will find official installers on [Node.js downloads](https://nodejs.org/en/download/). Choose the LTS version. It will install Node.js and `npm` on your machine.
|
8
8
|
|
9
|
-
**Linux users**: there are binaries for `node` and `npm` tools on the Node.js downloads page, but the recommended way to install them on a Linux machine is via a package manager. As of writing this, the recommended version of Node.js to install is 4.x. To install it on a Debian or Ubuntu Linux
|
9
|
+
**Linux users**: there are binaries for `node` and `npm` tools on the Node.js downloads page, but the recommended way to install them on a Linux machine is via a package manager. As of writing this, the recommended version of Node.js to install is 4.x. To install it on a Debian or Ubuntu Linux distribution just execute these commands:
|
10
10
|
|
11
11
|
curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -
|
12
12
|
sudo apt-get install -y nodejs
|
@@ -0,0 +1,17 @@
|
|
1
|
+
{
|
2
|
+
"name": "leap",
|
3
|
+
"ignore": [
|
4
|
+
"**/.*",
|
5
|
+
"node_modules",
|
6
|
+
"bower_components",
|
7
|
+
"output"
|
8
|
+
],
|
9
|
+
"dependencies": {
|
10
|
+
"purescript-prelude": "^2.1.0",
|
11
|
+
"purescript-unicode": "^2.0.1"
|
12
|
+
},
|
13
|
+
"devDependencies": {
|
14
|
+
"purescript-psci-support": "^2.0.0",
|
15
|
+
"purescript-test-unit": "^10.0.1"
|
16
|
+
}
|
17
|
+
}
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Acronym
|
2
|
+
( abbreviate
|
3
|
+
) where
|
4
|
+
|
5
|
+
import Prelude
|
6
|
+
import Data.Foldable (foldl)
|
7
|
+
import Data.String as String
|
8
|
+
import Data.Char as Char
|
9
|
+
import Data.List as List
|
10
|
+
import Data.List (List)
|
11
|
+
import Data.Char.Unicode as UChar
|
12
|
+
|
13
|
+
abbreviate :: String -> String
|
14
|
+
abbreviate =
|
15
|
+
initials <<< List.fromFoldable <<< String.toCharArray
|
16
|
+
|
17
|
+
data CharType
|
18
|
+
= Upper
|
19
|
+
| Lower
|
20
|
+
| Space
|
21
|
+
| Other
|
22
|
+
|
23
|
+
|
24
|
+
classify :: Char -> CharType
|
25
|
+
classify '-' = Space
|
26
|
+
classify ' ' = Space
|
27
|
+
classify c
|
28
|
+
| UChar.isUpper c = Upper
|
29
|
+
| UChar.isLower c = Lower
|
30
|
+
| otherwise = Other
|
31
|
+
|
32
|
+
|
33
|
+
initials :: List Char -> String
|
34
|
+
initials =
|
35
|
+
let
|
36
|
+
next Lower Upper c = String.singleton c
|
37
|
+
next Space _ c = String.singleton (Char.toUpper c)
|
38
|
+
next _ _ _ = ""
|
39
|
+
|
40
|
+
step { acc, last } c =
|
41
|
+
let charClass = classify c
|
42
|
+
in { acc: acc <> next last charClass c
|
43
|
+
, last: charClass
|
44
|
+
}
|
45
|
+
in
|
46
|
+
_.acc <<< foldl step { acc: "", last: Space }
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Test.Main where
|
2
|
+
|
3
|
+
import Prelude
|
4
|
+
import Test.Unit.Assert as Assert
|
5
|
+
import Acronym (abbreviate)
|
6
|
+
import Control.Monad.Eff (Eff)
|
7
|
+
import Test.Unit (suite, test)
|
8
|
+
import Test.Unit.Main (runTest)
|
9
|
+
|
10
|
+
|
11
|
+
main :: Eff _ Unit
|
12
|
+
main = runTest do
|
13
|
+
suite "Acronym.abbreviate" do
|
14
|
+
test "acronyms from title case" $
|
15
|
+
Assert.equal
|
16
|
+
"PNG" $
|
17
|
+
abbreviate "Portable Networks Graphic"
|
18
|
+
|
19
|
+
test "acronyms from lower case" $
|
20
|
+
Assert.equal
|
21
|
+
"ROR" $
|
22
|
+
abbreviate "Ruby on Rails"
|
23
|
+
|
24
|
+
test "acronyms from inconsistent case" $
|
25
|
+
Assert.equal
|
26
|
+
"HTML" $
|
27
|
+
abbreviate "HyperText Markup Language"
|
28
|
+
|
29
|
+
test "punctuation is ignored" $
|
30
|
+
Assert.equal
|
31
|
+
"FIFO" $
|
32
|
+
abbreviate "First in, First out"
|
33
|
+
|
34
|
+
test "acronyms ignoring punctuation and casing" $
|
35
|
+
Assert.equal
|
36
|
+
"CMOS" $
|
37
|
+
abbreviate "Complementary Metal-Oxide semiconductor"
|
@@ -1,3 +1,12 @@
|
|
1
|
-
space_age <- function() {
|
2
|
-
|
1
|
+
space_age <- function(seconds,planet) {
|
2
|
+
earth_year <- 31557600 # number of seconds
|
3
|
+
conversion <- list(mercury = 0.2408467 * earth_year,
|
4
|
+
venus = 0.61519726 * earth_year,
|
5
|
+
earth = 1 * earth_year,
|
6
|
+
mars = 1.8808158 * earth_year,
|
7
|
+
jupiter = 11.862615 * earth_year,
|
8
|
+
saturn = 29.447498 * earth_year,
|
9
|
+
uranus = 84.016846 * earth_year,
|
10
|
+
neptune = 164.79132 * earth_year)
|
11
|
+
round(seconds / conversion[planet][[1]],2)
|
3
12
|
}
|
@@ -3,58 +3,42 @@ suppressPackageStartupMessages({ require(testthat) })
|
|
3
3
|
|
4
4
|
test_that("Age on Earth", {
|
5
5
|
seconds <- 1000000000
|
6
|
-
expect_equal(space_age(seconds),
|
7
|
-
31.69
|
8
|
-
)
|
6
|
+
expect_equal(space_age(seconds, "earth"), 31.69)
|
9
7
|
})
|
10
8
|
|
11
9
|
test_that("Age on Mercury", {
|
12
|
-
seconds <-
|
13
|
-
expect_equal(space_age(seconds),
|
14
|
-
280.88
|
15
|
-
)
|
10
|
+
seconds <- 2134835688
|
11
|
+
expect_equal(space_age(seconds, "mercury"), 280.88)
|
16
12
|
})
|
17
13
|
|
18
14
|
test_that("Age on Venus", {
|
19
15
|
seconds <- 189839836
|
20
|
-
expect_equal(space_age(seconds),
|
21
|
-
9.78
|
22
|
-
)
|
16
|
+
expect_equal(space_age(seconds, "venus"), 9.78)
|
23
17
|
})
|
24
18
|
|
25
19
|
test_that("Age on Mars", {
|
26
20
|
seconds <- 2329871239
|
27
|
-
expect_equal(space_age(seconds),
|
28
|
-
39.25
|
29
|
-
)
|
21
|
+
expect_equal(space_age(seconds, "mars"), 39.25)
|
30
22
|
})
|
31
23
|
|
32
24
|
test_that("Age on Jupiter", {
|
33
25
|
seconds <- 901876382
|
34
|
-
expect_equal(space_age(seconds),
|
35
|
-
2.41
|
36
|
-
)
|
26
|
+
expect_equal(space_age(seconds, "jupiter"), 2.41)
|
37
27
|
})
|
38
28
|
|
39
29
|
test_that("Age on Saturn", {
|
40
30
|
seconds <- 3000000000
|
41
|
-
expect_equal(space_age(seconds),
|
42
|
-
3.23
|
43
|
-
)
|
31
|
+
expect_equal(space_age(seconds, "saturn"), 3.23)
|
44
32
|
})
|
45
33
|
|
46
34
|
test_that("Age on Uranus", {
|
47
35
|
seconds <- 3210123456
|
48
|
-
expect_equal(space_age(seconds),
|
49
|
-
1.21
|
50
|
-
)
|
36
|
+
expect_equal(space_age(seconds,"uranus"), 1.21)
|
51
37
|
})
|
52
38
|
|
53
39
|
test_that("Age on Neptune", {
|
54
40
|
seconds <- 8210123456
|
55
|
-
expect_equal(space_age(seconds),
|
56
|
-
1.58
|
57
|
-
)
|
41
|
+
expect_equal(space_age(seconds, "neptune"), 1.58)
|
58
42
|
})
|
59
43
|
|
60
44
|
print("All tests passed!")
|
data/tracks/rust/config.json
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
## Installation
|
2
2
|
|
3
|
-
|
3
|
+
Methods for installing Rust change as the language evolves. To get up-to-date installation instructions head to the [Rust homepage](https://www.rust-lang.org/) and click the "Install Rust" link.
|
data/tracks/rust/docs/TESTS.md
CHANGED
@@ -1,16 +1,8 @@
|
|
1
1
|
## Writing the Code
|
2
2
|
|
3
|
-
Write your code in `src/lib.rs`
|
3
|
+
Write your code in `src/lib.rs`. Some exercises come with a stub file in `src/lib.rs` that will show you the signatures of the code you'll need to write. If the exercise does not come with a `src/lib.rs` file, create one.
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
If you were starting from scratch you could use `cargo new` to create the filestructure: e.g. `cargo new $projectname`.
|
8
|
-
exercism has already created the projectname directory so you'll need to create `src/lib.rs` manually:
|
9
|
-
|
10
|
-
```bash
|
11
|
-
mkdir src
|
12
|
-
touch src/lib.rs
|
13
|
-
```
|
5
|
+
The directory must be named `src` and the file must be named `lib.rs` otherwise your code will not compile. For more details, check out the rustlang book [chapter on crates and modules](http://doc.rust-lang.org/stable/book/crates-and-modules.html)
|
14
6
|
|
15
7
|
### Running Tests
|
16
8
|
|
@@ -24,3 +16,4 @@ Only the first test is enabled by default. After you are ready to pass the next
|
|
24
16
|
|
25
17
|
You should try to write as little code possible to get the tests to pass. Let the test failures guide you to what should be written next.
|
26
18
|
|
19
|
+
Because Rust checks all code at compile time you may find that your tests won't compile until you write the required code. Even `ignore`d tests are checked at compile time. You can [comment out](https://doc.rust-lang.org/stable/book/comments.html) tests that won't compile by starting each line with a `//`. Then, when you're ready to work on that test, you can un-comment it.
|
@@ -0,0 +1,17 @@
|
|
1
|
+
use std::collections::BTreeSet;
|
2
|
+
|
3
|
+
pub fn sum_of_multiples(limit: u32, factors: &[u32]) -> u32 {
|
4
|
+
let mut multiples: BTreeSet<u32> = BTreeSet::new();
|
5
|
+
|
6
|
+
for &f in factors {
|
7
|
+
let mut multiplier = 2;
|
8
|
+
let mut x = f;
|
9
|
+
while x < limit {
|
10
|
+
multiples.insert(x);
|
11
|
+
x = f * multiplier;
|
12
|
+
multiplier += 1;
|
13
|
+
}
|
14
|
+
}
|
15
|
+
|
16
|
+
multiples.iter().sum()
|
17
|
+
}
|
@@ -0,0 +1,74 @@
|
|
1
|
+
extern crate sum_of_multiples;
|
2
|
+
|
3
|
+
use sum_of_multiples::*;
|
4
|
+
|
5
|
+
#[test]
|
6
|
+
fn multiples_one() {
|
7
|
+
assert_eq!(0, sum_of_multiples(1, &vec![3, 5]))
|
8
|
+
}
|
9
|
+
|
10
|
+
#[test]
|
11
|
+
#[ignore]
|
12
|
+
fn multiples_two() {
|
13
|
+
assert_eq!(3, sum_of_multiples(4, &vec![3, 5]))
|
14
|
+
}
|
15
|
+
|
16
|
+
#[test]
|
17
|
+
#[ignore]
|
18
|
+
fn multiples_three() {
|
19
|
+
assert_eq!(23, sum_of_multiples(10, &vec![3, 5]))
|
20
|
+
}
|
21
|
+
|
22
|
+
#[test]
|
23
|
+
#[ignore]
|
24
|
+
fn multiples_four() {
|
25
|
+
assert_eq!(2318, sum_of_multiples(100, &vec![3, 5]))
|
26
|
+
}
|
27
|
+
|
28
|
+
#[test]
|
29
|
+
#[ignore]
|
30
|
+
fn multiples_five() {
|
31
|
+
assert_eq!(233168, sum_of_multiples(1000, &vec![3, 5]))
|
32
|
+
}
|
33
|
+
|
34
|
+
#[test]
|
35
|
+
#[ignore]
|
36
|
+
fn multiples_six() {
|
37
|
+
assert_eq!(51, sum_of_multiples(20, &vec![7, 13, 17]))
|
38
|
+
}
|
39
|
+
|
40
|
+
#[test]
|
41
|
+
#[ignore]
|
42
|
+
fn multiples_seven() {
|
43
|
+
assert_eq!(30, sum_of_multiples(15, &vec![4, 6]))
|
44
|
+
}
|
45
|
+
|
46
|
+
#[test]
|
47
|
+
#[ignore]
|
48
|
+
fn multiples_eight() {
|
49
|
+
assert_eq!(4419, sum_of_multiples(150, &vec![5, 6, 8]))
|
50
|
+
}
|
51
|
+
|
52
|
+
#[test]
|
53
|
+
#[ignore]
|
54
|
+
fn multiples_nine() {
|
55
|
+
assert_eq!(275, sum_of_multiples(51, &vec![5, 25]))
|
56
|
+
}
|
57
|
+
|
58
|
+
#[test]
|
59
|
+
#[ignore]
|
60
|
+
fn multiples_ten() {
|
61
|
+
assert_eq!(2203160, sum_of_multiples(10000, &vec![43, 47]))
|
62
|
+
}
|
63
|
+
|
64
|
+
#[test]
|
65
|
+
#[ignore]
|
66
|
+
fn multiples_eleven() {
|
67
|
+
assert_eq!(4950, sum_of_multiples(100, &vec![1]))
|
68
|
+
}
|
69
|
+
|
70
|
+
#[test]
|
71
|
+
#[ignore]
|
72
|
+
fn multiples_twelve() {
|
73
|
+
assert_eq!(0, sum_of_multiples(10000, &vec![]))
|
74
|
+
}
|
data/tracks/rust/problems.md
CHANGED
@@ -23,6 +23,7 @@ raindrops | case (or `format`). Mutable string
|
|
23
23
|
bob | chars, string functions
|
24
24
|
beer-song | case, string concatenation, vector (optional), loop
|
25
25
|
difference-of-squares | fold & map
|
26
|
+
sum-of-multiples | algorithm, borrowing
|
26
27
|
grains | math, panic
|
27
28
|
|
28
29
|
## Getting Rusty
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import scala.math.pow
|
2
2
|
|
3
|
-
|
3
|
+
object Squares {
|
4
4
|
|
5
5
|
def sumOfSquares(n: Int): Int = n * (n + 1) * (2 * n + 1) / 6
|
6
6
|
|
@@ -8,7 +8,3 @@ class Squares {
|
|
8
8
|
|
9
9
|
def difference(n: Int): Int = squareOfSums(n) - sumOfSquares(n)
|
10
10
|
}
|
11
|
-
|
12
|
-
object Squares {
|
13
|
-
def apply() = new Squares
|
14
|
-
}
|
@@ -2,55 +2,55 @@ import org.scalatest.{Matchers, FlatSpec}
|
|
2
2
|
|
3
3
|
class SquaresTest extends FlatSpec with Matchers {
|
4
4
|
it should "calc square of sums to 5" in {
|
5
|
-
val result = Squares
|
5
|
+
val result = Squares.squareOfSums(5)
|
6
6
|
result should equal (225)
|
7
7
|
}
|
8
8
|
|
9
9
|
it should "calc sum of squares to 5" in {
|
10
10
|
pending
|
11
|
-
val result = Squares
|
11
|
+
val result = Squares.sumOfSquares(5)
|
12
12
|
result should equal (55)
|
13
13
|
}
|
14
14
|
|
15
15
|
it should "calc difference of sums to 5" in {
|
16
16
|
pending
|
17
|
-
val result = Squares
|
17
|
+
val result = Squares.difference(5)
|
18
18
|
result should equal (170)
|
19
19
|
}
|
20
20
|
|
21
21
|
it should "calc square of sums to 10" in {
|
22
22
|
pending
|
23
|
-
val result = Squares
|
23
|
+
val result = Squares.squareOfSums(10)
|
24
24
|
result should equal (3025)
|
25
25
|
}
|
26
26
|
|
27
27
|
it should "calc sum of squares to 10" in {
|
28
28
|
pending
|
29
|
-
val result = Squares
|
29
|
+
val result = Squares.sumOfSquares(10)
|
30
30
|
result should equal (385)
|
31
31
|
}
|
32
32
|
|
33
33
|
it should "calc difference of sums to 10" in {
|
34
34
|
pending
|
35
|
-
val result = Squares
|
35
|
+
val result = Squares.difference(10)
|
36
36
|
result should equal (2640)
|
37
37
|
}
|
38
38
|
|
39
39
|
it should "calc square of sums to 100" in {
|
40
40
|
pending
|
41
|
-
val result = Squares
|
41
|
+
val result = Squares.squareOfSums(100)
|
42
42
|
result should equal (25502500)
|
43
43
|
}
|
44
44
|
|
45
45
|
it should "calc sum of squares to 100" in {
|
46
46
|
pending
|
47
|
-
val result = Squares
|
47
|
+
val result = Squares.sumOfSquares(100)
|
48
48
|
result should equal (338350)
|
49
49
|
}
|
50
50
|
|
51
51
|
it should "calc difference of sums to 100" in {
|
52
52
|
pending
|
53
|
-
val result = Squares
|
53
|
+
val result = Squares.difference(100)
|
54
54
|
result should equal (25164150)
|
55
55
|
}
|
56
56
|
}
|
@@ -1,21 +1,18 @@
|
|
1
1
|
import scala.util.Random
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
private def prefix = Random.shuffle(Robot.alphabet).take(2).mkString
|
13
|
-
|
14
|
-
private def suffix = Random.shuffle(Robot.suffixes).head.toString
|
3
|
+
object UniqueNames {
|
4
|
+
val names =
|
5
|
+
Random.shuffle(1 to 26 * 26 * 1000).iterator.map(n => {
|
6
|
+
val lettersPart = n / 1000
|
7
|
+
val firstLetter = 'A' + (lettersPart / 26)
|
8
|
+
val secondLetter = 'A' + (lettersPart % 26)
|
9
|
+
f"$firstLetter%c$secondLetter%c${n % 1000}%03d"
|
10
|
+
})
|
15
11
|
}
|
16
12
|
|
17
|
-
|
18
|
-
private
|
13
|
+
class Robot {
|
14
|
+
private var storedName = UniqueNames.names.next()
|
19
15
|
|
20
|
-
|
21
|
-
|
16
|
+
def name: String = storedName
|
17
|
+
def reset(): Unit = storedName = UniqueNames.names.next()
|
18
|
+
}
|
@@ -1,10 +1,12 @@
|
|
1
1
|
import org.scalatest._
|
2
2
|
|
3
|
+
import collection.mutable
|
4
|
+
|
3
5
|
class RobotNameSpecs extends FunSpec with Matchers {
|
4
6
|
val nameRegex = """[A-Z]{2}\d{3}"""
|
5
7
|
|
6
8
|
it ("has a name") {
|
7
|
-
new Robot().name should fullyMatch regex
|
9
|
+
new Robot().name should fullyMatch regex nameRegex
|
8
10
|
}
|
9
11
|
|
10
12
|
it ("does not change its name") {
|
@@ -16,7 +18,7 @@ class RobotNameSpecs extends FunSpec with Matchers {
|
|
16
18
|
|
17
19
|
it ("does not have the same name as other robots") {
|
18
20
|
pending
|
19
|
-
new Robot().name should not be
|
21
|
+
new Robot().name should not be new Robot().name
|
20
22
|
}
|
21
23
|
|
22
24
|
it ("can have its name reset") {
|
@@ -25,7 +27,22 @@ class RobotNameSpecs extends FunSpec with Matchers {
|
|
25
27
|
val name = robot.name
|
26
28
|
robot.reset()
|
27
29
|
val name2 = robot.name
|
28
|
-
name should not equal
|
29
|
-
name2 should fullyMatch regex
|
30
|
+
name should not equal name2
|
31
|
+
name2 should fullyMatch regex nameRegex
|
32
|
+
}
|
33
|
+
|
34
|
+
// Making this test pass is an optional extra exercise, should you want more of a challenge.
|
35
|
+
// It's ignored by default, to make it run, simply change "ignore" below to "it".
|
36
|
+
// There are 26^2 * 1,000 = 676,000 possible robot names - you have to ensure that none are repeated.
|
37
|
+
// The Robot code needs to be efficient enough to allow all 676,000 unique names to be generated.
|
38
|
+
ignore("a large number of new instances have unique names") {
|
39
|
+
val alreadySet = mutable.HashSet.empty[String]
|
40
|
+
for(_ <- 0 until 676000 - 6) { // as 6 robot names are generated in the tests above!!
|
41
|
+
val name = new Robot().name
|
42
|
+
if (alreadySet contains name) {
|
43
|
+
fail(s"$name is repeated")
|
44
|
+
}
|
45
|
+
alreadySet += name
|
46
|
+
}
|
30
47
|
}
|
31
48
|
}
|
data/tracks/swift/docs/TESTS.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
This guide explains how to create and configure a Swift-based Xcode project for Exercism.
|
4
4
|
|
5
|
-
Apple does not support user-defined project templates in Xcode, and the default templates are more elaborate than
|
5
|
+
Apple does not support user-defined project templates in Xcode, and the default templates are more elaborate than those needed for Exercism. This guide bridges that gap.
|
6
6
|
|
7
7
|
These instructions are written with the expectation that some readers will be very new to Xcode. Therefore each step is described in excruciating detail. However, after a few projects, setting up a fresh project should only take a minute.
|
8
8
|
|
@@ -78,13 +78,13 @@ In the Finder, locate the root folder `hello-world` for this exercise. Drag the
|
|
78
78
|
|
79
79
|

|
80
80
|
|
81
|
-
Select the newly imported file in the File Inspector to open the source code. Add the line `@testable import HelloWorld` above the class declaration. (When the Xcode project name contains a hyphen, replace it with an underscore. For example, `Word-Count` would become `
|
81
|
+
Select the newly imported file in the File Inspector to open the source code. Add the line `@testable import HelloWorld` above the class declaration. (When the Xcode project name contains a hyphen, replace it with an underscore. For example, `Word-Count` would become `Word_Count`.) The image below shows how the document should appear. Red errors are likely at this stage, and normal.
|
82
82
|
|
83
83
|

|
84
84
|
|
85
85
|
Here is how the file inspector should look now:
|
86
86
|
|
87
|
-

|
88
88
|
|
89
89
|
The housekeeping is finished and Xcode is ready! To review:
|
90
90
|
|
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.0.5.
|
4
|
+
version: 2.0.5.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Katrina Owen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-12-
|
11
|
+
date: 2016-12-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubyzip
|
@@ -5456,6 +5456,10 @@ files:
|
|
5456
5456
|
- tracks/purescript/docs/LEARNING.md
|
5457
5457
|
- tracks/purescript/docs/RESOURCES.md
|
5458
5458
|
- tracks/purescript/docs/TESTS.md
|
5459
|
+
- tracks/purescript/exercises/acronym/bower.json
|
5460
|
+
- tracks/purescript/exercises/acronym/examples/src/Acronym.purs
|
5461
|
+
- tracks/purescript/exercises/acronym/src/Acronym.purs
|
5462
|
+
- tracks/purescript/exercises/acronym/test/Main.purs
|
5459
5463
|
- tracks/purescript/exercises/bob/bower.json
|
5460
5464
|
- tracks/purescript/exercises/bob/examples/src/Bob.purs
|
5461
5465
|
- tracks/purescript/exercises/bob/src/Bob.purs
|
@@ -6307,6 +6311,10 @@ files:
|
|
6307
6311
|
- tracks/rust/exercises/sublist/Cargo.toml
|
6308
6312
|
- tracks/rust/exercises/sublist/example.rs
|
6309
6313
|
- tracks/rust/exercises/sublist/tests/sublist.rs
|
6314
|
+
- tracks/rust/exercises/sum-of-multiples/.gitignore
|
6315
|
+
- tracks/rust/exercises/sum-of-multiples/Cargo.toml
|
6316
|
+
- tracks/rust/exercises/sum-of-multiples/example.rs
|
6317
|
+
- tracks/rust/exercises/sum-of-multiples/tests/sum-of-multiples.rs
|
6310
6318
|
- tracks/rust/exercises/tournament/.gitignore
|
6311
6319
|
- tracks/rust/exercises/tournament/Cargo.lock
|
6312
6320
|
- tracks/rust/exercises/tournament/Cargo.toml
|