trackler 2.1.0.19 → 2.1.0.20
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/verify-metadata +1 -1
- data/lib/trackler/implementation.rb +1 -9
- data/lib/trackler/version.rb +1 -1
- data/tracks/go/exercises/tree-building/tree_test.go +1 -1
- data/tracks/haskell/.travis.yml +1 -0
- data/tracks/haskell/bin/test-example +17 -5
- data/tracks/haskell/bin/test-stub +14 -3
- data/tracks/java/exercises/build.gradle +3 -3
- data/tracks/java/exercises/difference-of-squares/src/test/java/DifferenceOfSquaresCalculatorTest.java +1 -1
- data/tracks/javascript/config.json +21 -1
- data/tracks/javascript/exercises/alphametics/alphametics.spec.js +95 -0
- data/tracks/javascript/exercises/alphametics/example.js +107 -0
- data/tracks/perl6/bin/README.md +5 -3
- data/tracks/perl6/docs/LEARNING.md +7 -0
- data/tracks/r/exercises/anagram/test_anagram.R +33 -52
- data/tracks/r/exercises/bob/test_bob.R +52 -73
- data/tracks/r/exercises/difference-of-squares/test_difference-of-squares.R +1 -2
- data/tracks/r/exercises/grains/test_grains.R +1 -1
- data/tracks/r/exercises/hamming/test_hamming.R +1 -1
- data/tracks/r/exercises/hello-world/test_hello-world.R +1 -1
- data/tracks/r/exercises/isogram/test_isogram.R +1 -1
- data/tracks/r/exercises/largest-series-product/test_largest-series-product.R +8 -8
- data/tracks/r/exercises/leap/test_leap.R +1 -1
- data/tracks/r/exercises/luhn/test_luhn.R +1 -1
- data/tracks/r/exercises/pascals-triangle/test_pascals-triangle.R +1 -1
- data/tracks/r/exercises/perfect-numbers/test_perfect-numbers.R +1 -1
- data/tracks/r/exercises/phone-number/test_phone-number.R +1 -1
- data/tracks/r/exercises/prime-factors/test_prime-factors.R +16 -21
- data/tracks/r/exercises/raindrops/test_raindrops.R +1 -1
- data/tracks/r/exercises/rna-transcription/test_rna-transcription.R +1 -1
- data/tracks/r/exercises/rotational-cipher/test_rotational-cipher.R +1 -1
- data/tracks/r/exercises/scrabble-score/test_scrabble-score.R +1 -1
- data/tracks/r/exercises/secret-handshake/test_secret-handshake.R +1 -1
- data/tracks/r/exercises/sieve/test_sieve.R +18 -17
- data/tracks/r/exercises/space-age/test_space-age.R +2 -2
- data/tracks/r/exercises/sum-of-multiples/test_sum-of-multiples.R +11 -11
- data/tracks/r/exercises/tournament/test_tournament.R +142 -107
- data/tracks/r/exercises/word-count/test_word-count.R +38 -17
- data/tracks/vimscript/config.json +23 -0
- data/tracks/vimscript/exercises/anagram/anagram.vader +95 -0
- data/tracks/vimscript/exercises/anagram/anagram.vim +19 -0
- data/tracks/vimscript/exercises/anagram/example.vim +18 -0
- data/tracks/vimscript/exercises/difference-of-squares/difference_of_squares.vader +35 -0
- data/tracks/vimscript/exercises/difference-of-squares/difference_of_squares.vim +24 -0
- data/tracks/vimscript/exercises/difference-of-squares/example.vim +19 -0
- data/tracks/vimscript/exercises/raindrops/example.vim +9 -0
- data/tracks/vimscript/exercises/raindrops/raindrops.vader +53 -0
- data/tracks/vimscript/exercises/raindrops/raindrops.vim +18 -0
- data/tracks/vimscript/exercises/rna-transcription/example.vim +3 -0
- data/tracks/vimscript/exercises/rna-transcription/rna_transcription.vader +23 -0
- data/tracks/vimscript/exercises/rna-transcription/rna_transcription.vim +20 -0
- metadata +16 -2
@@ -1,49 +1,70 @@
|
|
1
|
-
source(
|
1
|
+
source("./word-count.R")
|
2
2
|
library(testthat)
|
3
3
|
|
4
4
|
# When comparing lists, all.equal expects the objects to be in the same order
|
5
|
-
# This expectation instead checks that a) the set of names are the same and
|
5
|
+
# This expectation instead checks that a) the set of names are the same and
|
6
|
+
# b) each named object is equal
|
6
7
|
expect_equal_pairs <- function(object, expected) {
|
7
|
-
expect_equal(sort(names(object)),
|
8
|
-
|
9
|
-
|
8
|
+
expect_equal(sort(names(object)),
|
9
|
+
sort(names(expected)),
|
10
|
+
info = "names in lists differ")
|
11
|
+
for (name in names(expected)) {
|
12
|
+
expect_equal(object[name], expected[name], info = "list element missing")
|
10
13
|
}
|
11
14
|
}
|
12
15
|
|
13
16
|
test_that("count one word", {
|
14
17
|
expect_equal_pairs(word_count("word"),
|
15
|
-
|
16
|
-
)
|
18
|
+
list("word" = 1))
|
17
19
|
})
|
18
20
|
|
19
21
|
test_that("count one of each word", {
|
20
22
|
expect_equal_pairs(word_count("one of each"),
|
21
|
-
|
22
|
-
|
23
|
+
list(
|
24
|
+
"one" = 1,
|
25
|
+
"of" = 1,
|
26
|
+
"each" = 1
|
27
|
+
))
|
23
28
|
})
|
24
29
|
|
25
30
|
test_that("multiple occurrences of a word", {
|
26
|
-
expect_equal_pairs(
|
27
|
-
|
31
|
+
expect_equal_pairs(
|
32
|
+
word_count("one fish two fish red fish blue fish"),
|
33
|
+
list(
|
34
|
+
"one" = 1,
|
35
|
+
"fish" = 4,
|
36
|
+
"two" = 1,
|
37
|
+
"red" = 1,
|
38
|
+
"blue" = 1
|
39
|
+
)
|
28
40
|
)
|
29
41
|
})
|
30
42
|
|
31
43
|
test_that("ignore punctuation", {
|
32
|
-
expect_equal_pairs(
|
33
|
-
|
44
|
+
expect_equal_pairs(
|
45
|
+
word_count("car : carpet as java : javascript!!&@$%^&"),
|
46
|
+
list(
|
47
|
+
"car" = 1,
|
48
|
+
"carpet" = 1,
|
49
|
+
"as" = 1,
|
50
|
+
"java" = 1,
|
51
|
+
"javascript" = 1
|
52
|
+
)
|
34
53
|
)
|
35
54
|
})
|
36
55
|
|
37
56
|
test_that("include numbers", {
|
38
57
|
expect_equal_pairs(word_count("testing, 1, 2 testing"),
|
39
|
-
|
40
|
-
|
58
|
+
list(
|
59
|
+
"testing" = 2,
|
60
|
+
"1" = 1,
|
61
|
+
"2" = 1
|
62
|
+
))
|
41
63
|
})
|
42
64
|
|
43
65
|
test_that("normalize case", {
|
44
66
|
expect_equal_pairs(word_count("go Go GO Stop stop"),
|
45
|
-
|
46
|
-
)
|
67
|
+
list("go" = 3, "stop" = 2))
|
47
68
|
})
|
48
69
|
|
49
70
|
print("All tests passed!")
|
@@ -23,6 +23,29 @@
|
|
23
23
|
"slug": "bob",
|
24
24
|
"difficulty": 1,
|
25
25
|
"topics": []
|
26
|
+
},
|
27
|
+
{
|
28
|
+
"slug": "rna-transcription",
|
29
|
+
"difficulty": 1,
|
30
|
+
"topics": []
|
31
|
+
},
|
32
|
+
{
|
33
|
+
"slug": "anagram",
|
34
|
+
"difficulty": 1,
|
35
|
+
"topics": [
|
36
|
+
]
|
37
|
+
},
|
38
|
+
{
|
39
|
+
"slug": "difference-of-squares",
|
40
|
+
"difficulty": 1,
|
41
|
+
"topics": [
|
42
|
+
]
|
43
|
+
},
|
44
|
+
{
|
45
|
+
"slug": "raindrops",
|
46
|
+
"difficulty": 1,
|
47
|
+
"topics": [
|
48
|
+
]
|
26
49
|
}
|
27
50
|
],
|
28
51
|
"deprecated": [],
|
@@ -0,0 +1,95 @@
|
|
1
|
+
Execute (no matches):
|
2
|
+
let word = 'diaper'
|
3
|
+
let candidates = ['hello', 'world', 'zombies', 'pants']
|
4
|
+
let expected = []
|
5
|
+
AssertEqual expected, Anagram(word, candidates)
|
6
|
+
|
7
|
+
Execute (detects simple anagram):
|
8
|
+
let word = 'ant'
|
9
|
+
let candidates = ['tan', 'stand', 'at']
|
10
|
+
let expected = ['tan']
|
11
|
+
AssertEqual expected, Anagram(word, candidates)
|
12
|
+
|
13
|
+
Execute (does not detect false positives):
|
14
|
+
let word = 'galea'
|
15
|
+
let candidates = ['eagle']
|
16
|
+
let expected = []
|
17
|
+
AssertEqual expected, Anagram(word, candidates)
|
18
|
+
|
19
|
+
Execute (detects two anagrams):
|
20
|
+
let word = 'master'
|
21
|
+
let candidates = ['stream', 'pigeon', 'maters']
|
22
|
+
let expected = ['maters', 'stream']
|
23
|
+
AssertEqual expected, Anagram(word, candidates)
|
24
|
+
|
25
|
+
Execute (does not detect anagram subsets):
|
26
|
+
let word = 'good'
|
27
|
+
let candidates = ['dog', 'goody']
|
28
|
+
let expected = []
|
29
|
+
AssertEqual expected, Anagram(word, candidates)
|
30
|
+
|
31
|
+
Execute (detects anagram):
|
32
|
+
let word = 'listen'
|
33
|
+
let candidates = ['enlists', 'google', 'inlets', 'banana']
|
34
|
+
let expected = ['inlets']
|
35
|
+
AssertEqual expected, Anagram(word, candidates)
|
36
|
+
|
37
|
+
Execute (detects three anagrams):
|
38
|
+
let word = 'allergy'
|
39
|
+
let candidates = ['gallery', 'ballerina', 'regally', 'clergy', 'largely', 'leading']
|
40
|
+
let expected = ['gallery', 'largely', 'regally']
|
41
|
+
AssertEqual expected, Anagram(word, candidates)
|
42
|
+
|
43
|
+
Execute (does not detect identical words):
|
44
|
+
let word = 'corn'
|
45
|
+
let candidates = ['corn', 'dark', 'Corn', 'rank', 'CORN', 'cron', 'park']
|
46
|
+
let expected = ['cron']
|
47
|
+
AssertEqual expected, Anagram(word, candidates)
|
48
|
+
|
49
|
+
Execute (does not detect non-anagrams with identical checksum):
|
50
|
+
let word = 'mass'
|
51
|
+
let candidates = ['last']
|
52
|
+
let expected = []
|
53
|
+
AssertEqual expected, Anagram(word, candidates)
|
54
|
+
|
55
|
+
Execute (detects anagrams case insensitively):
|
56
|
+
let word = 'Orchestra'
|
57
|
+
let candidates = ['cashregister', 'Carthorse', 'radishes']
|
58
|
+
let expected = ['Carthorse']
|
59
|
+
AssertEqual expected, Anagram(word, candidates)
|
60
|
+
|
61
|
+
Execute (detects anagrams using case insensitive subject):
|
62
|
+
let word = 'Orchestra'
|
63
|
+
let candidates = ['cashregister', 'carthorse', 'radishes']
|
64
|
+
let expected = ['carthorse']
|
65
|
+
AssertEqual expected, Anagram(word, candidates)
|
66
|
+
|
67
|
+
Execute (detects anagrams using case insensitive possible matches):
|
68
|
+
let word = 'orchestra'
|
69
|
+
let candidates = ['cashregister', 'Carthorse', 'radishes']
|
70
|
+
let expected = ['Carthorse']
|
71
|
+
AssertEqual expected, Anagram(word, candidates)
|
72
|
+
|
73
|
+
Execute (does not detect a word as its own anagram):
|
74
|
+
let word = 'banana'
|
75
|
+
let candidates = ['Banana']
|
76
|
+
let expected = []
|
77
|
+
AssertEqual expected, Anagram(word, candidates)
|
78
|
+
|
79
|
+
Execute (does not detect an anagramif the original word is repeated):
|
80
|
+
let word = 'go'
|
81
|
+
let candidates = ['go Go GO']
|
82
|
+
let expected = []
|
83
|
+
AssertEqual expected, Anagram(word, candidates)
|
84
|
+
|
85
|
+
Execute (anagrams must use all letters exactly once):
|
86
|
+
let word = 'tapper'
|
87
|
+
let candidates = ['patter']
|
88
|
+
let expected = []
|
89
|
+
AssertEqual expected, Anagram(word, candidates)
|
90
|
+
|
91
|
+
Execute (capital word is not own anagram):
|
92
|
+
let word = 'BANANA'
|
93
|
+
let candidates = ['Banana']
|
94
|
+
let expected = []
|
95
|
+
AssertEqual expected, Anagram(word, candidates)
|
@@ -0,0 +1,19 @@
|
|
1
|
+
"
|
2
|
+
" Given a word and a list of possible anagrams, select the correct sublist.
|
3
|
+
"
|
4
|
+
" Hints:
|
5
|
+
"
|
6
|
+
" - Same words don't match.
|
7
|
+
" - Cases are treated insensitivley.
|
8
|
+
" - The returned list is sorted.
|
9
|
+
"
|
10
|
+
" Example:
|
11
|
+
"
|
12
|
+
" :echo Anagram('foo', ['foo', 'bar', 'oof', 'Ofo'])
|
13
|
+
" ['Ofo', 'oof']
|
14
|
+
"
|
15
|
+
function! Anagram(word, candidates) abort
|
16
|
+
|
17
|
+
" your solution goes here
|
18
|
+
|
19
|
+
endfunction
|
@@ -0,0 +1,18 @@
|
|
1
|
+
function! Anagram(word, candidates) abort
|
2
|
+
let fp = s:fingerprint(a:word)
|
3
|
+
let matches = []
|
4
|
+
|
5
|
+
for cand in a:candidates
|
6
|
+
if cand ==? a:word
|
7
|
+
continue
|
8
|
+
elseif s:fingerprint(cand) ==? fp
|
9
|
+
let matches += [cand]
|
10
|
+
endif
|
11
|
+
endfor
|
12
|
+
|
13
|
+
return sort(matches)
|
14
|
+
endfunction
|
15
|
+
|
16
|
+
function! s:fingerprint(word) abort
|
17
|
+
return sort(reverse(split(tolower(a:word), '\zs')))
|
18
|
+
endfunction
|
@@ -0,0 +1,35 @@
|
|
1
|
+
Execute (square of sum 0):
|
2
|
+
AssertEqual 0, SquareOfSum(0)
|
3
|
+
|
4
|
+
Execute (square of sum 1):
|
5
|
+
AssertEqual 1, SquareOfSum(1)
|
6
|
+
|
7
|
+
Execute (square of sum 5):
|
8
|
+
AssertEqual 225, SquareOfSum(5)
|
9
|
+
|
10
|
+
Execute (square of sum 100):
|
11
|
+
AssertEqual 25502500, SquareOfSum(100)
|
12
|
+
|
13
|
+
Execute (sum of squares 0):
|
14
|
+
AssertEqual 0, SumOfSquares(0)
|
15
|
+
|
16
|
+
Execute (sum of squares 1):
|
17
|
+
AssertEqual 1, SumOfSquares(1)
|
18
|
+
|
19
|
+
Execute (sum of squares 5):
|
20
|
+
AssertEqual 55, SumOfSquares(5)
|
21
|
+
|
22
|
+
Execute (sum of squares 100):
|
23
|
+
AssertEqual 338350, SumOfSquares(100)
|
24
|
+
|
25
|
+
Execute (differences of squares 0):
|
26
|
+
AssertEqual 0, Difference(0)
|
27
|
+
|
28
|
+
Execute (differences of squares 1):
|
29
|
+
AssertEqual 0, Difference(1)
|
30
|
+
|
31
|
+
Execute (differences of squares 5):
|
32
|
+
AssertEqual 170, Difference(5)
|
33
|
+
|
34
|
+
Execute (differences of squares 100):
|
35
|
+
AssertEqual 25164150, Difference(100)
|
@@ -0,0 +1,24 @@
|
|
1
|
+
"
|
2
|
+
" Find the difference between the square of the sum and the sum of the squares
|
3
|
+
" of the first N natural numbers.
|
4
|
+
"
|
5
|
+
" Examples:
|
6
|
+
"
|
7
|
+
" :echo SquareOfSum(3)
|
8
|
+
" 36
|
9
|
+
" :echo SumOfSquares(3)
|
10
|
+
" 14
|
11
|
+
" :echo Difference(3)
|
12
|
+
" 22
|
13
|
+
"
|
14
|
+
function! Difference(number) abort
|
15
|
+
" your implemention goes here
|
16
|
+
endfunction
|
17
|
+
|
18
|
+
function! SquareOfSum(number) abort
|
19
|
+
" your implemention goes here
|
20
|
+
endfunction
|
21
|
+
|
22
|
+
function! SumOfSquares(number) abort
|
23
|
+
" your implemention goes here
|
24
|
+
endfunction
|
@@ -0,0 +1,19 @@
|
|
1
|
+
function! Difference(number) abort
|
2
|
+
return SquareOfSum(a:number) - SumOfSquares(a:number)
|
3
|
+
endfunction
|
4
|
+
|
5
|
+
function! SquareOfSum(number) abort
|
6
|
+
let sum = 0
|
7
|
+
for n in range(1, a:number)
|
8
|
+
let sum += n
|
9
|
+
endfor
|
10
|
+
return float2nr(pow(sum, 2))
|
11
|
+
endfunction
|
12
|
+
|
13
|
+
function! SumOfSquares(number) abort
|
14
|
+
let sum = 0
|
15
|
+
for n in range(1, a:number)
|
16
|
+
let sum += float2nr(pow(n, 2))
|
17
|
+
endfor
|
18
|
+
return sum
|
19
|
+
endfunction
|
@@ -0,0 +1,53 @@
|
|
1
|
+
Execute (the sound for 1 is 1):
|
2
|
+
AssertEqual '1', Raindrops(1)
|
3
|
+
|
4
|
+
Execute (the sound for 3 is Pling):
|
5
|
+
AssertEqual 'Pling', Raindrops(3)
|
6
|
+
|
7
|
+
Execute (the sound for 5 is Plang):
|
8
|
+
AssertEqual 'Plang', Raindrops(5)
|
9
|
+
|
10
|
+
Execute (the sound for 7 is Plong):
|
11
|
+
AssertEqual 'Plong', Raindrops(7)
|
12
|
+
|
13
|
+
Execute (the sound for 6 is Pling as it has a factor 3):
|
14
|
+
AssertEqual 'Pling', Raindrops(6)
|
15
|
+
|
16
|
+
Execute (2 to the power 3 does not make a raindrop sound as 3 is the exponent not the base):
|
17
|
+
AssertEqual '8', Raindrops(8)
|
18
|
+
|
19
|
+
Execute (the sound for 9 is Pling as it has a factor 3):
|
20
|
+
AssertEqual 'Pling', Raindrops(9)
|
21
|
+
|
22
|
+
Execute (the sound for 10 is Plang as it has a factor 5):
|
23
|
+
AssertEqual 'Plang', Raindrops(10)
|
24
|
+
|
25
|
+
Execute (the sound for 14 is Plong as it has a factor 7):
|
26
|
+
AssertEqual 'Plong', Raindrops(14)
|
27
|
+
|
28
|
+
Execute (the sound for 15 is PlingPlang as it has factors 3 and 5):
|
29
|
+
AssertEqual 'PlingPlang', Raindrops(15)
|
30
|
+
|
31
|
+
Execute (the sound for 21 is PlingPlong as it has factors 3 and 7):
|
32
|
+
AssertEqual 'PlingPlong', Raindrops(21)
|
33
|
+
|
34
|
+
Execute (the sound for 25 is Plang as it has factor 5):
|
35
|
+
AssertEqual 'Plang', Raindrops(5)
|
36
|
+
|
37
|
+
Execute (the sound for 27 is Pling as it has factor 3):
|
38
|
+
AssertEqual 'Pling', Raindrops(27)
|
39
|
+
|
40
|
+
Execute (the sound for 35 is PlangPlong as it has factors 5 and 7):
|
41
|
+
AssertEqual 'PlangPlong', Raindrops(35)
|
42
|
+
|
43
|
+
Execute (the sound for 49 is Plong as it has factor 7):
|
44
|
+
AssertEqual 'Plong', Raindrops(49)
|
45
|
+
|
46
|
+
Execute (the sound for 52 is 52):
|
47
|
+
AssertEqual '52', Raindrops(52)
|
48
|
+
|
49
|
+
Execute (the sound for 105 is PlingPlangPlong as it has factors 3, 5 and 7):
|
50
|
+
AssertEqual 'PlingPlangPlong', Raindrops(105)
|
51
|
+
|
52
|
+
Execute (the sound for 3125 is Plang as it has factor 5):
|
53
|
+
AssertEqual 'Plang', Raindrops(3125)
|
@@ -0,0 +1,18 @@
|
|
1
|
+
"
|
2
|
+
" Convert a number to a string, the contents of which depend on the number's
|
3
|
+
" factors.
|
4
|
+
"
|
5
|
+
" - If the number has 3 as a factor, output 'Pling'.
|
6
|
+
" - If the number has 5 as a factor, output 'Plang'.
|
7
|
+
" - If the number has 7 as a factor, output 'Plong'.
|
8
|
+
" - If the number does not have 3, 5, or 7 as a factor, just pass
|
9
|
+
" the number's digits straight through.
|
10
|
+
"
|
11
|
+
" Example:
|
12
|
+
"
|
13
|
+
" :echo Raindrops(15)
|
14
|
+
" PlingPlang
|
15
|
+
"
|
16
|
+
function! Raindrops(number) abort
|
17
|
+
" your solution goes here
|
18
|
+
endfunction
|
@@ -0,0 +1,23 @@
|
|
1
|
+
Execute (complement of cytosine is guanine):
|
2
|
+
AssertEqual 'G', OfDNA('C')
|
3
|
+
|
4
|
+
Execute (complement of guanine is cytosine):
|
5
|
+
AssertEqual 'C', OfDNA('G')
|
6
|
+
|
7
|
+
Execute (complement of thymine is adenine):
|
8
|
+
AssertEqual 'A', OfDNA('T')
|
9
|
+
|
10
|
+
Execute (complement of adenine is uracil):
|
11
|
+
AssertEqual 'U', OfDNA('A')
|
12
|
+
|
13
|
+
Execute (rna complement):
|
14
|
+
AssertEqual 'UGCACCAGAAUU', OfDNA('ACGTGGTCTTAA')
|
15
|
+
|
16
|
+
Execute (dna correctly handles invalid input):
|
17
|
+
AssertEqual '', OfDNA('U')
|
18
|
+
|
19
|
+
Execute (dna correctly handles completely invalid input):
|
20
|
+
AssertEqual '', OfDNA('XXX')
|
21
|
+
|
22
|
+
Execute (dna correctly handles partially invalid input):
|
23
|
+
AssertEqual '', OfDNA('ACGTXXXCTAA')
|