trackler 2.0.6.10 → 2.0.6.11

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.
Files changed (80) hide show
  1. checksums.yaml +4 -4
  2. data/common/exercises/circular-buffer/canonical-data.json +343 -0
  3. data/common/exercises/luhn/description.md +4 -1
  4. data/common/exercises/secret-handshake/canonical-data.json +67 -0
  5. data/common/exercises/secret-handshake/description.md +6 -8
  6. data/common/exercises/variable-length-quantity/canonical-data.json +147 -0
  7. data/lib/trackler/version.rb +1 -1
  8. data/tracks/ceylon/.gitignore +1 -0
  9. data/tracks/ceylon/.travis.yml +6 -1
  10. data/tracks/ceylon/README.md +143 -4
  11. data/tracks/ceylon/bin/test-all-exercises +13 -0
  12. data/tracks/ceylon/bin/test-exercise +30 -0
  13. data/tracks/ceylon/config.json +33 -3
  14. data/tracks/ceylon/{SETUP.md → exercises/TRACK_HINTS.md} +0 -0
  15. data/tracks/ceylon/exercises/anagram/example/Anagram.ceylon +8 -0
  16. data/tracks/ceylon/exercises/anagram/source/anagram/Anagram.ceylon +3 -0
  17. data/tracks/ceylon/exercises/anagram/source/anagram/AnagramTest.ceylon +47 -0
  18. data/tracks/ceylon/exercises/anagram/source/anagram/module.ceylon +3 -0
  19. data/tracks/ceylon/exercises/bracket-push/example/Brackets.ceylon +18 -0
  20. data/tracks/ceylon/exercises/bracket-push/example/module.ceylon +4 -0
  21. data/tracks/ceylon/exercises/bracket-push/source/bracketpush/Brackets.ceylon +3 -0
  22. data/tracks/ceylon/exercises/bracket-push/source/bracketpush/BracketsTest.ceylon +37 -0
  23. data/tracks/ceylon/exercises/bracket-push/source/bracketpush/module.ceylon +3 -0
  24. data/tracks/ceylon/exercises/leap/example/Leap.ceylon +3 -0
  25. data/tracks/ceylon/exercises/leap/source/leap/Leap.ceylon +3 -0
  26. data/tracks/ceylon/exercises/leap/source/leap/LeapTest.ceylon +10 -0
  27. data/tracks/ceylon/exercises/leap/source/leap/module.ceylon +3 -0
  28. data/tracks/ceylon/exercises/sieve/example/Sieve.ceylon +24 -0
  29. data/tracks/ceylon/exercises/sieve/example/module.ceylon +4 -0
  30. data/tracks/ceylon/exercises/sieve/source/sieve/Sieve.ceylon +3 -0
  31. data/tracks/ceylon/exercises/sieve/source/sieve/SieveTest.ceylon +23 -0
  32. data/tracks/ceylon/exercises/sieve/source/sieve/module.ceylon +3 -0
  33. data/tracks/csharp/.travis.yml +4 -0
  34. data/tracks/elm/SETUP.md +5 -4
  35. data/tracks/fsharp/.travis.yml +4 -0
  36. data/tracks/go/config.json +6 -2
  37. data/tracks/go/exercises/luhn/example.go +5 -4
  38. data/tracks/go/exercises/luhn/luhn_test.go +18 -34
  39. data/tracks/java/exercises/word-count/src/test/java/WordCountTest.java +10 -13
  40. data/tracks/lua/docs/ABOUT.md +1 -1
  41. data/tracks/lua/docs/LEARNING.md +1 -0
  42. data/tracks/lua/docs/RESOURCES.md +6 -1
  43. data/tracks/lua/exercises/flatten-array/flatten-array_spec.lua +11 -0
  44. data/tracks/lua/exercises/luhn/example.lua +11 -27
  45. data/tracks/lua/exercises/luhn/luhn_spec.lua +12 -39
  46. data/tracks/ocaml/exercises/all-your-base/all_your_base.mli +0 -2
  47. data/tracks/ocaml/exercises/bracket-push/bracket_push.mli +0 -2
  48. data/tracks/ocaml/exercises/luhn/example.ml +12 -16
  49. data/tracks/ocaml/exercises/luhn/luhn.mli +1 -2
  50. data/tracks/ocaml/exercises/luhn/test.ml +15 -12
  51. data/tracks/php/config.json +8 -0
  52. data/tracks/php/exercises/grains/example.php +63 -0
  53. data/tracks/php/exercises/grains/grains_test.php +82 -0
  54. data/tracks/pony/config.json +26 -14
  55. data/tracks/pony/exercises/anagram/example.pony +17 -73
  56. data/tracks/pony/exercises/anagram/test.pony +6 -13
  57. data/tracks/pony/exercises/bob/example.pony +24 -24
  58. data/tracks/pony/exercises/bob/test.pony +16 -34
  59. data/tracks/pony/exercises/difference-of-squares/example.pony +13 -25
  60. data/tracks/pony/exercises/difference-of-squares/test.pony +9 -16
  61. data/tracks/pony/exercises/hamming/example.pony +8 -23
  62. data/tracks/pony/exercises/hamming/test.pony +16 -30
  63. data/tracks/pony/exercises/hello-world/example.pony +3 -9
  64. data/tracks/pony/exercises/hello-world/test.pony +2 -11
  65. data/tracks/pony/exercises/leap/example.pony +4 -10
  66. data/tracks/pony/exercises/leap/test.pony +2 -11
  67. data/tracks/ruby/lib/generator/command_line.rb +5 -6
  68. data/tracks/ruby/lib/generator/repository.rb +13 -13
  69. data/tracks/ruby/lib/tasks/exercise_test_tasks.rb +2 -4
  70. data/tracks/ruby/lib/tasks/exercise_tests_runner.rb +6 -8
  71. data/tracks/ruby/test/generator/repository_test.rb +26 -34
  72. data/tracks/rust/README.md +1 -1
  73. data/tracks/scheme/config.json +5 -0
  74. data/tracks/scheme/docs/ABOUT.md +7 -0
  75. data/tracks/scheme/exercises/scrabble-score/example.scm +16 -0
  76. data/tracks/scheme/exercises/scrabble-score/scrabble-score-test.scm +57 -0
  77. data/tracks/scheme/exercises/scrabble-score/scrabble-score.scm +2 -0
  78. metadata +33 -5
  79. data/tracks/ceylon/exercises/.keep +0 -0
  80. data/tracks/ceylon/img/.keep +0 -0
