trackler 2.2.1.57 → 2.2.1.58

Sign up to get free protection for your applications and to get access to all the features.
Files changed (141) hide show
  1. checksums.yaml +4 -4
  2. data/lib/trackler/version.rb +1 -1
  3. data/problem-specifications/exercises/custom-set/canonical-data.json +8 -1
  4. data/tracks/c/README.md +2 -44
  5. data/tracks/c/docs/CONTRIBUTING.md +93 -0
  6. data/tracks/c/docs/C_STYLE_GUIDE.md +1 -1
  7. data/tracks/clojure/config.json +27 -0
  8. data/tracks/clojure/exercises/accumulate/project.clj +1 -1
  9. data/tracks/clojure/exercises/acronym/project.clj +1 -1
  10. data/tracks/clojure/exercises/all-your-base/project.clj +1 -1
  11. data/tracks/clojure/exercises/allergies/project.clj +1 -1
  12. data/tracks/clojure/exercises/anagram/project.clj +1 -1
  13. data/tracks/clojure/exercises/atbash-cipher/project.clj +1 -1
  14. data/tracks/clojure/exercises/bank-account/project.clj +1 -1
  15. data/tracks/clojure/exercises/beer-song/project.clj +1 -1
  16. data/tracks/clojure/exercises/binary/project.clj +1 -1
  17. data/tracks/clojure/exercises/binary-search/project.clj +1 -1
  18. data/tracks/clojure/exercises/binary-search-tree/project.clj +1 -1
  19. data/tracks/clojure/exercises/bob/project.clj +1 -1
  20. data/tracks/clojure/exercises/bracket-push/project.clj +1 -1
  21. data/tracks/clojure/exercises/change/project.clj +1 -1
  22. data/tracks/clojure/exercises/clock/project.clj +1 -1
  23. data/tracks/clojure/exercises/collatz-conjecture/project.clj +1 -1
  24. data/tracks/clojure/exercises/complex-numbers/project.clj +1 -1
  25. data/tracks/clojure/exercises/crypto-square/project.clj +1 -1
  26. data/tracks/clojure/exercises/diamond/README.md +51 -0
  27. data/tracks/clojure/exercises/diamond/project.clj +4 -0
  28. data/tracks/clojure/exercises/diamond/src/example.clj +22 -0
  29. data/tracks/clojure/exercises/diamond/test/diamond_test.clj +79 -0
  30. data/tracks/clojure/exercises/difference-of-squares/project.clj +1 -1
  31. data/tracks/clojure/exercises/etl/project.clj +1 -1
  32. data/tracks/clojure/exercises/flatten-array/project.clj +1 -1
  33. data/tracks/clojure/exercises/gigasecond/project.clj +1 -1
  34. data/tracks/clojure/exercises/grade-school/project.clj +1 -1
  35. data/tracks/clojure/exercises/grains/project.clj +1 -1
  36. data/tracks/clojure/exercises/hamming/project.clj +1 -1
  37. data/tracks/clojure/exercises/hello-world/project.clj +1 -1
  38. data/tracks/clojure/exercises/hexadecimal/project.clj +1 -1
  39. data/tracks/clojure/exercises/isogram/project.clj +1 -1
  40. data/tracks/clojure/exercises/kindergarten-garden/project.clj +1 -1
  41. data/tracks/clojure/exercises/largest-series-product/project.clj +1 -1
  42. data/tracks/clojure/exercises/leap/project.clj +1 -1
  43. data/tracks/clojure/exercises/luhn/project.clj +1 -1
  44. data/tracks/clojure/exercises/meetup/project.clj +1 -1
  45. data/tracks/clojure/exercises/minesweeper/project.clj +1 -1
  46. data/tracks/clojure/exercises/nth-prime/project.clj +1 -1
  47. data/tracks/clojure/exercises/nucleotide-count/project.clj +1 -1
  48. data/tracks/clojure/exercises/octal/project.clj +1 -1
  49. data/tracks/clojure/exercises/pascals-triangle/project.clj +1 -1
  50. data/tracks/clojure/exercises/perfect-numbers/project.clj +1 -1
  51. data/tracks/clojure/exercises/phone-number/project.clj +1 -1
  52. data/tracks/clojure/exercises/pig-latin/project.clj +1 -1
  53. data/tracks/clojure/exercises/prime-factors/project.clj +1 -1
  54. data/tracks/clojure/exercises/protein-translation/README.md +40 -0
  55. data/tracks/clojure/exercises/protein-translation/project.clj +4 -0
  56. data/tracks/clojure/exercises/protein-translation/src/example.clj +19 -0
  57. data/tracks/clojure/exercises/protein-translation/test/protein_translation_test.clj +36 -0
  58. data/tracks/clojure/exercises/queen-attack/project.clj +1 -1
  59. data/tracks/clojure/exercises/raindrops/project.clj +1 -1
  60. data/tracks/clojure/exercises/rna-transcription/project.clj +1 -1
  61. data/tracks/clojure/exercises/robot-name/project.clj +1 -1
  62. data/tracks/clojure/exercises/robot-simulator/project.clj +1 -1
  63. data/tracks/clojure/exercises/roman-numerals/project.clj +1 -1
  64. data/tracks/clojure/exercises/rotational-cipher/project.clj +1 -1
  65. data/tracks/clojure/exercises/run-length-encoding/README.md +36 -0
  66. data/tracks/clojure/exercises/run-length-encoding/project.clj +4 -0
  67. data/tracks/clojure/exercises/run-length-encoding/src/example.clj +20 -0
  68. data/tracks/clojure/exercises/run-length-encoding/src/run_length_encoding.clj +11 -0
  69. data/tracks/clojure/exercises/run-length-encoding/test/run_length_encoding_test.clj +57 -0
  70. data/tracks/clojure/exercises/scrabble-score/project.clj +1 -1
  71. data/tracks/clojure/exercises/secret-handshake/project.clj +1 -1
  72. data/tracks/clojure/exercises/series/project.clj +1 -1
  73. data/tracks/clojure/exercises/sieve/project.clj +1 -1
  74. data/tracks/clojure/exercises/space-age/project.clj +1 -1
  75. data/tracks/clojure/exercises/spiral-matrix/project.clj +1 -1
  76. data/tracks/clojure/exercises/strain/project.clj +1 -1
  77. data/tracks/clojure/exercises/sublist/project.clj +1 -1
  78. data/tracks/clojure/exercises/sum-of-multiples/project.clj +1 -1
  79. data/tracks/clojure/exercises/triangle/project.clj +1 -1
  80. data/tracks/clojure/exercises/trinary/project.clj +1 -1
  81. data/tracks/clojure/exercises/word-count/project.clj +1 -1
  82. data/tracks/clojure/exercises/wordy/project.clj +1 -1
  83. data/tracks/clojure/project.clj +2 -2
  84. data/tracks/ecmascript/config.json +10 -15
  85. data/tracks/ecmascript/docs/TESTS.md +15 -0
  86. data/tracks/ecmascript/exercises/complex-numbers/README.md +68 -0
  87. data/tracks/ecmascript/exercises/complex-numbers/complex-numbers.spec.js +216 -0
  88. data/tracks/ecmascript/exercises/complex-numbers/example.js +43 -0
  89. data/tracks/ecmascript/exercises/{transpose → complex-numbers}/package.json +2 -2
  90. data/tracks/elixir/config.json +22 -1
  91. data/tracks/elixir/exercises/isbn-verifier/README.md +80 -0
  92. data/tracks/elixir/exercises/isbn-verifier/example.exs +36 -0
  93. data/tracks/elixir/exercises/isbn-verifier/isbn_verifier.exs +18 -0
  94. data/tracks/elixir/exercises/isbn-verifier/isbn_verifier_test.exs +75 -0
  95. data/tracks/elixir/exercises/spiral-matrix/README.md +65 -0
  96. data/tracks/elixir/exercises/spiral-matrix/example.exs +27 -0
  97. data/tracks/elixir/exercises/spiral-matrix/spiral.exs +9 -0
  98. data/tracks/elixir/exercises/spiral-matrix/spiral_test.exs +58 -0
  99. data/tracks/erlang/config.json +10 -0
  100. data/tracks/erlang/exercises/complex-numbers/HINTS.md +2 -0
  101. data/tracks/erlang/exercises/complex-numbers/README.md +85 -0
  102. data/tracks/erlang/exercises/complex-numbers/include/exercism.hrl +11 -0
  103. data/tracks/erlang/exercises/complex-numbers/rebar.config +30 -0
  104. data/tracks/erlang/exercises/complex-numbers/src/complex_numbers.app.src +9 -0
  105. data/tracks/erlang/exercises/complex-numbers/src/complex_numbers.erl +29 -0
  106. data/tracks/erlang/exercises/complex-numbers/src/example.erl +44 -0
  107. data/tracks/erlang/exercises/complex-numbers/test/complex_numbers_tests.erl +152 -0
  108. data/tracks/erlang/testgen/src/tgen.erl +1 -1
  109. data/tracks/erlang/testgen/src/tgen_complex-numbers.erl +75 -0
  110. data/tracks/java/config.json +10 -5
  111. data/tracks/javascript/config.json +13 -0
  112. data/tracks/javascript/exercises/isbn-verifier/README.md +66 -0
  113. data/tracks/javascript/exercises/isbn-verifier/example.js +24 -0
  114. data/tracks/javascript/exercises/isbn-verifier/isbn-verifier.spec.js +68 -0
  115. data/tracks/perl6/config/maintainers.json +4 -4
  116. data/tracks/perl6/config.json +21 -21
  117. data/tracks/php/README.md +1 -0
  118. data/tracks/python/config/maintainers.json +3 -3
  119. data/tracks/python/exercises/alphametics/alphametics_test.py +6 -6
  120. data/tracks/python/exercises/queen-attack/queen_attack_test.py +60 -40
  121. data/tracks/sml/config.json +13 -2
  122. data/tracks/sml/exercises/flatten-array/{HINTS.md → .meta/hints.md} +0 -0
  123. data/tracks/sml/exercises/nth-prime/{HINTS.md → .meta/hints.md} +0 -0
  124. data/tracks/sml/exercises/pig-latin/README.md +54 -0
  125. data/tracks/sml/exercises/pig-latin/example.sml +23 -0
  126. data/tracks/sml/exercises/pig-latin/pig-latin.sml +2 -0
  127. data/tracks/sml/exercises/pig-latin/test.sml +90 -0
  128. data/tracks/sml/exercises/pig-latin/testlib.sml +159 -0
  129. data/tracks/typescript/config.json +16 -0
  130. data/tracks/typescript/exercises/ocr-numbers/README.md +110 -0
  131. data/tracks/typescript/exercises/ocr-numbers/ocr-numbers.example.ts +92 -0
  132. data/tracks/typescript/exercises/ocr-numbers/ocr-numbers.test.ts +155 -0
  133. data/tracks/typescript/exercises/ocr-numbers/ocr-numbers.ts +3 -0
  134. data/tracks/typescript/exercises/ocr-numbers/package.json +36 -0
  135. data/tracks/typescript/exercises/ocr-numbers/tsconfig.json +22 -0
  136. data/tracks/typescript/exercises/ocr-numbers/tslint.json +127 -0
  137. data/tracks/typescript/exercises/ocr-numbers/yarn.lock +2624 -0
  138. metadata +55 -8
  139. data/tracks/ecmascript/exercises/transpose/README.md +0 -94
  140. data/tracks/ecmascript/exercises/transpose/example.js +0 -12
  141. data/tracks/ecmascript/exercises/transpose/transpose.spec.js +0 -67
