trackler 2.0.6.10 → 2.0.6.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/common/exercises/circular-buffer/canonical-data.json +343 -0
- data/common/exercises/luhn/description.md +4 -1
- data/common/exercises/secret-handshake/canonical-data.json +67 -0
- data/common/exercises/secret-handshake/description.md +6 -8
- data/common/exercises/variable-length-quantity/canonical-data.json +147 -0
- data/lib/trackler/version.rb +1 -1
- data/tracks/ceylon/.gitignore +1 -0
- data/tracks/ceylon/.travis.yml +6 -1
- data/tracks/ceylon/README.md +143 -4
- data/tracks/ceylon/bin/test-all-exercises +13 -0
- data/tracks/ceylon/bin/test-exercise +30 -0
- data/tracks/ceylon/config.json +33 -3
- data/tracks/ceylon/{SETUP.md → exercises/TRACK_HINTS.md} +0 -0
- data/tracks/ceylon/exercises/anagram/example/Anagram.ceylon +8 -0
- data/tracks/ceylon/exercises/anagram/source/anagram/Anagram.ceylon +3 -0
- data/tracks/ceylon/exercises/anagram/source/anagram/AnagramTest.ceylon +47 -0
- data/tracks/ceylon/exercises/anagram/source/anagram/module.ceylon +3 -0
- data/tracks/ceylon/exercises/bracket-push/example/Brackets.ceylon +18 -0
- data/tracks/ceylon/exercises/bracket-push/example/module.ceylon +4 -0
- data/tracks/ceylon/exercises/bracket-push/source/bracketpush/Brackets.ceylon +3 -0
- data/tracks/ceylon/exercises/bracket-push/source/bracketpush/BracketsTest.ceylon +37 -0
- data/tracks/ceylon/exercises/bracket-push/source/bracketpush/module.ceylon +3 -0
- data/tracks/ceylon/exercises/leap/example/Leap.ceylon +3 -0
- data/tracks/ceylon/exercises/leap/source/leap/Leap.ceylon +3 -0
- data/tracks/ceylon/exercises/leap/source/leap/LeapTest.ceylon +10 -0
- data/tracks/ceylon/exercises/leap/source/leap/module.ceylon +3 -0
- data/tracks/ceylon/exercises/sieve/example/Sieve.ceylon +24 -0
- data/tracks/ceylon/exercises/sieve/example/module.ceylon +4 -0
- data/tracks/ceylon/exercises/sieve/source/sieve/Sieve.ceylon +3 -0
- data/tracks/ceylon/exercises/sieve/source/sieve/SieveTest.ceylon +23 -0
- data/tracks/ceylon/exercises/sieve/source/sieve/module.ceylon +3 -0
- data/tracks/csharp/.travis.yml +4 -0
- data/tracks/elm/SETUP.md +5 -4
- data/tracks/fsharp/.travis.yml +4 -0
- data/tracks/go/config.json +6 -2
- data/tracks/go/exercises/luhn/example.go +5 -4
- data/tracks/go/exercises/luhn/luhn_test.go +18 -34
- data/tracks/java/exercises/word-count/src/test/java/WordCountTest.java +10 -13
- data/tracks/lua/docs/ABOUT.md +1 -1
- data/tracks/lua/docs/LEARNING.md +1 -0
- data/tracks/lua/docs/RESOURCES.md +6 -1
- data/tracks/lua/exercises/flatten-array/flatten-array_spec.lua +11 -0
- data/tracks/lua/exercises/luhn/example.lua +11 -27
- data/tracks/lua/exercises/luhn/luhn_spec.lua +12 -39
- data/tracks/ocaml/exercises/all-your-base/all_your_base.mli +0 -2
- data/tracks/ocaml/exercises/bracket-push/bracket_push.mli +0 -2
- data/tracks/ocaml/exercises/luhn/example.ml +12 -16
- data/tracks/ocaml/exercises/luhn/luhn.mli +1 -2
- data/tracks/ocaml/exercises/luhn/test.ml +15 -12
- data/tracks/php/config.json +8 -0
- data/tracks/php/exercises/grains/example.php +63 -0
- data/tracks/php/exercises/grains/grains_test.php +82 -0
- data/tracks/pony/config.json +26 -14
- data/tracks/pony/exercises/anagram/example.pony +17 -73
- data/tracks/pony/exercises/anagram/test.pony +6 -13
- data/tracks/pony/exercises/bob/example.pony +24 -24
- data/tracks/pony/exercises/bob/test.pony +16 -34
- data/tracks/pony/exercises/difference-of-squares/example.pony +13 -25
- data/tracks/pony/exercises/difference-of-squares/test.pony +9 -16
- data/tracks/pony/exercises/hamming/example.pony +8 -23
- data/tracks/pony/exercises/hamming/test.pony +16 -30
- data/tracks/pony/exercises/hello-world/example.pony +3 -9
- data/tracks/pony/exercises/hello-world/test.pony +2 -11
- data/tracks/pony/exercises/leap/example.pony +4 -10
- data/tracks/pony/exercises/leap/test.pony +2 -11
- data/tracks/ruby/lib/generator/command_line.rb +5 -6
- data/tracks/ruby/lib/generator/repository.rb +13 -13
- data/tracks/ruby/lib/tasks/exercise_test_tasks.rb +2 -4
- data/tracks/ruby/lib/tasks/exercise_tests_runner.rb +6 -8
- data/tracks/ruby/test/generator/repository_test.rb +26 -34
- data/tracks/rust/README.md +1 -1
- data/tracks/scheme/config.json +5 -0
- data/tracks/scheme/docs/ABOUT.md +7 -0
- data/tracks/scheme/exercises/scrabble-score/example.scm +16 -0
- data/tracks/scheme/exercises/scrabble-score/scrabble-score-test.scm +57 -0
- data/tracks/scheme/exercises/scrabble-score/scrabble-score.scm +2 -0
- metadata +33 -5
- data/tracks/ceylon/exercises/.keep +0 -0
- data/tracks/ceylon/img/.keep +0 -0
@@ -1,51 +1,24 @@
|
|
1
|
-
local
|
1
|
+
local luhn = require('luhn')
|
2
2
|
|
3
3
|
describe('luhn', function()
|
4
|
-
it('should
|
5
|
-
assert.equal(
|
6
|
-
assert.equal(
|
4
|
+
it('should indicate that single digits are invalid', function()
|
5
|
+
assert.equal(false, luhn.valid('1'))
|
6
|
+
assert.equal(false, luhn.valid('0'))
|
7
7
|
end)
|
8
8
|
|
9
|
-
it('should
|
10
|
-
|
11
|
-
assert.same({ 1, 4, 1, 4, 1 }, luhn:addends())
|
9
|
+
it('should check a valid Canadian SIN', function()
|
10
|
+
assert.equal(true, luhn.valid('046 454 286'))
|
12
11
|
end)
|
13
12
|
|
14
|
-
it('should
|
15
|
-
|
16
|
-
assert.same({ 7, 6, 6, 1 }, luhn:addends())
|
13
|
+
it('should check an invalid Canadian SIN', function()
|
14
|
+
assert.equal(false, luhn.valid('046 454 287'))
|
17
15
|
end)
|
18
16
|
|
19
|
-
it('should
|
20
|
-
assert.equal(
|
21
|
-
assert.equal(21, Luhn.new('201773'):checksum())
|
17
|
+
it('should check an invalid credit card', function()
|
18
|
+
assert.equal(false, luhn.valid('8273 1232 7352 0569'))
|
22
19
|
end)
|
23
20
|
|
24
|
-
it('should
|
25
|
-
|
26
|
-
assert.equal(false, luhn:valid())
|
27
|
-
end)
|
28
|
-
|
29
|
-
it('should indicate that a number with a checksum divisible by 0 is valid', function()
|
30
|
-
local luhn = Luhn.new('8739567')
|
31
|
-
assert.equal(true, luhn:valid())
|
32
|
-
end)
|
33
|
-
|
34
|
-
it('should create valid numbers by appending the correct check digit', function()
|
35
|
-
assert.equal('1230', Luhn.create('123'))
|
36
|
-
assert.equal('8739567', Luhn.create('873956'))
|
37
|
-
assert.equal('8372637564', Luhn.create('837263756'))
|
38
|
-
end)
|
39
|
-
|
40
|
-
it('should support extremely large input', function()
|
41
|
-
local luhn = Luhn.new('34598754109846124372104312349048732432143214732140498237142')
|
42
|
-
assert.equal(2, luhn:check_digit())
|
43
|
-
assert.equal(268, luhn:checksum())
|
44
|
-
assert.equal(false, luhn:valid())
|
45
|
-
|
46
|
-
assert.equal(
|
47
|
-
'345987541098461243721043123490487324321432147321404982371420',
|
48
|
-
Luhn.create('34598754109846124372104312349048732432143214732140498237142')
|
49
|
-
)
|
21
|
+
it('should not allow non-digits', function()
|
22
|
+
assert.equal(false, luhn.valid('a46 454 286'))
|
50
23
|
end)
|
51
24
|
end)
|
@@ -1,20 +1,16 @@
|
|
1
1
|
open Core.Std
|
2
2
|
|
3
|
-
let
|
4
|
-
|
5
|
-
|
6
|
-
let rec sum_digits s r c = function
|
7
|
-
| 0 -> r
|
8
|
-
| i ->
|
9
|
-
let d = c * (digit s.[i - 1]) in
|
10
|
-
sum_digits s (r + (d/10) + (d mod 10)) (3-c) (i-1)
|
11
|
-
|
12
|
-
let checksum s =
|
13
|
-
(sum_digits s 0 1 (String.length s))
|
3
|
+
let every_second_digit_doubled =
|
4
|
+
let double_digit n = let d = n * 2 in if d >= 10 then d - 9 else d in
|
5
|
+
List.rev_mapi ~f:(fun i -> if i % 2 = 1 then double_digit else Fn.id)
|
14
6
|
|
15
7
|
let valid s =
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
8
|
+
let s = String.filter s ~f:(fun ch -> ch <> ' ') in
|
9
|
+
if String.length s > 1
|
10
|
+
then
|
11
|
+
let checksum = String.to_list s
|
12
|
+
|> List.rev_map ~f:(fun ch -> Char.to_int ch - Char.to_int '0')
|
13
|
+
|> every_second_digit_doubled
|
14
|
+
|> List.sum (module Int) ~f:Fn.id in
|
15
|
+
checksum % 10 = 0
|
16
|
+
else false
|
@@ -2,20 +2,23 @@ open Core.Std
|
|
2
2
|
open OUnit2
|
3
3
|
open Luhn
|
4
4
|
|
5
|
-
let
|
5
|
+
let assert_valid expected input _test_ctxt =
|
6
|
+
assert_equal ~printer:Bool.to_string expected (valid input)
|
6
7
|
|
7
8
|
let tests = [
|
8
|
-
"
|
9
|
-
|
10
|
-
"
|
11
|
-
|
12
|
-
"valid
|
13
|
-
|
14
|
-
"
|
15
|
-
|
16
|
-
"
|
17
|
-
|
9
|
+
"single digit strings are not valid" >::
|
10
|
+
assert_valid false "1";
|
11
|
+
"A single zero is invalid" >::
|
12
|
+
assert_valid false "0";
|
13
|
+
"valid Canadian SIN" >::
|
14
|
+
assert_valid true "046 454 286";
|
15
|
+
"invalid Canadian SIN" >::
|
16
|
+
assert_valid false "046 454 287";
|
17
|
+
"invalid credit card" >::
|
18
|
+
assert_valid false "8273 1232 7352 0569";
|
19
|
+
"strings that contain non-digits are not valid" >::
|
20
|
+
assert_valid false "827a 1232 7352 0569";
|
18
21
|
]
|
19
22
|
|
20
23
|
let () =
|
21
|
-
run_test_tt_main ("luhn tests" >::: tests)
|
24
|
+
run_test_tt_main ("luhn tests" >::: tests)
|
data/tracks/php/config.json
CHANGED
@@ -0,0 +1,63 @@
|
|
1
|
+
<?php
|
2
|
+
|
3
|
+
/**
|
4
|
+
*
|
5
|
+
Here is the simplest solution. But King hates floats.
|
6
|
+
|
7
|
+
function square($n)
|
8
|
+
{
|
9
|
+
if ($n < 1 || $n > 64) {
|
10
|
+
throw new InvalidArgumentException();
|
11
|
+
}
|
12
|
+
return pow(2, $n - 1);
|
13
|
+
}
|
14
|
+
|
15
|
+
function total()
|
16
|
+
{
|
17
|
+
return array_reduce(range(1, 64), function ($acc, $n) {
|
18
|
+
return $acc += square($n);
|
19
|
+
});
|
20
|
+
}
|
21
|
+
*/
|
22
|
+
|
23
|
+
function square($n)
|
24
|
+
{
|
25
|
+
if ($n < 1 || $n > 64) {
|
26
|
+
throw new InvalidArgumentException();
|
27
|
+
}
|
28
|
+
|
29
|
+
$result = [1];
|
30
|
+
for ($i = $n - 1; $i > 0; $i--) {
|
31
|
+
$result = sum($result, $result);
|
32
|
+
}
|
33
|
+
|
34
|
+
return implode('', array_reverse($result));
|
35
|
+
}
|
36
|
+
|
37
|
+
function total()
|
38
|
+
{
|
39
|
+
return implode('', array_reverse(
|
40
|
+
array_reduce(range(1, 64), function ($acc, $n) {
|
41
|
+
return sum($acc, array_reverse(str_split(square($n))));
|
42
|
+
}, [])
|
43
|
+
));
|
44
|
+
}
|
45
|
+
|
46
|
+
function sum($x, $y)
|
47
|
+
{
|
48
|
+
$shift = 0;
|
49
|
+
$result = array_map(function ($a, $b) use (&$shift) {
|
50
|
+
$value = $a + $b + $shift;
|
51
|
+
if ($value >= 10) {
|
52
|
+
$value -= 10;
|
53
|
+
$shift = 1;
|
54
|
+
} else {
|
55
|
+
$shift = 0;
|
56
|
+
}
|
57
|
+
return $value;
|
58
|
+
}, $x, $y);
|
59
|
+
if ($shift) {
|
60
|
+
array_push($result, $shift);
|
61
|
+
}
|
62
|
+
return $result;
|
63
|
+
}
|
@@ -0,0 +1,82 @@
|
|
1
|
+
<?php
|
2
|
+
|
3
|
+
include_once 'grains.php';
|
4
|
+
|
5
|
+
class GrainsTest extends PHPUnit_Framework_TestCase
|
6
|
+
{
|
7
|
+
/**
|
8
|
+
* PHP integers greater than 2^31 (32-bit systems)
|
9
|
+
* or 2^63 (64-bit) are casted to floats.
|
10
|
+
* In some cases it may lead to problems
|
11
|
+
* http://php.net/manual/ru/language.types.float.php#warn.float-precision
|
12
|
+
*
|
13
|
+
* Consider King hates floats and demands solution with
|
14
|
+
* precise integer-only calculations. Don't involve any floats.
|
15
|
+
* Don't use gmp or any other similar libraries.
|
16
|
+
* Try to make the solution for virtually any board size.
|
17
|
+
*/
|
18
|
+
|
19
|
+
public function testInput1()
|
20
|
+
{
|
21
|
+
$this->assertSame('1', square(1));
|
22
|
+
}
|
23
|
+
|
24
|
+
public function testInput2()
|
25
|
+
{
|
26
|
+
$this->assertSame('2', square(2));
|
27
|
+
}
|
28
|
+
|
29
|
+
public function testInput3()
|
30
|
+
{
|
31
|
+
$this->assertSame('4', square(3));
|
32
|
+
}
|
33
|
+
|
34
|
+
public function testInput4()
|
35
|
+
{
|
36
|
+
$this->assertSame('8', square(4));
|
37
|
+
}
|
38
|
+
|
39
|
+
public function testInput16()
|
40
|
+
{
|
41
|
+
$this->assertSame('32768', square(16));
|
42
|
+
}
|
43
|
+
|
44
|
+
public function testInput32()
|
45
|
+
{
|
46
|
+
$this->assertSame('2147483648', square(32));
|
47
|
+
}
|
48
|
+
|
49
|
+
public function testInput64()
|
50
|
+
{
|
51
|
+
$this->assertSame('9223372036854775808', square(64));
|
52
|
+
}
|
53
|
+
|
54
|
+
/**
|
55
|
+
* @expectedException InvalidArgumentException
|
56
|
+
*/
|
57
|
+
public function testRejectsZero()
|
58
|
+
{
|
59
|
+
square(0);
|
60
|
+
}
|
61
|
+
|
62
|
+
/**
|
63
|
+
* @expectedException InvalidArgumentException
|
64
|
+
*/
|
65
|
+
public function testRejectsNegative()
|
66
|
+
{
|
67
|
+
square(-1);
|
68
|
+
}
|
69
|
+
|
70
|
+
/**
|
71
|
+
* @expectedException InvalidArgumentException
|
72
|
+
*/
|
73
|
+
public function testRejectsGreaterThan64()
|
74
|
+
{
|
75
|
+
square(65);
|
76
|
+
}
|
77
|
+
|
78
|
+
public function testTotal()
|
79
|
+
{
|
80
|
+
$this->assertSame('18446744073709551615', total());
|
81
|
+
}
|
82
|
+
}
|
data/tracks/pony/config.json
CHANGED
@@ -3,53 +3,65 @@
|
|
3
3
|
"language": "Pony",
|
4
4
|
"repository": "https://github.com/exercism/xpony",
|
5
5
|
"active": false,
|
6
|
-
"test_pattern": "TODO",
|
7
|
-
"deprecated": [
|
8
|
-
|
9
|
-
],
|
10
6
|
"ignored": [
|
11
7
|
"bin",
|
12
8
|
"docs",
|
13
9
|
"img"
|
14
|
-
],
|
15
|
-
"foregone": [
|
16
|
-
|
17
10
|
],
|
18
11
|
"exercises": [
|
19
12
|
{
|
20
13
|
"difficulty": 1,
|
21
14
|
"slug": "hello-world",
|
22
|
-
"topics": [
|
15
|
+
"topics": [
|
16
|
+
"strings",
|
17
|
+
"default arguments"
|
18
|
+
]
|
23
19
|
},
|
24
20
|
{
|
25
21
|
"difficulty": 1,
|
26
22
|
"slug": "difference-of-squares",
|
27
|
-
"topics": [
|
23
|
+
"topics": [
|
24
|
+
"iterators"
|
25
|
+
]
|
28
26
|
},
|
29
27
|
{
|
30
28
|
"difficulty": 1,
|
31
29
|
"slug": "bob",
|
32
|
-
"topics": [
|
30
|
+
"topics": [
|
31
|
+
"strings"
|
32
|
+
]
|
33
33
|
},
|
34
34
|
{
|
35
35
|
"difficulty": 1,
|
36
36
|
"slug": "hamming",
|
37
|
-
"topics": [
|
37
|
+
"topics": [
|
38
|
+
"errors"
|
39
|
+
]
|
38
40
|
},
|
39
41
|
{
|
40
42
|
"difficulty": 1,
|
41
43
|
"slug": "leap",
|
42
|
-
"topics": [
|
44
|
+
"topics": [
|
45
|
+
"math",
|
46
|
+
"booleans"
|
47
|
+
]
|
43
48
|
},
|
44
49
|
{
|
45
50
|
"difficulty": 1,
|
46
51
|
"slug": "anagram",
|
47
|
-
"topics": [
|
52
|
+
"topics": [
|
53
|
+
"reference capabilities",
|
54
|
+
"strings"
|
55
|
+
]
|
48
56
|
},
|
49
57
|
{
|
50
58
|
"difficulty": 1,
|
51
59
|
"slug": "rna-transcription",
|
52
|
-
"topics": [
|
60
|
+
"topics": [
|
61
|
+
"strings",
|
62
|
+
"errors",
|
63
|
+
"iterators"
|
64
|
+
]
|
53
65
|
}
|
54
66
|
]
|
55
67
|
}
|
@@ -1,73 +1,17 @@
|
|
1
|
-
use "
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
fun apply(word: String, phrase: Array[String]): Array[String]
|
6
|
-
let
|
7
|
-
let
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
end
|
19
|
-
|
20
|
-
anagrams
|
21
|
-
|
22
|
-
fun _to_array_and_order(word: String): Array[U8] ? =>
|
23
|
-
// As of right now the String.split() function doesn't appear to work
|
24
|
-
// on no delimiter, i.e. "abcd".split("") to ["a", "b", "c", "d"]
|
25
|
-
// So I pull of the bytes
|
26
|
-
|
27
|
-
let word_array: Array[U8] = Array[U8]
|
28
|
-
let sorted_array: Array[U8] = Array[U8]
|
29
|
-
|
30
|
-
for value in word.values() do
|
31
|
-
word_array.push(value)
|
32
|
-
end
|
33
|
-
|
34
|
-
|
35
|
-
for (index, value) in word_array.pairs() do
|
36
|
-
var inserted = false
|
37
|
-
if (index == 0) then sorted_array.push(value) end
|
38
|
-
if (index > 0) then
|
39
|
-
for (i, v) in sorted_array.pairs() do
|
40
|
-
if value <= v then
|
41
|
-
sorted_array.insert(i, value)
|
42
|
-
inserted = true
|
43
|
-
break
|
44
|
-
end
|
45
|
-
end
|
46
|
-
if not inserted then
|
47
|
-
sorted_array.push(value)
|
48
|
-
inserted = false
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
sorted_array
|
54
|
-
|
55
|
-
// https://github.com/ponylang/ponyc/blob/master/packages/ponytest/helper.pony#L163-L188
|
56
|
-
// there isn't a join function as of 2.1, and Array doesn't support eq()
|
57
|
-
fun _check_array_eq(expect: Array[U8], actual: Array[U8]): Bool ? =>
|
58
|
-
var ok = true
|
59
|
-
|
60
|
-
if expect.size() != actual.size() then
|
61
|
-
ok = false
|
62
|
-
else
|
63
|
-
var i: USize = 0
|
64
|
-
while i < expect.size() do
|
65
|
-
if expect(i) != actual(i) then
|
66
|
-
ok = false
|
67
|
-
break
|
68
|
-
end
|
69
|
-
|
70
|
-
i = i + 1
|
71
|
-
end
|
72
|
-
end
|
73
|
-
ok
|
1
|
+
use "collections"
|
2
|
+
use "itertools"
|
3
|
+
|
4
|
+
primitive Anagram
|
5
|
+
fun apply(word: String, phrase: Array[String]): Array[String] =>
|
6
|
+
let lower: String = word.lower()
|
7
|
+
let sorted = _strsort(lower)
|
8
|
+
|
9
|
+
Iter[String](phrase.values())
|
10
|
+
.filter({(s: String)(lower, sorted): Bool =>
|
11
|
+
let lower': String = s.lower()
|
12
|
+
(lower != lower') and (sorted == Anagram._strsort(lower'))
|
13
|
+
})
|
14
|
+
.collect[Array[String] iso](recover Array[String] end)
|
15
|
+
|
16
|
+
fun _strsort(s: String): String =>
|
17
|
+
String.from_array(recover Sort[Array[U8], U8](s.array().clone()) end)
|