trackler 2.1.0.1 → 2.1.0.2
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/elixir/config.json +17 -0
- data/tracks/elixir/exercises/matrix/example.exs +63 -0
- data/tracks/elixir/exercises/matrix/matrix.exs +48 -0
- data/tracks/elixir/exercises/matrix/matrix_test.exs +58 -0
- data/tracks/elixir/exercises/twelve-days/example.exs +53 -0
- data/tracks/elixir/exercises/twelve-days/twelve_days.exs +25 -0
- data/tracks/elixir/exercises/twelve-days/twelve_days_test.exs +86 -0
- data/tracks/go/exercises/change/.meta/gen.go +1 -3
- data/tracks/go/exercises/change/cases_test.go +1 -0
- data/tracks/go/exercises/forth/example.go +1 -1
- data/tracks/go/exercises/raindrops/.meta/gen.go +1 -3
- data/tracks/go/exercises/raindrops/cases_test.go +5 -1
- data/tracks/go/exercises/raindrops/example.go +1 -1
- data/tracks/go/exercises/raindrops/raindrops.go +1 -1
- data/tracks/go/exercises/raindrops/raindrops_test.go +1 -1
- data/tracks/java/config.json +5 -5
- data/tracks/java/exercises/isogram/src/example/java/IsogramChecker.java +23 -27
- data/tracks/java/exercises/isogram/src/test/java/IsogramCheckerTest.java +77 -0
- data/tracks/javascript/config.json +9 -0
- data/tracks/javascript/exercises/proverb/example.js +36 -0
- data/tracks/javascript/exercises/proverb/proverb.spec.js +78 -0
- data/tracks/ruby/README.md +0 -33
- data/tracks/ruby/exercises/acronym/.meta/.version +1 -1
- data/tracks/ruby/exercises/acronym/acronym_test.rb +14 -9
- data/tracks/ruby/exercises/acronym/example.rb +1 -1
- data/tracks/ruby/exercises/acronym/example.tt +7 -4
- data/tracks/ruby/exercises/all-your-base/all_your_base_test.rb +1 -1
- data/tracks/ruby/exercises/all-your-base/example.tt +4 -3
- data/tracks/ruby/exercises/alphametics/alphametics_test.rb +2 -1
- data/tracks/ruby/exercises/alphametics/example.tt +2 -1
- data/tracks/ruby/exercises/anagram/anagram_test.rb +35 -20
- data/tracks/ruby/exercises/anagram/example.rb +1 -1
- data/tracks/ruby/exercises/anagram/example.tt +5 -2
- data/tracks/ruby/exercises/beer-song/beer_song_test.rb +1 -0
- data/tracks/ruby/exercises/beer-song/example.tt +6 -4
- data/tracks/ruby/exercises/binary/binary_test.rb +3 -2
- data/tracks/ruby/exercises/binary/example.tt +5 -2
- data/tracks/ruby/exercises/bowling/bowling_test.rb +39 -40
- data/tracks/ruby/exercises/bowling/example.tt +2 -2
- data/tracks/ruby/exercises/bracket-push/.meta/.version +1 -1
- data/tracks/ruby/exercises/bracket-push/bracket_push_test.rb +7 -3
- data/tracks/ruby/exercises/bracket-push/example.rb +1 -1
- data/tracks/ruby/exercises/bracket-push/example.tt +5 -2
- data/tracks/ruby/exercises/clock/clock_test.rb +40 -41
- data/tracks/ruby/exercises/clock/example.tt +5 -2
- data/tracks/ruby/exercises/connect/.meta/.version +1 -1
- data/tracks/ruby/exercises/connect/connect_test.rb +20 -3
- data/tracks/ruby/exercises/connect/example.rb +1 -1
- data/tracks/ruby/exercises/connect/example.tt +3 -1
- data/tracks/ruby/exercises/custom-set/custom_set_test.rb +1 -2
- data/tracks/ruby/exercises/custom-set/example.tt +5 -2
- data/tracks/ruby/exercises/difference-of-squares/difference_of_squares_test.rb +6 -5
- data/tracks/ruby/exercises/difference-of-squares/example.tt +8 -4
- data/tracks/ruby/exercises/dominoes/dominoes_test.rb +1 -1
- data/tracks/ruby/exercises/dominoes/example.tt +1 -1
- data/tracks/ruby/exercises/gigasecond/.meta/.version +1 -1
- data/tracks/ruby/exercises/gigasecond/example.rb +1 -1
- data/tracks/ruby/exercises/gigasecond/example.tt +7 -5
- data/tracks/ruby/exercises/gigasecond/gigasecond_test.rb +11 -16
- data/tracks/ruby/exercises/grains/example.tt +5 -3
- data/tracks/ruby/exercises/grains/grains_test.rb +2 -1
- data/tracks/ruby/exercises/hello-world/example.tt +1 -1
- data/tracks/ruby/exercises/hello-world/hello_world_test.rb +1 -1
- data/tracks/ruby/exercises/isogram/.meta/.version +1 -1
- data/tracks/ruby/exercises/isogram/example.rb +1 -1
- data/tracks/ruby/exercises/isogram/example.tt +6 -4
- data/tracks/ruby/exercises/isogram/isogram_test.rb +18 -10
- data/tracks/ruby/exercises/largest-series-product/.meta/.version +1 -1
- data/tracks/ruby/exercises/largest-series-product/example.rb +1 -1
- data/tracks/ruby/exercises/largest-series-product/example.tt +7 -5
- data/tracks/ruby/exercises/largest-series-product/largest_series_product_test.rb +11 -21
- data/tracks/ruby/exercises/leap/.meta/.version +1 -1
- data/tracks/ruby/exercises/leap/example.rb +1 -1
- data/tracks/ruby/exercises/leap/example.tt +6 -4
- data/tracks/ruby/exercises/leap/leap_test.rb +11 -25
- data/tracks/ruby/exercises/nth-prime/example.tt +7 -5
- data/tracks/ruby/exercises/nth-prime/nth_prime_test.rb +2 -3
- data/tracks/ruby/exercises/pangram/example.tt +5 -3
- data/tracks/ruby/exercises/pangram/pangram_test.rb +2 -1
- data/tracks/ruby/exercises/queen-attack/example.tt +2 -2
- data/tracks/ruby/exercises/queen-attack/queen_attack_test.rb +14 -15
- data/tracks/ruby/exercises/raindrops/example.tt +7 -4
- data/tracks/ruby/exercises/raindrops/raindrops_test.rb +38 -38
- data/tracks/ruby/exercises/rna-transcription/example.tt +6 -3
- data/tracks/ruby/exercises/rna-transcription/rna_transcription_test.rb +4 -5
- data/tracks/ruby/exercises/roman-numerals/example.tt +7 -4
- data/tracks/ruby/exercises/roman-numerals/roman_numerals_test.rb +5 -5
- data/tracks/ruby/exercises/run-length-encoding/.meta/.version +1 -1
- data/tracks/ruby/exercises/run-length-encoding/example.rb +1 -1
- data/tracks/ruby/exercises/run-length-encoding/example.tt +6 -3
- data/tracks/ruby/exercises/run-length-encoding/run_length_encoding_test.rb +70 -28
- data/tracks/ruby/exercises/say/example.tt +7 -5
- data/tracks/ruby/exercises/say/say_test.rb +3 -2
- data/tracks/ruby/exercises/sieve/example.tt +4 -1
- data/tracks/ruby/exercises/sieve/sieve_test.rb +1 -3
- data/tracks/ruby/exercises/tournament/example.tt +4 -1
- data/tracks/ruby/exercises/tournament/tournament_test.rb +1 -2
- data/tracks/ruby/exercises/transpose/example.tt +5 -2
- data/tracks/ruby/exercises/transpose/transpose_test.rb +1 -2
- data/tracks/ruby/exercises/triangle/example.tt +5 -3
- data/tracks/ruby/exercises/triangle/triangle_test.rb +1 -3
- data/tracks/ruby/exercises/two-bucket/example.tt +7 -4
- data/tracks/ruby/exercises/two-bucket/two_bucket_test.rb +9 -9
- data/tracks/ruby/exercises/word-count/example.tt +6 -4
- data/tracks/ruby/exercises/word-count/word_count_test.rb +2 -3
- data/tracks/ruby/exercises/wordy/example.tt +5 -3
- data/tracks/ruby/exercises/wordy/wordy_test.rb +2 -1
- data/tracks/ruby/lib/acronym_cases.rb +3 -15
- data/tracks/ruby/lib/all_your_base_cases.rb +22 -54
- data/tracks/ruby/lib/alphametics_cases.rb +12 -27
- data/tracks/ruby/lib/anagram_cases.rb +7 -15
- data/tracks/ruby/lib/beer_song_cases.rb +7 -24
- data/tracks/ruby/lib/binary_cases.rb +5 -18
- data/tracks/ruby/lib/bowling_cases.rb +24 -24
- data/tracks/ruby/lib/bracket_push_cases.rb +6 -21
- data/tracks/ruby/lib/clock_cases.rb +6 -25
- data/tracks/ruby/lib/connect_cases.rb +2 -20
- data/tracks/ruby/lib/custom_set_cases.rb +14 -35
- data/tracks/ruby/lib/difference_of_squares_cases.rb +5 -26
- data/tracks/ruby/lib/dominoes_cases.rb +2 -11
- data/tracks/ruby/lib/generator/case_values.rb +25 -0
- data/tracks/ruby/lib/generator/exercise_cases.rb +11 -0
- data/tracks/ruby/lib/generator/files/track_files.rb +7 -2
- data/tracks/ruby/lib/generator/template_values.rb +12 -7
- data/tracks/ruby/lib/gigasecond_cases.rb +4 -18
- data/tracks/ruby/lib/grains_cases.rb +11 -38
- data/tracks/ruby/lib/hamming_cases.rb +0 -6
- data/tracks/ruby/lib/hello_world_cases.rb +2 -14
- data/tracks/ruby/lib/isogram_cases.rb +8 -16
- data/tracks/ruby/lib/largest_series_product_cases.rb +10 -16
- data/tracks/ruby/lib/leap_cases.rb +3 -16
- data/tracks/ruby/lib/luhn_cases.rb +0 -6
- data/tracks/ruby/lib/nth_prime_cases.rb +11 -13
- data/tracks/ruby/lib/ocr_numbers_cases.rb +0 -5
- data/tracks/ruby/lib/pangram_cases.rb +2 -19
- data/tracks/ruby/lib/pig_latin_cases.rb +0 -5
- data/tracks/ruby/lib/queen_attack_cases.rb +14 -37
- data/tracks/ruby/lib/raindrops_cases.rb +3 -15
- data/tracks/ruby/lib/rna_transcription_cases.rb +2 -14
- data/tracks/ruby/lib/roman_numerals_cases.rb +7 -10
- data/tracks/ruby/lib/run_length_encoding_cases.rb +4 -25
- data/tracks/ruby/lib/say_cases.rb +3 -14
- data/tracks/ruby/lib/sieve_cases.rb +1 -15
- data/tracks/ruby/lib/tournament_cases.rb +1 -14
- data/tracks/ruby/lib/transpose_cases.rb +1 -14
- data/tracks/ruby/lib/triangle_cases.rb +8 -27
- data/tracks/ruby/lib/two_bucket_cases.rb +7 -17
- data/tracks/ruby/lib/word_count_cases.rb +1 -13
- data/tracks/ruby/lib/wordy_cases.rb +4 -27
- data/tracks/ruby/test/fixtures/metadata/exercises/complex/canonical-data.json +45 -0
- data/tracks/ruby/test/fixtures/xruby/lib/beta_cases.rb +7 -0
- data/tracks/ruby/test/generator/case_values_test.rb +30 -0
- data/tracks/ruby/test/generator/files/track_files_test.rb +2 -3
- data/tracks/ruby/test/generator/template_values_test.rb +44 -3
- data/tracks/ruby/test/wordy_cases_test.rb +4 -65
- metadata +14 -4
- data/tracks/java/exercises/isogram/src/test/java/IsogramTest.java +0 -80
- data/tracks/ruby/test/grains_cases_test.rb +0 -103
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 11bdb5b1d6a2fdfcc6f3b2804ff0de87d01dda5f
|
|
4
|
+
data.tar.gz: 739035a2434c6e4a34deccca06e6c90a2c927f87
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: be2f4153e3178291a6c4b0e6df06ecdab554d119d87fa16207466abee760f8531129675441dde45bb574dfab129a7e81f844351de929120ad770f1ee2203bc83
|
|
7
|
+
data.tar.gz: d824ba18c322a95eae1d0f23839bd74cf7f425e4ac05729c83d28355df7ae521e8f2797ec5abe3367932aa8f8c1868698cc1b5d9a06fbab60486d8ecbc1b2629
|
data/lib/trackler/version.rb
CHANGED
data/tracks/elixir/config.json
CHANGED
|
@@ -73,6 +73,15 @@
|
|
|
73
73
|
"string processing"
|
|
74
74
|
]
|
|
75
75
|
},
|
|
76
|
+
{
|
|
77
|
+
"slug": "twelve-days",
|
|
78
|
+
"difficulty": 3,
|
|
79
|
+
"topics": [
|
|
80
|
+
"enumerations",
|
|
81
|
+
"string formatting",
|
|
82
|
+
"reduce"
|
|
83
|
+
]
|
|
84
|
+
},
|
|
76
85
|
{
|
|
77
86
|
"slug": "word-count",
|
|
78
87
|
"difficulty": 2,
|
|
@@ -154,6 +163,14 @@
|
|
|
154
163
|
"topics": [
|
|
155
164
|
]
|
|
156
165
|
},
|
|
166
|
+
{
|
|
167
|
+
"slug": "matrix",
|
|
168
|
+
"difficulty": 3,
|
|
169
|
+
"topics": [
|
|
170
|
+
"structs",
|
|
171
|
+
"string processing"
|
|
172
|
+
]
|
|
173
|
+
},
|
|
157
174
|
{
|
|
158
175
|
"slug": "bracket-push",
|
|
159
176
|
"difficulty": 3,
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
defmodule Matrix do
|
|
2
|
+
defstruct matrix: nil, transposed_matrix: nil
|
|
3
|
+
|
|
4
|
+
@doc """
|
|
5
|
+
Convert an `input` string, with rows separated by newlines and values
|
|
6
|
+
separated by single spaces, into a `Matrix` struct.
|
|
7
|
+
"""
|
|
8
|
+
@spec from_string(input :: String.t()) :: %Matrix{}
|
|
9
|
+
def from_string(input) do
|
|
10
|
+
rows = input
|
|
11
|
+
|> String.split("\n", trim: true)
|
|
12
|
+
|> Enum.map(&parse_line/1)
|
|
13
|
+
|
|
14
|
+
%Matrix{
|
|
15
|
+
matrix: rows,
|
|
16
|
+
transposed_matrix: rows |> List.zip |> Enum.map(&Tuple.to_list/1)
|
|
17
|
+
}
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
defp parse_line(input_line) do
|
|
21
|
+
input_line
|
|
22
|
+
|> String.split(" ", trim: true)
|
|
23
|
+
|> Enum.map(&String.to_integer/1)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
@doc """
|
|
27
|
+
Write the `matrix` out as a string, with rows separated by newlines and
|
|
28
|
+
values separated by single spaces.
|
|
29
|
+
"""
|
|
30
|
+
@spec to_string(matrix :: %Matrix{}) :: String.t()
|
|
31
|
+
def to_string(%Matrix{ matrix: rows }) do
|
|
32
|
+
rows
|
|
33
|
+
|> Enum.map(&join_row/1)
|
|
34
|
+
|> Enum.join("\n")
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
defp join_row(row), do: Enum.join(row, " ")
|
|
38
|
+
|
|
39
|
+
@doc """
|
|
40
|
+
Given a `matrix`, return its rows as a list of lists of integers.
|
|
41
|
+
"""
|
|
42
|
+
@spec rows(matrix :: %Matrix{}) :: list(list(integer))
|
|
43
|
+
def rows(%Matrix{matrix: rows}), do: rows
|
|
44
|
+
|
|
45
|
+
@doc """
|
|
46
|
+
Given a `matrix` and `index`, return the row at `index`.
|
|
47
|
+
"""
|
|
48
|
+
@spec row(matrix :: %Matrix{}, index :: integer) :: list(integer)
|
|
49
|
+
def row(%Matrix{matrix: rows}, index), do: Enum.at(rows, index)
|
|
50
|
+
|
|
51
|
+
@doc """
|
|
52
|
+
Given a `matrix`, return its columns as a list of lists of integers.
|
|
53
|
+
"""
|
|
54
|
+
@spec columns(matrix :: %Matrix{}) :: list(list(integer))
|
|
55
|
+
def columns(%Matrix{transposed_matrix: cols}), do: cols
|
|
56
|
+
|
|
57
|
+
@doc """
|
|
58
|
+
Given a `matrix` and `index`, return the column at `index`.
|
|
59
|
+
"""
|
|
60
|
+
@spec column(matrix :: %Matrix{}, index :: integer) :: list(integer)
|
|
61
|
+
def column(%Matrix{transposed_matrix: cols}, index), do: Enum.at(cols, index)
|
|
62
|
+
end
|
|
63
|
+
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
defmodule Matrix do
|
|
2
|
+
defstruct matrix: nil
|
|
3
|
+
|
|
4
|
+
@doc """
|
|
5
|
+
Convert an `input` string, with rows separated by newlines and values
|
|
6
|
+
separated by single spaces, into a `Matrix` struct.
|
|
7
|
+
"""
|
|
8
|
+
@spec from_string(input :: String.t()) :: %Matrix{}
|
|
9
|
+
def from_string(input) do
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
@doc """
|
|
13
|
+
Write the `matrix` out as a string, with rows separated by newlines and
|
|
14
|
+
values separated by single spaces.
|
|
15
|
+
"""
|
|
16
|
+
@spec to_string(matrix :: %Matrix{}) :: String.t()
|
|
17
|
+
def to_string(matrix) do
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
@doc """
|
|
21
|
+
Given a `matrix`, return its rows as a list of lists of integers.
|
|
22
|
+
"""
|
|
23
|
+
@spec rows(matrix :: %Matrix{}) :: list(list(integer))
|
|
24
|
+
def rows(matrix) do
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
@doc """
|
|
28
|
+
Given a `matrix` and `index`, return the row at `index`.
|
|
29
|
+
"""
|
|
30
|
+
@spec row(matrix :: %Matrix{}, index :: integer) :: list(integer)
|
|
31
|
+
def row(matrix, index) do
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
@doc """
|
|
35
|
+
Given a `matrix`, return its columns as a list of lists of integers.
|
|
36
|
+
"""
|
|
37
|
+
@spec columns(matrix :: %Matrix{}) :: list(list(integer))
|
|
38
|
+
def columns(matrix) do
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
@doc """
|
|
42
|
+
Given a `matrix` and `index`, return the column at `index`.
|
|
43
|
+
"""
|
|
44
|
+
@spec column(matrix :: %Matrix{}, index :: integer) :: list(integer)
|
|
45
|
+
def column(matrix, index) do
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
if !System.get_env("EXERCISM_TEST_EXAMPLES") do
|
|
2
|
+
Code.load_file("matrix.exs", __DIR__)
|
|
3
|
+
end
|
|
4
|
+
|
|
5
|
+
ExUnit.start
|
|
6
|
+
ExUnit.configure trace: true, exclude: :pending
|
|
7
|
+
|
|
8
|
+
defmodule MatrixTest do
|
|
9
|
+
use ExUnit.Case
|
|
10
|
+
|
|
11
|
+
@input "1 2 3\n4 5 6\n7 8 9"
|
|
12
|
+
|
|
13
|
+
#@tag :pending
|
|
14
|
+
test "reading from and writing to string" do
|
|
15
|
+
matrix = Matrix.from_string(@input)
|
|
16
|
+
assert Matrix.to_string(matrix) == @input
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
@tag :pending
|
|
20
|
+
test "rows should return nested lists regardless of internal structure" do
|
|
21
|
+
matrix = Matrix.from_string(@input)
|
|
22
|
+
|
|
23
|
+
assert Matrix.rows(matrix) == [
|
|
24
|
+
[1, 2, 3],
|
|
25
|
+
[4, 5, 6],
|
|
26
|
+
[7, 8, 9]
|
|
27
|
+
]
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
@tag :pending
|
|
31
|
+
test "row should return list at index" do
|
|
32
|
+
matrix = Matrix.from_string(@input)
|
|
33
|
+
|
|
34
|
+
assert Matrix.row(matrix, 0) == [1, 2, 3]
|
|
35
|
+
assert Matrix.row(matrix, 1) == [4, 5, 6]
|
|
36
|
+
assert Matrix.row(matrix, 2) == [7, 8, 9]
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
@tag :pending
|
|
40
|
+
test "columns should return nested lists regardless of internal structure" do
|
|
41
|
+
matrix = Matrix.from_string(@input)
|
|
42
|
+
|
|
43
|
+
assert Matrix.columns(matrix) == [
|
|
44
|
+
[1, 4, 7],
|
|
45
|
+
[2, 5, 8],
|
|
46
|
+
[3, 6, 9]
|
|
47
|
+
]
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
@tag :pending
|
|
51
|
+
test "column should return list at index" do
|
|
52
|
+
matrix = Matrix.from_string(@input)
|
|
53
|
+
|
|
54
|
+
assert Matrix.column(matrix, 0) == [1, 4, 7]
|
|
55
|
+
assert Matrix.column(matrix, 1) == [2, 5, 8]
|
|
56
|
+
assert Matrix.column(matrix, 2) == [3, 6, 9]
|
|
57
|
+
end
|
|
58
|
+
end
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
defmodule TwelveDays do
|
|
2
|
+
@days [
|
|
3
|
+
{"a", "first", "Partridge in a Pear Tree"},
|
|
4
|
+
{"two", "second", "Turtle Doves"},
|
|
5
|
+
{"three", "third", "French Hens"},
|
|
6
|
+
{"four", "fourth", "Calling Birds"},
|
|
7
|
+
{"five", "fifth", "Gold Rings"},
|
|
8
|
+
{"six", "sixth", "Geese-a-Laying"},
|
|
9
|
+
{"seven", "seventh", "Swans-a-Swimming"},
|
|
10
|
+
{"eight", "eighth", "Maids-a-Milking"},
|
|
11
|
+
{"nine", "ninth", "Ladies Dancing"},
|
|
12
|
+
{"ten", "tenth", "Lords-a-Leaping"},
|
|
13
|
+
{"eleven", "eleventh", "Pipers Piping"},
|
|
14
|
+
{"twelve", "twelfth", "Drummers Drumming"}
|
|
15
|
+
]
|
|
16
|
+
|
|
17
|
+
for { { count, ordinal, gift }, number } <- @days |> Enum.with_index(1) do
|
|
18
|
+
defp count(unquote(number)), do: unquote(count)
|
|
19
|
+
defp ordinal(unquote(number)), do: unquote(ordinal)
|
|
20
|
+
defp gift(unquote(number)), do: "#{count(unquote(number))} #{ unquote(gift) }"
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
@doc """
|
|
24
|
+
Given a `number`, return the song's verse for that specific day, including
|
|
25
|
+
all gifts for previous days in the same line.
|
|
26
|
+
"""
|
|
27
|
+
@spec verse(number :: integer) :: String.t()
|
|
28
|
+
def verse(number) do
|
|
29
|
+
"On the #{ordinal(number)} day of Christmas my true love gave to me, #{gifts_for_day(number, [])}."
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
defp gifts_for_day(1, []), do: gift(1)
|
|
33
|
+
defp gifts_for_day(1, results), do: ["and #{gift(1)}" | results] |> Enum.reverse |> Enum.join(", ")
|
|
34
|
+
defp gifts_for_day(number, results), do: gifts_for_day(number - 1, [gift(number) | results])
|
|
35
|
+
|
|
36
|
+
@doc """
|
|
37
|
+
Given a `starting_verse` and an `ending_verse`, return the verses for each
|
|
38
|
+
included day, one per line.
|
|
39
|
+
"""
|
|
40
|
+
@spec verses(starting_verse :: integer, ending_verse :: integer) :: String.t()
|
|
41
|
+
def verses(starting_verse, ending_verse) do
|
|
42
|
+
starting_verse
|
|
43
|
+
|> Range.new(ending_verse)
|
|
44
|
+
|> Enum.map_join("\n", &verse/1)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
@doc """
|
|
48
|
+
Sing all 12 verses, in order, one verse per line.
|
|
49
|
+
"""
|
|
50
|
+
@spec sing():: String.t()
|
|
51
|
+
def sing, do: verses(1, 12)
|
|
52
|
+
end
|
|
53
|
+
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
defmodule TwelveDays do
|
|
2
|
+
@doc """
|
|
3
|
+
Given a `number`, return the song's verse for that specific day, including
|
|
4
|
+
all gifts for previous days in the same line.
|
|
5
|
+
"""
|
|
6
|
+
@spec verse(number :: integer) :: String.t()
|
|
7
|
+
def verse(number) do
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
@doc """
|
|
11
|
+
Given a `starting_verse` and an `ending_verse`, return the verses for each
|
|
12
|
+
included day, one per line.
|
|
13
|
+
"""
|
|
14
|
+
@spec verses(starting_verse :: integer, ending_verse :: integer) :: String.t()
|
|
15
|
+
def verses(starting_verse, ending_verse) do
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
@doc """
|
|
19
|
+
Sing all 12 verses, in order, one verse per line.
|
|
20
|
+
"""
|
|
21
|
+
@spec sing():: String.t()
|
|
22
|
+
def sing do
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
if !System.get_env("EXERCISM_TEST_EXAMPLES") do
|
|
2
|
+
Code.load_file("twelve_days.exs", __DIR__)
|
|
3
|
+
end
|
|
4
|
+
|
|
5
|
+
ExUnit.start
|
|
6
|
+
ExUnit.configure trace: true, exclude: :pending
|
|
7
|
+
|
|
8
|
+
defmodule TwelveDaysTest do
|
|
9
|
+
use ExUnit.Case
|
|
10
|
+
|
|
11
|
+
describe "verse" do
|
|
12
|
+
#@tag :pending
|
|
13
|
+
test "first verse" do
|
|
14
|
+
assert TwelveDays.verse(1) == "On the first day of Christmas my true love gave to me, a Partridge in a Pear Tree."
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
@tag :pending
|
|
18
|
+
test "sixth verse" do
|
|
19
|
+
assert TwelveDays.verse(6) == "On the sixth day of Christmas my true love gave to me, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree."
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
@tag :pending
|
|
23
|
+
test "last verse" do
|
|
24
|
+
assert TwelveDays.verse(12) == "On the twelfth day of Christmas my true love gave to me, twelve Drummers Drumming, eleven Pipers Piping, ten Lords-a-Leaping, nine Ladies Dancing, eight Maids-a-Milking, seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree."
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
describe "verses" do
|
|
29
|
+
@tag :pending
|
|
30
|
+
test "1-3" do
|
|
31
|
+
assert TwelveDays.verses(1, 3) == """
|
|
32
|
+
On the first day of Christmas my true love gave to me, a Partridge in a Pear Tree.
|
|
33
|
+
On the second day of Christmas my true love gave to me, two Turtle Doves, and a Partridge in a Pear Tree.
|
|
34
|
+
On the third day of Christmas my true love gave to me, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.
|
|
35
|
+
""" |> String.trim
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
@tag :pending
|
|
39
|
+
test "4-6" do
|
|
40
|
+
assert TwelveDays.verses(4, 6) == """
|
|
41
|
+
On the fourth day of Christmas my true love gave to me, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.
|
|
42
|
+
On the fifth day of Christmas my true love gave to me, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.
|
|
43
|
+
On the sixth day of Christmas my true love gave to me, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.
|
|
44
|
+
""" |> String.trim
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
@tag :pending
|
|
48
|
+
test "1-12" do
|
|
49
|
+
assert TwelveDays.verses(1, 12) == """
|
|
50
|
+
On the first day of Christmas my true love gave to me, a Partridge in a Pear Tree.
|
|
51
|
+
On the second day of Christmas my true love gave to me, two Turtle Doves, and a Partridge in a Pear Tree.
|
|
52
|
+
On the third day of Christmas my true love gave to me, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.
|
|
53
|
+
On the fourth day of Christmas my true love gave to me, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.
|
|
54
|
+
On the fifth day of Christmas my true love gave to me, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.
|
|
55
|
+
On the sixth day of Christmas my true love gave to me, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.
|
|
56
|
+
On the seventh day of Christmas my true love gave to me, seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.
|
|
57
|
+
On the eighth day of Christmas my true love gave to me, eight Maids-a-Milking, seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.
|
|
58
|
+
On the ninth day of Christmas my true love gave to me, nine Ladies Dancing, eight Maids-a-Milking, seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.
|
|
59
|
+
On the tenth day of Christmas my true love gave to me, ten Lords-a-Leaping, nine Ladies Dancing, eight Maids-a-Milking, seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.
|
|
60
|
+
On the eleventh day of Christmas my true love gave to me, eleven Pipers Piping, ten Lords-a-Leaping, nine Ladies Dancing, eight Maids-a-Milking, seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.
|
|
61
|
+
On the twelfth day of Christmas my true love gave to me, twelve Drummers Drumming, eleven Pipers Piping, ten Lords-a-Leaping, nine Ladies Dancing, eight Maids-a-Milking, seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.
|
|
62
|
+
""" |> String.trim
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
describe "sing" do
|
|
67
|
+
@tag :pending
|
|
68
|
+
test "all 12 verses" do
|
|
69
|
+
assert TwelveDays.sing == """
|
|
70
|
+
On the first day of Christmas my true love gave to me, a Partridge in a Pear Tree.
|
|
71
|
+
On the second day of Christmas my true love gave to me, two Turtle Doves, and a Partridge in a Pear Tree.
|
|
72
|
+
On the third day of Christmas my true love gave to me, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.
|
|
73
|
+
On the fourth day of Christmas my true love gave to me, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.
|
|
74
|
+
On the fifth day of Christmas my true love gave to me, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.
|
|
75
|
+
On the sixth day of Christmas my true love gave to me, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.
|
|
76
|
+
On the seventh day of Christmas my true love gave to me, seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.
|
|
77
|
+
On the eighth day of Christmas my true love gave to me, eight Maids-a-Milking, seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.
|
|
78
|
+
On the ninth day of Christmas my true love gave to me, nine Ladies Dancing, eight Maids-a-Milking, seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.
|
|
79
|
+
On the tenth day of Christmas my true love gave to me, ten Lords-a-Leaping, nine Ladies Dancing, eight Maids-a-Milking, seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.
|
|
80
|
+
On the eleventh day of Christmas my true love gave to me, eleven Pipers Piping, ten Lords-a-Leaping, nine Ladies Dancing, eight Maids-a-Milking, seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.
|
|
81
|
+
On the twelfth day of Christmas my true love gave to me, twelve Drummers Drumming, eleven Pipers Piping, ten Lords-a-Leaping, nine Ladies Dancing, eight Maids-a-Milking, seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.
|
|
82
|
+
""" |> String.trim
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
@@ -31,9 +31,7 @@ type js struct {
|
|
|
31
31
|
// template applied to above data structure generates the Go test cases
|
|
32
32
|
var tmpl = `package raindrops
|
|
33
33
|
|
|
34
|
-
|
|
35
|
-
{{if .Commit}}// Commit: {{.Commit}}
|
|
36
|
-
{{end}}
|
|
34
|
+
{{.Header}}
|
|
37
35
|
|
|
38
36
|
var tests = []struct {
|
|
39
37
|
input int
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
package raindrops
|
|
2
2
|
|
|
3
3
|
// Source: exercism/x-common
|
|
4
|
-
// Commit:
|
|
4
|
+
// Commit: 9db5371 raindrops: Fix canonical-data.json formatting
|
|
5
|
+
// x-common version: 1.0.0
|
|
5
6
|
|
|
6
7
|
var tests = []struct {
|
|
7
8
|
input int
|
|
@@ -12,14 +13,17 @@ var tests = []struct {
|
|
|
12
13
|
{5, "Plang"},
|
|
13
14
|
{7, "Plong"},
|
|
14
15
|
{6, "Pling"},
|
|
16
|
+
{8, "8"},
|
|
15
17
|
{9, "Pling"},
|
|
16
18
|
{10, "Plang"},
|
|
17
19
|
{14, "Plong"},
|
|
18
20
|
{15, "PlingPlang"},
|
|
19
21
|
{21, "PlingPlong"},
|
|
20
22
|
{25, "Plang"},
|
|
23
|
+
{27, "Pling"},
|
|
21
24
|
{35, "PlangPlong"},
|
|
22
25
|
{49, "Plong"},
|
|
23
26
|
{52, "52"},
|
|
24
27
|
{105, "PlingPlangPlong"},
|
|
28
|
+
{3125, "Plang"},
|
|
25
29
|
}
|