@@ -1,51 +1,24 @@
1
- local Luhn = require('luhn')
1
+ local luhn = require('luhn')
2
2
 
3
3
  describe('luhn', function()
4
- it('should give the last digit of a number as the check digit', function()
5
- assert.equal(7, Luhn.new('34567'):check_digit())
6
- assert.equal(0, Luhn.new('91370'):check_digit())
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 determine the addends of a value', function()
10
- local luhn = Luhn.new('12121')
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 subtract 9 from any addends >9', function()
15
- local luhn = Luhn.new('8631')
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 calculate the checksum of a number by summing the addends', function()
20
- assert.equal(22, Luhn.new('4913'):checksum())
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 indicate that a number with a checksum indivisible by 0 is not valid', function()
25
- local luhn = Luhn.new('738')
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,5 +1,3 @@
1
- open Core.Std
2
-
3
1
  type base = int
4
2
 
5
3
  val convert_bases : from: base -> digits: int list -> target: base -> (int list) option
@@ -1,3 +1 @@
1
- open Core.Std
2
-
3
1
  val are_balanced : string -> bool
@@ -1,20 +1,16 @@
1
1
  open Core.Std
2
2
 
3
- let digit character =
4
- (int_of_char character) - 48
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
- (checksum s) mod 10 = 0
17
-
18
- let add_check_digit s =
19
- let check = ((sum_digits s 0 2 (String.length s)) mod 10) in
20
- String.concat ~sep:"" [s; (string_of_int ((10 - check) mod 10))]
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
@@ -1,3 +1,2 @@
1
- val checksum: string -> int
1
+ (* Returns true if the input is a valid Luhn string *)
2
2
  val valid : string -> bool
3
- val add_check_digit: string -> string
@@ -2,20 +2,23 @@ open Core.Std
2
2
  open OUnit2
3
3
  open Luhn
4
4
 
5
- let ae exp got _test_ctxt = assert_equal exp got
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
- "checksum of 4913" >:: ae 22 (checksum "4913");
9
- "checksum of 201773" >:: ae 21 (checksum "201773");
10
- "invalid number 1111" >:: ae false (valid "1111");
11
- "invalid number 738" >:: ae false (valid "738");
12
- "valid number 8739567" >:: ae true (valid "8739567");
13
- "valid number 8763" >:: ae true (valid "8763");
14
- "valid number long" >:: ae true (valid "2323200577663554");
15
- "create valid number" >:: ae "1230" (add_check_digit "123");
16
- "create large valid number" >:: ae "8739567" (add_check_digit "873956");
17
- "even larger valid number" >:: ae "8372637564" (add_check_digit "837263756");
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)
@@ -307,6 +307,14 @@
307
307
  "slug": "markdown",
308
308
  "difficulty": 3,
309
309
  "topics": ["refactoring"]
310
+ },
311
+ {
312
+ "slug": "grains",
313
+ "difficulty": 3,
314
+ "topics": [
315
+ "Floating-point numbers",
316
+ "Algorithms"
317
+ ]
310
318
  }
311
319
  ]
312
320
  }
@@ -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
+ }
@@ -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 "ponytest"
2
-
3
- class Anagram
4
-
5
- fun apply(word: String, phrase: Array[String]): Array[String] ? =>
6
- let anagrams: Array[String] = Array[String]
7
- let word_array: Array[U8] = _to_array_and_order(word.lower())
8
-
9
-
10
- for (index, value) in phrase.pairs() do
11
- let value_array: Array[U8] = _to_array_and_order(value.lower())
12
-
13
- if value.size() != word.size() then continue end
14
- if value.lower() == word.lower() then continue end
15
- if _check_array_eq(word_array, value_array) then
16
- anagrams.push(value)
17
- end
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)