@@ -0,0 +1,2 @@
1
+ You also need to implement a `equal/2` function. For this you can consider
2
+ two numbers as equal, when the difference of each component is less than 0.005.
@@ -0,0 +1,85 @@
1
+ # Complex Numbers
2
+
3
+ A complex number is a number in the form `a + b * i` where `a` and `b` are real and `i` satisfies `i^2 = -1`.
4
+
5
+ `a` is called the real part and `b` is called the imaginary part of `z`.
6
+ The conjugate of the number `a + b * i` is the number `a - b * i`.
7
+ The absolute value of a complex number `z = a + b * i` is a real number `|z| = sqrt(a^2 + b^2)`. The square of the absolute value `|z|^2` is the result of multiplication of `z` by its complex conjugate.
8
+
9
+ The sum/difference of two complex numbers involves adding/subtracting their real and imaginary parts separately:
10
+ `(a + i * b) + (c + i * d) = (a + c) + (b + d) * i`,
11
+ `(a + i * b) - (c + i * d) = (a - c) + (b - d) * i`.
12
+
13
+ Multiplication result is by definition
14
+ `(a + i * b) * (c + i * d) = (a * c - b * d) + (b * c + a * d) * i`.
15
+
16
+ The reciprocal of a non-zero complex number is
17
+ `1 / (a + i * b) = a/(a^2 + b^2) - b/(a^2 + b^2) * i`.
18
+
19
+ Dividing a complex number `a + i * b` by another `c + i * d` gives:
20
+ `(a + i * b) / (c + i * d) = (a * c + b * d)/(c^2 + d^2) + (b * c - a * d)/(c^2 + d^2) * i`.
21
+
22
+ Exponent of a complex number can be expressed as
23
+ `exp(a + i * b) = exp(a) * exp(i * b)`,
24
+ and the last term is given by Euler's formula `exp(i * b) = cos(b) + i * sin(b)`.
25
+
26
+
27
+ Implement the following operations:
28
+ - addition, subtraction, multiplication and division of two complex numbers,
29
+ - conjugate, absolute value, exponent of a given complex number.
30
+
31
+
32
+ Assume the programming language you are using does not have an implementation of complex numbers.
33
+
34
+ You also need to implement a `equal/2` function. For this you can consider
35
+ two numbers as equal, when the difference of each component is less than 0.005.
36
+
37
+
38
+ ## Running tests
39
+
40
+ In order to run the tests, issue the following command from the exercise
41
+ directory:
42
+
43
+ For running the tests provided, `rebar3` is used as it is the official build and
44
+ dependency management tool for erlang now. Please refer to [the tracks installation
45
+ instructions](http://exercism.io/languages/erlang/installation) on how to do that.
46
+
47
+ In order to run the tests, you can issue the following command from the exercise
48
+ directory.
49
+
50
+ ```bash
51
+ $ rebar3 eunit
52
+ ```
53
+
54
+ ### Test versioning
55
+
56
+ Each problem defines a macro `TEST_VERSION` in the test file and
57
+ verifies that the solution defines and exports a function `test_version`
58
+ returning that same value.
59
+
60
+ To make tests pass, add the following to your solution:
61
+
62
+ ```erlang
63
+ -export([test_version/0]).
64
+
65
+ test_version() ->
66
+ 1.
67
+ ```
68
+
69
+ The benefit of this is that reviewers can see against which test version
70
+ an iteration was written if, for example, a previously posted solution
71
+ does not solve the current problem or passes current tests.
72
+
73
+ ## Questions?
74
+
75
+ For detailed information about the Erlang track, please refer to the
76
+ [help page](http://exercism.io/languages/erlang) on the Exercism site.
77
+ This covers the basic information on setting up the development
78
+ environment expected by the exercises.
79
+
80
+ ## Source
81
+
82
+ Wikipedia [https://en.wikipedia.org/wiki/Complex_number](https://en.wikipedia.org/wiki/Complex_number)
83
+
84
+ ## Submitting Incomplete Solutions
85
+ It's possible to submit an incomplete solution so you can see how others have completed the exercise.
@@ -0,0 +1,11 @@
1
+ -include_lib("eunit/include/eunit.hrl").
2
+
3
+ sut(Module) ->
4
+ {ok, Files} = file:list_dir("./src"),
5
+ case lists:member("example.erl", Files) of
6
+ true -> example;
7
+ false -> Module
8
+ end.
9
+
10
+ version_test() ->
11
+ ?assertMatch(?TEST_VERSION, ?TESTED_MODULE:test_version()).
@@ -0,0 +1,30 @@
1
+ %% Erlang compiler options
2
+ {erl_opts, [debug_info]}.
3
+
4
+ {deps, []}.
5
+
6
+ {dialyzer, [
7
+ {warnings, [underspecs, no_return]},
8
+ {get_warnings, true},
9
+ {plt_apps, top_level_deps}, % top_level_deps | all_deps
10
+ {plt_extra_apps, []},
11
+ {plt_location, local}, % local | "/my/file/name"
12
+ {plt_prefix, "rebar3"},
13
+ {base_plt_apps, [stdlib, kernel, crypto]},
14
+ {base_plt_location, global}, % global | "/my/file/name"
15
+ {base_plt_prefix, "rebar3"}
16
+ ]}.
17
+
18
+ %% eunit:test(Tests)
19
+ {eunit_tests, []}.
20
+ %% Options for eunit:test(Tests, Opts)
21
+ {eunit_opts, [verbose]}.
22
+
23
+ %% == xref ==
24
+
25
+ {xref_warnings, true}.
26
+
27
+ %% xref checks to run
28
+ {xref_checks, [undefined_function_calls, undefined_functions,
29
+ locals_not_used, exports_not_used,
30
+ deprecated_function_calls, deprecated_functions]}.
@@ -0,0 +1,9 @@
1
+ {application, complex_numbers,
2
+ [{description, "exercism.io - complex-numbers"},
3
+ {vsn, "0.0.1"},
4
+ {modules, []},
5
+ {registered, []},
6
+ {applications, [kernel,
7
+ stdlib]},
8
+ {env, []}
9
+ ]}.
@@ -0,0 +1,29 @@
1
+ -module(complex_numbers).
2
+
3
+ -export([abs/1, add/2, conjugate/1, divide/2, equal/2, exp/1, imaginary/1, mul/2, new/2,
4
+ real/1, sub/2, test_version/0]).
5
+
6
+
7
+ abs(Z) -> undefined.
8
+
9
+ add(Z1, Z2) -> undefined.
10
+
11
+ conjugate(Z) -> undefined.
12
+
13
+ divide(Z1, Z2) -> undefined.
14
+
15
+ equal(Z1, Z2) -> undefined.
16
+
17
+ exp(Z) -> undefined.
18
+
19
+ imaginary(Z) -> undefined.
20
+
21
+ mul(Z1, Z2) -> undefined.
22
+
23
+ new(R, I) -> undefined.
24
+
25
+ real(Z) -> undefined.
26
+
27
+ sub(Z1, Z2) -> undefined.
28
+
29
+ test_version() -> 1.
@@ -0,0 +1,44 @@
1
+ -module(example).
2
+
3
+ -export([abs/1, add/2, conjugate/1, divide/2, equal/2, exp/1, imaginary/1, mul/2, new/2,
4
+ real/1, sub/2, test_version/0]).
5
+
6
+ -record(complex, {r = 0, i = 0}).
7
+
8
+ new(R, I) -> #complex{r = R, i = I}.
9
+
10
+ abs(#complex{r = A, i = B}) ->
11
+ erlang:abs(math:sqrt(A * A + B * B)).
12
+
13
+ add(#complex{r = A, i = B}, #complex{r = C, i = D}) ->
14
+ #complex{r = A + C, i = B + D}.
15
+
16
+ conjugate(#complex{r = A, i = B}) ->
17
+ #complex{r = A, i = -B}.
18
+
19
+ divide(#complex{r = A, i = B}, #complex{r = C, i = D}) ->
20
+ #complex{
21
+ r = (A * C + B * D) / (C * C + D * D),
22
+ i = (B * C - A * D) / (C * C + D * D)}.
23
+
24
+ equal(#complex{r = A, i = B}, #complex{r = C, i = D}) when erlang:abs(A - C) < 0.005, erlang:abs(B - D) < 0.005 -> true;
25
+ equal(X, Y) -> false.
26
+
27
+ exp(#complex{r = A, i = B}) ->
28
+ mul(
29
+ new(math:exp(A), 0),
30
+ new(math:cos(B), math:sin(B))).
31
+
32
+ imaginary(#complex{i = B}) ->
33
+ B.
34
+
35
+ mul(#complex{r = A, i = B}, #complex{r = C, i = D}) ->
36
+ #complex{r = A * C - B * D, i = B * C + A * D}.
37
+
38
+ real(#complex{r = A}) ->
39
+ A.
40
+
41
+ sub(#complex{r = A, i = B}, #complex{r = C, i = D}) ->
42
+ #complex{r = A - C, i = B - D}.
43
+
44
+ test_version() -> 1.
@@ -0,0 +1,152 @@
1
+ -module(complex_numbers_tests).
2
+
3
+ % This file is automatically generated from the exercises canonical data.
4
+
5
+ -define(TESTED_MODULE, (sut(complex_numbers))).
6
+ -define(TEST_VERSION, 1).
7
+ -include("exercism.hrl").
8
+
9
+
10
+ imaginary_unit_test() ->
11
+ ?assert(?TESTED_MODULE:equal(?TESTED_MODULE:new(-1, 0),
12
+ ?TESTED_MODULE:mul(?TESTED_MODULE:new(0, 1),
13
+ ?TESTED_MODULE:new(0, 1)))).
14
+
15
+ add_purely_real_numbers_test() ->
16
+ ?assert(?TESTED_MODULE:equal(?TESTED_MODULE:new(3, 0),
17
+ ?TESTED_MODULE:add(?TESTED_MODULE:new(1, 0),
18
+ ?TESTED_MODULE:new(2, 0)))).
19
+
20
+ add_purely_imaginary_numbers_test() ->
21
+ ?assert(?TESTED_MODULE:equal(?TESTED_MODULE:new(0, 3),
22
+ ?TESTED_MODULE:add(?TESTED_MODULE:new(0, 1),
23
+ ?TESTED_MODULE:new(0, 2)))).
24
+
25
+ add_numbers_with_real_and_imaginary_part_test() ->
26
+ ?assert(?TESTED_MODULE:equal(?TESTED_MODULE:new(4, 6),
27
+ ?TESTED_MODULE:add(?TESTED_MODULE:new(1, 2),
28
+ ?TESTED_MODULE:new(3, 4)))).
29
+
30
+ subtract_purely_real_numbers_test() ->
31
+ ?assert(?TESTED_MODULE:equal(?TESTED_MODULE:new(-1, 0),
32
+ ?TESTED_MODULE:sub(?TESTED_MODULE:new(1, 0),
33
+ ?TESTED_MODULE:new(2, 0)))).
34
+
35
+ subtract_purely_imaginary_numbers_test() ->
36
+ ?assert(?TESTED_MODULE:equal(?TESTED_MODULE:new(0, -1),
37
+ ?TESTED_MODULE:sub(?TESTED_MODULE:new(0, 1),
38
+ ?TESTED_MODULE:new(0, 2)))).
39
+
40
+ subtract_numbers_with_real_and_imaginary_part_test() ->
41
+ ?assert(?TESTED_MODULE:equal(?TESTED_MODULE:new(-2, -2),
42
+ ?TESTED_MODULE:sub(?TESTED_MODULE:new(1, 2),
43
+ ?TESTED_MODULE:new(3, 4)))).
44
+
45
+ multiply_purely_real_numbers_test() ->
46
+ ?assert(?TESTED_MODULE:equal(?TESTED_MODULE:new(2, 0),
47
+ ?TESTED_MODULE:mul(?TESTED_MODULE:new(1, 0),
48
+ ?TESTED_MODULE:new(2, 0)))).
49
+
50
+ multiply_purely_imaginary_numbers_test() ->
51
+ ?assert(?TESTED_MODULE:equal(?TESTED_MODULE:new(-2, 0),
52
+ ?TESTED_MODULE:mul(?TESTED_MODULE:new(0, 1),
53
+ ?TESTED_MODULE:new(0, 2)))).
54
+
55
+ multiply_numbers_with_real_and_imaginary_part_test() ->
56
+ ?assert(?TESTED_MODULE:equal(?TESTED_MODULE:new(-5, 10),
57
+ ?TESTED_MODULE:mul(?TESTED_MODULE:new(1, 2),
58
+ ?TESTED_MODULE:new(3, 4)))).
59
+
60
+ divide_purely_real_numbers_test() ->
61
+ ?assert(?TESTED_MODULE:equal(?TESTED_MODULE:new(5.0e-1,
62
+ 0),
63
+ ?TESTED_MODULE:divide(?TESTED_MODULE:new(1, 0),
64
+ ?TESTED_MODULE:new(2,
65
+ 0)))).
66
+
67
+ divide_purely_imaginary_numbers_test() ->
68
+ ?assert(?TESTED_MODULE:equal(?TESTED_MODULE:new(5.0e-1,
69
+ 0),
70
+ ?TESTED_MODULE:divide(?TESTED_MODULE:new(0, 1),
71
+ ?TESTED_MODULE:new(0,
72
+ 2)))).
73
+
74
+ divide_numbers_with_real_and_imaginary_part_test() ->
75
+ ?assert(?TESTED_MODULE:equal(?TESTED_MODULE:new(4.4e-1,
76
+ 8.0e-2),
77
+ ?TESTED_MODULE:divide(?TESTED_MODULE:new(1, 2),
78
+ ?TESTED_MODULE:new(3,
79
+ 4)))).
80
+
81
+ absolute_value_of_a_positive_purely_real_number_test() ->
82
+ ?assert(5 ==
83
+ ?TESTED_MODULE:abs(?TESTED_MODULE:new(5, 0))).
84
+
85
+ absolute_value_of_a_negative_purely_real_number_test() ->
86
+ ?assert(5 ==
87
+ ?TESTED_MODULE:abs(?TESTED_MODULE:new(-5, 0))).
88
+
89
+ absolute_value_of_a_purely_imaginary_number_with_positive_imaginary_part_test() ->
90
+ ?assert(5 ==
91
+ ?TESTED_MODULE:abs(?TESTED_MODULE:new(0, 5))).
92
+
93
+ absolute_value_of_a_purely_imaginary_number_with_negative_imaginary_part_test() ->
94
+ ?assert(5 ==
95
+ ?TESTED_MODULE:abs(?TESTED_MODULE:new(0, -5))).
96
+
97
+ absolute_value_of_a_number_with_real_and_imaginary_part_test() ->
98
+ ?assert(5 ==
99
+ ?TESTED_MODULE:abs(?TESTED_MODULE:new(3, 4))).
100
+
101
+ conjugate_a_purely_real_number_test() ->
102
+ ?assert(?TESTED_MODULE:equal(?TESTED_MODULE:new(5, 0),
103
+ ?TESTED_MODULE:conjugate(?TESTED_MODULE:new(5,
104
+ 0)))).
105
+
106
+ conjugate_a_purely_imaginary_number_test() ->
107
+ ?assert(?TESTED_MODULE:equal(?TESTED_MODULE:new(0, -5),
108
+ ?TESTED_MODULE:conjugate(?TESTED_MODULE:new(0,
109
+ 5)))).
110
+
111
+ conjugate_a_number_with_real_and_imaginary_part_test() ->
112
+ ?assert(?TESTED_MODULE:equal(?TESTED_MODULE:new(1, -1),
113
+ ?TESTED_MODULE:conjugate(?TESTED_MODULE:new(1,
114
+ 1)))).
115
+
116
+ real_part_of_a_purely_real_number_test() ->
117
+ ?assert(1 ==
118
+ ?TESTED_MODULE:real(?TESTED_MODULE:new(1, 0))).
119
+
120
+ real_part_of_a_purely_imaginary_number_test() ->
121
+ ?assert(0 ==
122
+ ?TESTED_MODULE:real(?TESTED_MODULE:new(0, 1))).
123
+
124
+ real_part_of_a_number_with_real_and_imaginary_part_test() ->
125
+ ?assert(1 ==
126
+ ?TESTED_MODULE:real(?TESTED_MODULE:new(1, 2))).
127
+
128
+ imaginary_part_of_a_purely_real_number_test() ->
129
+ ?assert(0 ==
130
+ ?TESTED_MODULE:imaginary(?TESTED_MODULE:new(1, 0))).
131
+
132
+ imaginary_part_of_a_purely_imaginary_number_test() ->
133
+ ?assert(1 ==
134
+ ?TESTED_MODULE:imaginary(?TESTED_MODULE:new(0, 1))).
135
+
136
+ imaginary_part_of_a_number_with_real_and_imaginary_part_test() ->
137
+ ?assert(2 ==
138
+ ?TESTED_MODULE:imaginary(?TESTED_MODULE:new(1, 2))).
139
+
140
+ eulers_identityformula_test() ->
141
+ ?assert(?TESTED_MODULE:equal(?TESTED_MODULE:new(-1, 0),
142
+ ?TESTED_MODULE:exp(?TESTED_MODULE:new(0,
143
+ 3.14159265358979311600)))).
144
+
145
+ exponential_of_0_test() ->
146
+ ?assert(?TESTED_MODULE:equal(?TESTED_MODULE:new(1, 0),
147
+ ?TESTED_MODULE:exp(?TESTED_MODULE:new(0, 0)))).
148
+
149
+ exponential_of_a_purely_real_number_test() ->
150
+ ?assert(?TESTED_MODULE:equal(?TESTED_MODULE:new(2.71828182845904509080,
151
+ 0),
152
+ ?TESTED_MODULE:exp(?TESTED_MODULE:new(1, 0)))).
@@ -137,7 +137,7 @@ generate_test_module(ModuleName, Tests, Version) ->
137
137
  tgs:define("TEST_VERSION", tgs:value(Version)),
138
138
  tgs:include("exercism.hrl"),
139
139
  nl,
140
- nl] ++ inter(nl, Tests),
140
+ nl] ++ inter(nl, lists:flatten(Tests)),
141
141
 
142
142
  {SluggedModName ++ "_tests", lists:flatten(
143
143
  lists:map(
@@ -0,0 +1,75 @@
1
+ -module('tgen_complex-numbers').
2
+
3
+ -behaviour(tgen).
4
+
5
+ -export([
6
+ available/0,
7
+ version/0,
8
+ generate_test/1
9
+ ]).
10
+
11
+ -spec available() -> true.
12
+ available() ->
13
+ true.
14
+
15
+ version() -> 1.
16
+
17
+ generate_test(F = #{description := Desc, cases := Cases}) ->
18
+ rewrap(lists:flatten(lists:map(fun generate_test/1, Cases)), {[], []});
19
+ generate_test(#{description := Desc, expected := Exp, property := Prop, input := Z}) when is_number(Exp) ->
20
+ TestName = tgen:to_test_name(Desc),
21
+ Property = binary_to_list(Prop),
22
+
23
+ Cplx = lists:map(fun to_num/1, Z),
24
+
25
+ Fn = tgs:simple_fun(TestName, [
26
+ tgs:call_macro("assert", [
27
+ erl_syntax:infix_expr(
28
+ tgs:value(Exp),
29
+ erl_syntax:operator("=="),
30
+ tgs:call_macro("TESTED_MODULE:" ++ Property, [
31
+ tgs:call_macro("TESTED_MODULE:new", lists:map(fun tgs:value/1, Cplx))]))])]),
32
+
33
+ {ok, Fn, [{Property, ["Z"]}]};
34
+ generate_test(#{description := Desc, expected := Exp, property := Prop, input := Z}) ->
35
+ TestName = tgen:to_test_name(Desc),
36
+ Property = binary_to_list(Prop),
37
+
38
+ Cplx = lists:map(fun to_num/1, Z),
39
+ Expected = lists:map(fun to_num/1, Exp),
40
+
41
+ Fn = tgs:simple_fun(TestName, [
42
+ tgs:call_macro("assert", [
43
+ tgs:call_macro("TESTED_MODULE:equal", [
44
+ tgs:call_macro("TESTED_MODULE:new", lists:map(fun tgs:value/1, Expected)),
45
+ tgs:call_macro("TESTED_MODULE:" ++ Property, [
46
+ tgs:call_macro("TESTED_MODULE:new", lists:map(fun tgs:value/1, Cplx))])])])]),
47
+
48
+ {ok, Fn, [{Property, ["Z"]}]};
49
+ generate_test(#{description := Desc, expected := Exp, property := <<"div">>, z1 := Z1, z2 := Z2}) ->
50
+ generate_test(#{description => Desc, expected => Exp, property => <<"divide">>, z1 => Z1, z2 => Z2});
51
+ generate_test(#{description := Desc, expected := Exp, property := Prop, z1 := Z1, z2 := Z2}) ->
52
+ TestName = tgen:to_test_name(Desc),
53
+ Property = binary_to_list(Prop),
54
+
55
+ Cplx1 = lists:map(fun to_num/1, Z1),
56
+ Cplx2 = lists:map(fun to_num/1, Z2),
57
+ Expected = lists:map(fun to_num/1, Exp),
58
+
59
+ Fn = tgs:simple_fun(TestName, [
60
+ tgs:call_macro("assert", [
61
+ tgs:call_macro("TESTED_MODULE:equal", [
62
+ tgs:call_macro("TESTED_MODULE:new", lists:map(fun tgs:value/1, Expected)),
63
+ tgs:call_macro("TESTED_MODULE:" ++ Property, [
64
+ tgs:call_macro("TESTED_MODULE:new", lists:map(fun tgs:value/1, Cplx1)),
65
+ tgs:call_macro("TESTED_MODULE:new", lists:map(fun tgs:value/1, Cplx2))])])])]),
66
+
67
+ {ok, Fn, [{Property, ["Z1", "Z2"]}, {"equal", ["Z1", "Z2"]}, {"new", ["R", "I"]}]}.
68
+
69
+ rewrap([], {Fns, Props}) -> {ok, lists:reverse(Fns), Props};
70
+ rewrap([{ok, Fn, Props}|Tail], {Fns, AccProps}) ->
71
+ rewrap(Tail, {[Fn|Fns], Props ++ AccProps}).
72
+
73
+ to_num(N) when is_number(N) -> N;
74
+ to_num(<<"pi">>) -> math:pi();
75
+ to_num(<<"e">>) -> math:exp(1).
@@ -919,10 +919,10 @@
919
919
  "slug": "ocr-numbers",
920
920
  "topics": [
921
921
  "exception_handling",
922
- "loops",
923
922
  "lists",
924
- "strings",
925
- "parsing"
923
+ "loops",
924
+ "parsing",
925
+ "strings"
926
926
  ],
927
927
  "unlocked_by": "robot-name",
928
928
  "uuid": "5cbc6a67-3a53-4aad-ae68-ff469525437f"
@@ -1039,7 +1039,12 @@
1039
1039
  "core": false,
1040
1040
  "difficulty": 9,
1041
1041
  "slug": "pythagorean-triplet",
1042
- "topics": null,
1042
+ "topics": [
1043
+ "integer",
1044
+ "lists",
1045
+ "logic",
1046
+ "mathematics"
1047
+ ],
1043
1048
  "unlocked_by": "triangle",
1044
1049
  "uuid": "88505f95-89e5-4a08-8ed2-208eb818cdf1"
1045
1050
  },
@@ -1108,4 +1113,4 @@
1108
1113
  ],
1109
1114
  "language": "Java",
1110
1115
  "solution_pattern": "reference"
1111
- }
1116
+ }
@@ -1135,6 +1135,19 @@
1135
1135
  "searching",
1136
1136
  "trees"
1137
1137
  ]
1138
+ },
1139
+ {
1140
+ "uuid": "8740af44-002c-4716-a759-a68ae4c68737",
1141
+ "slug": "isbn-verifier",
1142
+ "core": false,
1143
+ "unlocked_by": "bob",
1144
+ "difficulty": 4,
1145
+ "topics": [
1146
+ "conditionals",
1147
+ "loops",
1148
+ "pattern_matching",
1149
+ "strings"
1150
+ ]
1138
1151
  }
1139
1152
  ],
1140
1153
  "foregone": [],
@@ -0,0 +1,66 @@
1
+ # ISBN Verifier
2
+
3
+ Check if a given ISBN-10 is valid.
4
+
5
+ ## Functionality
6
+
7
+ Given an unknown string the program should check if the provided string is a valid ISBN-10.
8
+ Putting this into place requires some thinking about preprocessing/parsing of the string prior to calculating the check digit for the ISBN.
9
+
10
+ The program should allow for ISBN-10 without the separating dashes to be verified as well.
11
+
12
+ ## ISBN
13
+
14
+ Let's take a random ISBN-10 number, say `3-598-21508-8` for this.
15
+ The first digit block indicates the group where the ISBN belongs. Groups can consist of shared languages, geographic regions or countries. The leading '3' signals this ISBN is from a german speaking country.
16
+ The following number block is to identify the publisher. Since this is a three digit publisher number there is a 5 digit title number for this book.
17
+ The last digit in the ISBN is the check digit which is used to detect read errors.
18
+
19
+ The first 9 digits in the ISBN have to be between 0 and 9.
20
+ The check digit can additionally be an 'X' to allow 10 to be a valid check digit as well.
21
+
22
+ A valid ISBN-10 is calculated with this formula `(x1 * 10 + x2 * 9 + x3 * 8 + x4 * 7 + x5 * 6 + x6 * 5 + x7 * 4 + x8 * 3 + x9 * 2 + x10 * 1) mod 11 == 0`
23
+ So for our example ISBN this means:
24
+ (3 * 10 + 5 * 9 + 9 * 8 + 8 * 7 + 2 * 6 + 1 * 5 + 5 * 4 + 0 * 3 + 8 * 2 + 8 * 1) mod 11 = 0
25
+
26
+ Which proves that the ISBN is valid.
27
+
28
+ ## Setup
29
+
30
+ Go through the setup instructions for JavaScript to
31
+ install the necessary dependencies:
32
+
33
+ http://exercism.io/languages/javascript
34
+
35
+ ## Making the Test Suite Pass
36
+
37
+ Execute the tests with:
38
+
39
+ jasmine <exercise-name>.spec.js
40
+
41
+ Replace `<exercise-name>` with the name of the current exercise. E.g., to
42
+ test the Hello World exercise:
43
+
44
+ jasmine hello-world.spec.js
45
+
46
+ In many test suites all but the first test have been skipped.
47
+
48
+ Once you get a test passing, you can unskip the next one by
49
+ changing `xit` to `it`.
50
+
51
+ ### Submitting Exercises
52
+
53
+ Note that, when trying to submit an exercise, make sure the solution is in the `exercism/javascript/<exerciseName>` directory.
54
+
55
+ For example, if you're submitting `bob.js` for the Bob exercise, the submit command would be something like `exercism submit <path_to_exercism_dir>/javascript/bob/bob.js`.
56
+
57
+
58
+ For more detailed information about running tests, code style and linting,
59
+ please see the [help page](http://exercism.io/languages/javascript).
60
+
61
+ ## Source
62
+
63
+ Converting a string into a number and some basic processing utilizing a relatable real world example. [https://en.wikipedia.org/wiki/International_Standard_Book_Number#ISBN-10_check_digit_calculation](https://en.wikipedia.org/wiki/International_Standard_Book_Number)
64
+
65
+ ## Submitting Incomplete Solutions
66
+ It's possible to submit an incomplete solution so you can see how others have completed the exercise.
@@ -0,0 +1,24 @@
1
+ 'use strict';
2
+
3
+ function ISBN(isbn) {
4
+ this.isbn = isbn.replace(/-/g, '');
5
+
6
+ this.isValid = function () {
7
+ if (!this.isbn.match(/^(\d{9}[\dX])$/)) {
8
+ return false;
9
+ }
10
+
11
+ var digits = this.isbn.split('');
12
+ if (digits[9] === 'X') {
13
+ digits[9] = 10;
14
+ }
15
+
16
+ var sum = digits.reduce(function (total, current, index) {
17
+ return total + ((10 - index) * parseInt(current, 10));
18
+ }, 0);
19
+
20
+ return sum % 11 === 0;
21
+ };
22
+ }
23
+
24
+ module.exports = ISBN;
@@ -0,0 +1,68 @@
1
+ var ISBN = require('./isbn-verifier');
2
+
3
+ describe('ISBN', function () {
4
+ it('valid isbn number', function () {
5
+ var isbn = new ISBN('3-598-21508-8');
6
+ expect(isbn.isValid()).toBe(true);
7
+ });
8
+
9
+ it('invalid isbn check digit', function () {
10
+ var isbn = new ISBN('3-598-21508-9');
11
+ expect(isbn.isValid()).toBe(false);
12
+ });
13
+
14
+ it('valid isbn number with a check digit of 10', function () {
15
+ var isbn = new ISBN('3-598-21507-X');
16
+ expect(isbn.isValid()).toBe(true);
17
+ });
18
+
19
+ it('check digit is a character other than X', function () {
20
+ var isbn = new ISBN('3-598-21507-A');
21
+ expect(isbn.isValid()).toBe(false);
22
+ });
23
+
24
+ it('invalid character in isbn', function () {
25
+ var isbn = new ISBN('3-598-2K507-0');
26
+ expect(isbn.isValid()).toBe(false);
27
+ });
28
+
29
+ it('X is only valid as a check digit', function () {
30
+ var isbn = new ISBN('3-598-2X507-0');
31
+ expect(isbn.isValid()).toBe(false);
32
+ });
33
+
34
+ it('valid isbn without separating dashes', function () {
35
+ var isbn = new ISBN('3598215088');
36
+ expect(isbn.isValid()).toBe(true);
37
+ });
38
+
39
+ it('isbn without separating dashes and X as check digit', function () {
40
+ var isbn = new ISBN('359821507X');
41
+ expect(isbn.isValid()).toBe(true);
42
+ });
43
+
44
+ it('isbn without check digit and dashes', function () {
45
+ var isbn = new ISBN('359821507');
46
+ expect(isbn.isValid()).toBe(false);
47
+ });
48
+
49
+ it('too long isbn and no dashes', function () {
50
+ var isbn = new ISBN('3598215078X');
51
+ expect(isbn.isValid()).toBe(false);
52
+ });
53
+
54
+ it('isbn without check digit', function () {
55
+ var isbn = new ISBN('3-598-21507');
56
+ expect(isbn.isValid()).toBe(false);
57
+ });
58
+
59
+ it('too long isbn', function () {
60
+ var isbn = new ISBN('3-598-21507-XA');
61
+ expect(isbn.isValid()).toBe(false);
62
+ });
63
+
64
+ it('check digit of X should not be used for 0', function () {
65
+ var isbn = new ISBN('3-598-21515-X');
66
+ expect(isbn.isValid()).toBe(false);
67
+ });
68
+ });