trackler 1.0.1.0 → 1.0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (103) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +1 -0
  3. data/bin/bump-content +33 -0
  4. data/common/exercises/bowling/canonical-data.json +78 -77
  5. data/common/exercises/counter/.deprecated +1 -0
  6. data/common/exercises/point-mutations/.deprecated +1 -0
  7. data/common/exercises/say/canonical-data.json +83 -0
  8. data/common/exercises/word-count/canonical-data.json +25 -5
  9. data/lib/trackler/version.rb +1 -1
  10. data/tracks/c/config.json +9 -0
  11. data/tracks/c/exercises/largest-series-product/makefile +16 -0
  12. data/tracks/c/exercises/largest-series-product/src/example.c +54 -0
  13. data/tracks/c/exercises/largest-series-product/src/example.h +9 -0
  14. data/tracks/c/exercises/largest-series-product/test/test_largest_series_product.c +114 -0
  15. data/tracks/c/exercises/largest-series-product/test/vendor/unity.c +1300 -0
  16. data/tracks/c/exercises/largest-series-product/test/vendor/unity.h +274 -0
  17. data/tracks/c/exercises/largest-series-product/test/vendor/unity_internals.h +701 -0
  18. data/tracks/clojure/_test/check_exercises.clj +7 -6
  19. data/tracks/clojure/config.json +268 -53
  20. data/tracks/clojure/exercises/flatten-array/src/example.clj +16 -0
  21. data/tracks/clojure/exercises/flatten-array/test/flatten_array_test.clj +28 -0
  22. data/tracks/clojure/exercises/perfect-numbers/project.clj +4 -0
  23. data/tracks/clojure/exercises/perfect-numbers/src/example.clj +17 -0
  24. data/tracks/clojure/exercises/perfect-numbers/test/perfect_numbers_test.clj +20 -0
  25. data/tracks/ecmascript/exercises/grade-school/grade-school.spec.js +7 -0
  26. data/tracks/elixir/.travis.yml +3 -0
  27. data/tracks/elixir/bin/dialyzer_check.sh +28 -0
  28. data/tracks/elixir/config.json +13 -1
  29. data/tracks/elixir/docs/TESTS.md +81 -0
  30. data/tracks/elixir/exercises/bank-account/example.exs +1 -1
  31. data/tracks/elixir/exercises/binary-search/binary_search_test.exs +5 -0
  32. data/tracks/elixir/exercises/clock/clock.exs +23 -0
  33. data/tracks/elixir/exercises/clock/clock_test.exs +281 -0
  34. data/tracks/elixir/exercises/clock/example.exs +55 -0
  35. data/tracks/elixir/exercises/prime-factors/example.exs +1 -2
  36. data/tracks/elixir/exercises/robot-simulator/example.exs +2 -3
  37. data/tracks/elixir/mix.exs +2 -1
  38. data/tracks/go/docs/TESTS.md +1 -1
  39. data/tracks/go/exercises/gigasecond/gigasecond_test.go +0 -2
  40. data/tracks/go/exercises/palindrome-products/palindrome_products_test.go +38 -22
  41. data/tracks/haskell/.travis.yml +26 -7
  42. data/tracks/haskell/config.json +0 -69
  43. data/tracks/haskell/exercises/anagram/examples/list-string/Anagram.hs +10 -0
  44. data/tracks/haskell/exercises/anagram/examples/list-string/package.yaml +17 -0
  45. data/tracks/haskell/exercises/anagram/{src/Example.hs → examples/set-text/Anagram.hs} +0 -0
  46. data/tracks/haskell/exercises/anagram/examples/set-text/package.yaml +20 -0
  47. data/tracks/haskell/exercises/anagram/package.yaml +0 -3
  48. data/tracks/idris/config.json +3 -3
  49. data/tracks/kotlin/config.json +207 -43
  50. data/tracks/lfe/config.json +152 -32
  51. data/tracks/lfe/docs/TESTS.md +18 -56
  52. data/tracks/lua/docs/ABOUT.md +9 -0
  53. data/tracks/mips/config.json +72 -16
  54. data/tracks/ocaml/config.json +6 -0
  55. data/tracks/ocaml/exercises/etl/.merlin +5 -0
  56. data/tracks/ocaml/exercises/etl/Makefile +11 -0
  57. data/tracks/ocaml/exercises/etl/etl.mli +2 -0
  58. data/tracks/ocaml/exercises/etl/example.ml +7 -0
  59. data/tracks/ocaml/exercises/etl/test.ml +35 -0
  60. data/tracks/ocaml/exercises/raindrops/test.ml +1 -1
  61. data/tracks/php/config.json +7 -1
  62. data/tracks/php/exercises/acronym/acronym_test.php +56 -0
  63. data/tracks/php/exercises/acronym/example.php +20 -0
  64. data/tracks/racket/config.json +109 -22
  65. data/tracks/ruby/README.md +3 -3
  66. data/tracks/ruby/bin/generate +16 -0
  67. data/tracks/ruby/exercises/alphametics/.version +1 -1
  68. data/tracks/ruby/exercises/alphametics/alphametics_test.rb +24 -22
  69. data/tracks/ruby/exercises/alphametics/example.rb +1 -1
  70. data/tracks/ruby/lib/bracket_push_cases.rb +3 -3
  71. data/tracks/ruby/lib/{raindrop_cases.rb → raindrops_cases.rb} +1 -1
  72. data/tracks/rust/config.json +1 -0
  73. data/tracks/rust/exercises/atbash-cipher/Cargo.lock +4 -0
  74. data/tracks/rust/exercises/atbash-cipher/Cargo.toml +3 -0
  75. data/tracks/rust/exercises/atbash-cipher/example.rs +36 -0
  76. data/tracks/rust/exercises/atbash-cipher/tests/atbash-cipher.rs +82 -0
  77. data/tracks/rust/problems.md +1 -0
  78. data/tracks/scala/config.json +8 -0
  79. data/tracks/scala/exercises/sum-of-multiples/build.sbt +3 -0
  80. data/tracks/scala/exercises/sum-of-multiples/example.scala +10 -0
  81. data/tracks/scala/exercises/sum-of-multiples/src/main/scala/.keep +0 -0
  82. data/tracks/scala/exercises/sum-of-multiples/src/test/scala/SumOfMultiplesTest.scala +62 -0
  83. metadata +43 -23
  84. data/tracks/ruby/bin/generate-acronym +0 -7
  85. data/tracks/ruby/bin/generate-alphametics +0 -8
  86. data/tracks/ruby/bin/generate-binary +0 -7
  87. data/tracks/ruby/bin/generate-bracket-push +0 -7
  88. data/tracks/ruby/bin/generate-clock +0 -7
  89. data/tracks/ruby/bin/generate-connect +0 -7
  90. data/tracks/ruby/bin/generate-custom-set +0 -7
  91. data/tracks/ruby/bin/generate-difference-of-squares +0 -7
  92. data/tracks/ruby/bin/generate-gigasecond +0 -7
  93. data/tracks/ruby/bin/generate-hamming +0 -7
  94. data/tracks/ruby/bin/generate-hello-world +0 -7
  95. data/tracks/ruby/bin/generate-largest-series-product +0 -7
  96. data/tracks/ruby/bin/generate-leap +0 -7
  97. data/tracks/ruby/bin/generate-nth-prime +0 -7
  98. data/tracks/ruby/bin/generate-pangram +0 -7
  99. data/tracks/ruby/bin/generate-raindrops +0 -7
  100. data/tracks/ruby/bin/generate-rna-transcription +0 -7
  101. data/tracks/ruby/bin/generate-roman-numerals +0 -7
  102. data/tracks/ruby/bin/generate-run-length-encoding +0 -7
  103. data/tracks/ruby/bin/generate-two-bucket +0 -7
@@ -0,0 +1,11 @@
1
+ test: test.native
2
+ @./test.native
3
+
4
+ test.native: *.ml *.mli
5
+ @corebuild -r -quiet -pkg oUnit test.native
6
+
7
+ clean:
8
+ rm -rf _build
9
+ rm -f test.native
10
+
11
+ .PHONY: clean
@@ -0,0 +1,2 @@
1
+ (* Transform legacy Scrabble data into shiny new Scrabble data *)
2
+ val transform: (int * char list) list -> (char * int) list
@@ -0,0 +1,7 @@
1
+ open Core.Std
2
+
3
+ let transform data =
4
+ let assign_value value character = ((Char.lowercase character), value) in
5
+ let assign (value, characters) = List.map ~f:(assign_value value) characters in
6
+ let compare (a, _) (b, _) = Char.compare a b in
7
+ List.sort compare (List.concat (List.map ~f:assign data))
@@ -0,0 +1,35 @@
1
+ open Core.Std
2
+ open OUnit2
3
+ open Etl
4
+
5
+
6
+ let ae exp got _test_ctxt =
7
+ let sexpr_of l = List.sexp_of_t (Tuple2.sexp_of_t Char.sexp_of_t Int.sexp_of_t) l in
8
+ let printer l = Sexp.to_string (sexpr_of l) in
9
+ assert_equal exp got ~printer
10
+
11
+ let tests =
12
+ ["transform one character">::
13
+ ae [('a', 1)] (transform [(1,['A'])]);
14
+ "transform multiple characters">::
15
+ ae [('a', 1);('e', 1);('i', 1);('o', 1);('u', 1)] (transform [(1, ['A';'E';'I';'O';'U'])]);
16
+ "transform multiple values">::
17
+ ae [('a',1);('d',2);('e',1);('g',2);('i',1);('o',1);('u',1)] (transform [(1, ['A';'E';'I';'O';'U']);
18
+ (2, ['D';'G'])]);
19
+ "transform full dataset">::
20
+ ae [('a',1);('b',3);('c',3);('d',2);('e',1);
21
+ ('f',4);('g',2);('h',4);('i',1);('j',8);
22
+ ('k',5);('l',1);('m',3);('n',1);('o',1);
23
+ ('p',3);('q',10);('r',1);('s',1);('t',1);
24
+ ('u',1);('v',4);('w',4);('x',8);('y',4);
25
+ ('z',10)] (transform [(1,['A';'E';'I';'O';'U';'L';'N';'R';'S';'T']);
26
+ (2,['D';'G']);
27
+ (3,['B';'C';'M';'P']);
28
+ (4,['F';'H';'V';'W';'Y']);
29
+ (5,['K']);
30
+ (8,['J';'X']);
31
+ (10,['Q';'Z'])]);
32
+ ]
33
+
34
+ let () =
35
+ run_test_tt_main ("etl tests" >::: tests)
@@ -2,7 +2,7 @@ open Core.Std
2
2
  open OUnit2
3
3
  open Raindrops
4
4
 
5
- let ae exp got _test_ctxt = assert_equal exp got
5
+ let ae exp got _test_ctxt = assert_equal ~printer:Fn.id exp got
6
6
 
7
7
  let tests =
8
8
  [
@@ -33,7 +33,8 @@
33
33
  "binary",
34
34
  "braket-push",
35
35
  "accumulate",
36
- "variable-length-quantity"
36
+ "variable-length-quantity",
37
+ "acronym"
37
38
  ],
38
39
  "deprecated": [
39
40
 
@@ -195,6 +196,11 @@
195
196
  "slug": "variable-length-quantity",
196
197
  "difficulty": 1,
197
198
  "topics": []
199
+ },
200
+ {
201
+ "slug": "acronym",
202
+ "difficulty": 1,
203
+ "topics": []
198
204
  }
199
205
  ]
200
206
  }
@@ -0,0 +1,56 @@
1
+ <?php
2
+
3
+ require_once 'acronym.php';
4
+
5
+ class AcronymTest extends PHPUnit_Framework_TestCase
6
+ {
7
+ public function testBasicTitleCase()
8
+ {
9
+ $this->assertEquals('PNG', acronym('Portable Network Graphics'));
10
+ }
11
+
12
+ public function testLowerCaseWord()
13
+ {
14
+ $this->markTestSkipped();
15
+
16
+ $this->assertEquals('ROR', acronym('Ruby on Rails'));
17
+ }
18
+
19
+ public function testCamelCase()
20
+ {
21
+ $this->markTestSkipped();
22
+
23
+ $this->assertEquals('HTML', acronym('HyperText Markup Language'));
24
+ }
25
+
26
+ public function testAllCapsWords()
27
+ {
28
+ $this->markTestSkipped();
29
+
30
+ $this->assertEquals('PHP', acronym('PHP: Hypertext Preprocessor'));
31
+ }
32
+
33
+ public function testHyphenated()
34
+ {
35
+ $this->markTestSkipped();
36
+
37
+ $this->assertEquals('CMOS', acronym('Complementary metal-oxide semiconductor'));
38
+ }
39
+
40
+ // Additional points for making the following tests pass
41
+
42
+ public function testOneWordIsNotAbbreviated()
43
+ {
44
+ $this->markTestSkipped();
45
+
46
+ $this->assertEmpty(acronym('Word'));
47
+ }
48
+
49
+ public function testUnicode()
50
+ {
51
+ $this->markTestSkipped();
52
+
53
+ $phrase = 'Специализированная процессорная часть';
54
+ $this->assertEquals('СПЧ', acronym($phrase));
55
+ }
56
+ }
@@ -0,0 +1,20 @@
1
+ <?php
2
+
3
+ /**
4
+ * Abbreviates a phrase.
5
+ *
6
+ * @param string $phrase
7
+ * @return string
8
+ */
9
+ function acronym($phrase)
10
+ {
11
+ $matches = preg_match_all('/\p{Lu}+\p{Ll}*|\p{Ll}+/u', $phrase, $words);
12
+
13
+ if ($matches === false || $matches < 2) {
14
+ return '';
15
+ }
16
+
17
+ return array_reduce($words[0], function ($acronym, $word) {
18
+ return $acronym.mb_strtoupper(mb_substr($word, 0, 1));
19
+ });
20
+ }
@@ -3,28 +3,115 @@
3
3
  "language": "Racket",
4
4
  "repository": "https://github.com/exercism/xracket",
5
5
  "active": true,
6
- "problems": [
7
- "hello-world",
8
- "grains",
9
- "leap",
10
- "difference-of-squares",
11
- "perfect-numbers",
12
- "gigasecond",
13
- "bob",
14
- "hamming",
15
- "scrabble-score",
16
- "roman-numerals",
17
- "anagram",
18
- "rna-transcription",
19
- "etl",
20
- "word-count",
21
- "phone-number",
22
- "nucleotide-count",
23
- "raindrops",
24
- "grep",
25
- "say",
26
- "allergies",
27
- "list-ops"
6
+ "exercises": [
7
+ {
8
+ "difficulty": 1,
9
+ "slug": "hello-world",
10
+ "topics": [
11
+ "optional values",
12
+ "text formatting"
13
+ ]
14
+ },
15
+ {
16
+ "difficulty": 1,
17
+ "slug": "grains",
18
+ "topics": []
19
+ },
20
+ {
21
+ "difficulty": 1,
22
+ "slug": "leap",
23
+ "topics": []
24
+ },
25
+ {
26
+ "difficulty": 1,
27
+ "slug": "difference-of-squares",
28
+ "topics": []
29
+ },
30
+ {
31
+ "difficulty": 1,
32
+ "slug": "perfect-numbers",
33
+ "topics": []
34
+ },
35
+ {
36
+ "difficulty": 1,
37
+ "slug": "gigasecond",
38
+ "topics": []
39
+ },
40
+ {
41
+ "difficulty": 1,
42
+ "slug": "bob",
43
+ "topics": []
44
+ },
45
+ {
46
+ "difficulty": 1,
47
+ "slug": "hamming",
48
+ "topics": []
49
+ },
50
+ {
51
+ "difficulty": 1,
52
+ "slug": "scrabble-score",
53
+ "topics": []
54
+ },
55
+ {
56
+ "difficulty": 1,
57
+ "slug": "roman-numerals",
58
+ "topics": []
59
+ },
60
+ {
61
+ "difficulty": 1,
62
+ "slug": "anagram",
63
+ "topics": []
64
+ },
65
+ {
66
+ "difficulty": 1,
67
+ "slug": "rna-transcription",
68
+ "topics": []
69
+ },
70
+ {
71
+ "difficulty": 1,
72
+ "slug": "etl",
73
+ "topics": []
74
+ },
75
+ {
76
+ "difficulty": 1,
77
+ "slug": "word-count",
78
+ "topics": []
79
+ },
80
+ {
81
+ "difficulty": 1,
82
+ "slug": "phone-number",
83
+ "topics": []
84
+ },
85
+ {
86
+ "difficulty": 1,
87
+ "slug": "nucleotide-count",
88
+ "topics": []
89
+ },
90
+ {
91
+ "difficulty": 1,
92
+ "slug": "raindrops",
93
+ "topics": []
94
+ },
95
+ {
96
+ "difficulty": 1,
97
+ "slug": "grep",
98
+ "topics": []
99
+ },
100
+ {
101
+ "difficulty": 1,
102
+ "slug": "say",
103
+ "topics": []
104
+ },
105
+ {
106
+ "difficulty": 1,
107
+ "slug": "allergies",
108
+ "topics": []
109
+ },
110
+ {
111
+ "difficulty": 1,
112
+ "slug": "list-ops",
113
+ "topics": []
114
+ }
28
115
  ],
29
116
  "deprecated": [
30
117
  "accumulate"
@@ -89,7 +89,7 @@ tree -L 1 ~/code/exercism
89
89
  1. `xruby/$PROBLEM/example.tt` - the Erb template for the test file, `$PROBLEM_test.rb`.
90
90
  1. `x-common/$PROBLEM.json` - the shared inputs and outputs for the problem.
91
91
  1. `lib/$PROBLEM.rb` - the logic for turning the data into tests.
92
- 1. `xruby/bin/generate-$PROBLEM` - the command to actually generate the test suite.
92
+ 1. `xruby/bin/generate $PROBLEM` - the command to actually generate the test suite.
93
93
  1. `.version` - used to keep track of the version of the test files as the data changes.
94
94
 
95
95
  Additionally, there is some common generator logic in `lib/generator.rb`.
@@ -98,7 +98,7 @@ For example, take a look at the `hamming.json` file in the x-common repository,
98
98
  as the following files in the xruby repository:
99
99
 
100
100
  1. `hamming/example.tt`
101
- 1. `bin/generate-hamming`
101
+ 1. `bin/generate hamming`
102
102
  1. `lib/hamming.rb`
103
103
  1. `lib/generator.rb`
104
104
 
@@ -166,4 +166,4 @@ The MIT License (MIT)
166
166
  Copyright (c) 2014 Katrina Owen, _@kytrinyx.com
167
167
 
168
168
  ## Ruby icon
169
- The Ruby icon is the Vienna.rb logo, and is used with permission. Thanks Floor Dress :)
169
+ The Ruby icon is the Vienna.rb logo, and is used with permission. Thanks Floor Dress :)
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ exercise = ARGV[0]
4
+ cases = "#{exercise.tr('-','_')}_cases"
5
+
6
+ require_relative '../lib/helper'
7
+ require 'generator'
8
+ begin
9
+ require "#{cases}"
10
+ rescue LoadError
11
+ puts "A generator does not currently exist for #{exercise}!"
12
+ exit(1)
13
+ end
14
+
15
+ klass = Object.const_get(cases.split('_').map(&:capitalize).join)
16
+ Generator.new(exercise, klass).generate
@@ -1 +1 @@
1
- 2
1
+ 3
@@ -4,7 +4,7 @@ require 'minitest/autorun'
4
4
  require_relative 'alphametics'
5
5
 
6
6
  # Test data version:
7
- # 0b81bdb
7
+ # 8d8589f
8
8
  class AlphameticsTest < Minitest::Test
9
9
  def test_solve_short_puzzle
10
10
  # skip
@@ -26,26 +26,6 @@ class AlphameticsTest < Minitest::Test
26
26
  # assert_equal(expect, actual)
27
27
  # end
28
28
 
29
- def test_solve_puzzle_with_multiplication
30
- skip
31
- expect = {
32
- 'I' => 8, 'F' => 2, 'D' => 3, 'R' => 9,
33
- 'O' => 1
34
- }
35
- actual = Alphametics.new.solve('IF * DR == DORI')
36
- assert_equal(expect, actual)
37
- end
38
-
39
- def test_solve_puzzle_with_exponents
40
- skip
41
- expect = {
42
- 'P' => 9, 'I' => 6, 'R' => 7, 'A' => 4,
43
- 'E' => 0
44
- }
45
- actual = Alphametics.new.solve('PI * R ^ 2 == AREA')
46
- assert_equal(expect, actual)
47
- end
48
-
49
29
  def test_solution_must_have_unique_value_for_each_letter
50
30
  skip
51
31
  expect = nil
@@ -60,6 +40,28 @@ class AlphameticsTest < Minitest::Test
60
40
  assert_equal(expect, actual)
61
41
  end
62
42
 
43
+ def test_solve_puzzle_with_four_words
44
+ skip
45
+ expect = {
46
+ 'E' => 4, 'G' => 2, 'H' => 5, 'I' => 0,
47
+ 'L' => 1, 'S' => 9, 'T' => 7
48
+ }
49
+ actual = Alphametics.new.solve('HE + SEES + THE == LIGHT')
50
+ assert_equal(expect, actual)
51
+ end
52
+
53
+ # This test has been commented out due its long runtime.
54
+ # def test_solve_puzzle_with_many_words
55
+ # skip
56
+ # expect = {
57
+ # 'A' => 5, 'D' => 3, 'E' => 4, 'F' => 7,
58
+ # 'G' => 8, 'N' => 0, 'O' => 2, 'R' => 1,
59
+ # 'S' => 6, 'T' => 9
60
+ # }
61
+ # actual = Alphametics.new.solve('AND + A + STRONG + OFFENSE + AS + A + GOOD = DEFENSE')
62
+ # assert_equal(expect, actual)
63
+ # end
64
+
63
65
  # Problems in exercism evolve over time, as we find better ways to ask
64
66
  # questions.
65
67
  # The version number refers to the version of the problem you solved,
@@ -79,6 +81,6 @@ class AlphameticsTest < Minitest::Test
79
81
 
80
82
  def test_bookkeeping
81
83
  skip
82
- assert_equal 2, BookKeeping::VERSION
84
+ assert_equal 3, BookKeeping::VERSION
83
85
  end
84
86
  end
@@ -1,5 +1,5 @@
1
1
  module BookKeeping
2
- VERSION = 2
2
+ VERSION = 3
3
3
  end
4
4
 
5
5
  class Alphametics
@@ -1,4 +1,4 @@
1
- class BracketsCase < OpenStruct
1
+ class BracketPushCase < OpenStruct
2
2
  def name
3
3
  'test_%s' % description.gsub(/[ -]/, '_')
4
4
  end
@@ -34,8 +34,8 @@ class BracketsCase < OpenStruct
34
34
  end
35
35
  end
36
36
 
37
- BracketsCases = proc do |data|
37
+ BracketPushCases = proc do |data|
38
38
  JSON.parse(data)['cases'].map.with_index do |row, i|
39
- BracketsCase.new(row.merge('index' => i))
39
+ BracketPushCase.new(row.merge('index' => i))
40
40
  end
41
41
  end
@@ -12,7 +12,7 @@ class RaindropsCase < OpenStruct
12
12
  end
13
13
  end
14
14
 
15
- RaindropCases = proc do |data|
15
+ RaindropsCases = proc do |data|
16
16
  JSON.parse(data)['cases'].map.with_index do |row, i|
17
17
  RaindropsCase.new(row.merge('index' => i))
18
18
  end
@@ -17,6 +17,7 @@
17
17
  "pangram",
18
18
  "nucleotide-count",
19
19
  "word-count",
20
+ "atbash-cipher",
20
21
  "etl",
21
22
  "acronym",
22
23
  "sieve",
@@ -0,0 +1,4 @@
1
+ [root]
2
+ name = "atbash-cipher"
3
+ version = "0.0.0"
4
+
@@ -0,0 +1,3 @@
1
+ [package]
2
+ name = "atbash-cipher"
3
+ version = "0.0.0"
@@ -0,0 +1,36 @@
1
+ use std::ascii::AsciiExt;
2
+
3
+ fn ascii(ch: char) -> u8 {
4
+ ch as u8
5
+ }
6
+
7
+ fn get_transpose(ch: char) -> char {
8
+ if ch.is_digit(10) {
9
+ ch
10
+ } else {
11
+ (ascii('z') - ascii(ch) + ascii('a')) as char
12
+ }
13
+ }
14
+
15
+ pub fn encode(plaintext: &str) -> String {
16
+ plaintext
17
+ .to_lowercase()
18
+ .chars()
19
+ .filter(|&ch| ch.is_ascii())
20
+ .filter(|&ch| ch.is_alphanumeric())
21
+ .map(|ch| get_transpose(ch))
22
+ .collect::<Vec<char>>()
23
+ .chunks(5)
24
+ .map(|slice| slice.iter().cloned().collect::<String>())
25
+ .collect::<Vec<String>>()
26
+ .join(" ")
27
+ }
28
+
29
+ pub fn decode(ciphertext: &str) -> String {
30
+ ciphertext
31
+ .split::<char>(' ')
32
+ .collect::<String>()
33
+ .chars()
34
+ .map(|ch| get_transpose(ch))
35
+ .collect::<String>()
36
+ }
@@ -0,0 +1,82 @@
1
+ extern crate atbash_cipher as cipher;
2
+
3
+ #[test]
4
+ fn test_encode_yes() {
5
+ assert_eq!("bvh", cipher::encode("yes"));
6
+ }
7
+
8
+ #[test]
9
+ #[ignore]
10
+ fn test_encode_no() {
11
+ assert_eq!("ml", cipher::encode("no"));
12
+ }
13
+
14
+ #[test]
15
+ #[ignore]
16
+ fn test_encode_omg() {
17
+ assert_eq!("lnt", cipher::encode("OMG"));
18
+ }
19
+
20
+ #[test]
21
+ #[ignore]
22
+ fn test_encode_spaces() {
23
+ assert_eq!("lnt", cipher::encode("O M G"));
24
+ }
25
+
26
+ #[test]
27
+ #[ignore]
28
+ fn test_encode_mindblowingly() {
29
+ assert_eq!("nrmwy oldrm tob", cipher::encode("mindblowingly"));
30
+ }
31
+
32
+ #[test]
33
+ #[ignore]
34
+ fn test_encode_numbers() {
35
+ assert_eq!("gvhgr mt123 gvhgr mt", cipher::encode("Testing,1 2 3, testing."));
36
+ }
37
+
38
+ #[test]
39
+ #[ignore]
40
+ fn test_encode_deep_thought() {
41
+ assert_eq!("gifgs rhurx grlm", cipher::encode("Truth is fiction."));
42
+ }
43
+
44
+ #[test]
45
+ #[ignore]
46
+ fn test_encode_all_the_letters() {
47
+ assert_eq!("gsvjf rxpyi ldmul cqfnk hlevi gsvoz abwlt",
48
+ cipher::encode("The quick brown fox jumps over the lazy dog."));
49
+ }
50
+
51
+ #[test]
52
+ #[ignore]
53
+ fn test_encode_ignores_non_ascii() {
54
+ assert_eq!("mlmzh xrrrt mlivw", cipher::encode("non ascii éignored"));
55
+ }
56
+
57
+
58
+ #[test]
59
+ #[ignore]
60
+ fn test_decode_exercism() {
61
+ assert_eq!("exercism", cipher::decode("vcvix rhn"));
62
+ }
63
+
64
+ #[test]
65
+ #[ignore]
66
+ fn test_decode_a_sentence() {
67
+ assert_eq!("anobstacleisoftenasteppingstone",
68
+ cipher::decode("zmlyh gzxov rhlug vmzhg vkkrm thglm v"));
69
+ }
70
+
71
+ #[test]
72
+ #[ignore]
73
+ fn test_decode_numbers() {
74
+ assert_eq!("testing123testing", cipher::decode("gvhgr mt123 gvhgr mt"));
75
+ }
76
+
77
+ #[test]
78
+ #[ignore]
79
+ fn test_decode_all_the_letters() {
80
+ assert_eq!("thequickbrownfoxjumpsoverthelazydog",
81
+ cipher::decode("gsvjf rxpyi ldmul cqfnk hlevi gsvoz abwlt"));
82
+ }
@@ -36,6 +36,7 @@ scrabble-score | chaining higher-order functions, HashMap (optional)
36
36
  pangram | filter, ascii (optional)
37
37
  nucleotide-count | filter, entry api, mutablity, match
38
38
  word-count | hashmap, str vs string, chars, entry api
39
+ atbash-cipher | str vs string, primitive types, iterators, chars, ascii
39
40
  etl | btree
40
41
  acronym | map, flat_map, filter, loops, Vec
41
42
  sieve | vector, map, while let (optional)
@@ -6,6 +6,7 @@
6
6
  "problems": [
7
7
  "hello-world",
8
8
  "bob",
9
+ "sum-of-multiples",
9
10
  "hamming",
10
11
  "word-count",
11
12
  "pangram",
@@ -85,6 +86,13 @@
85
86
  "Pattern matching"
86
87
  ]
87
88
  },
89
+ {
90
+ "slug": "sum-of-multiples",
91
+ "difficulty": 1,
92
+ "topics": [
93
+ "Filtering"
94
+ ]
95
+ },
88
96
  {
89
97
  "slug": "hamming",
90
98
  "difficulty": 2,
@@ -0,0 +1,3 @@
1
+ scalaVersion := "2.11.8"
2
+
3
+ libraryDependencies += "org.scalatest" % "scalatest_2.11" % "2.2.5" % "test"
@@ -0,0 +1,10 @@
1
+ object SumOfMultiples {
2
+ def sumOfMultiples(factors: List[Int], limit: Int): Int = {
3
+ def isDivisibleBy(x: Int)(y: Int): Boolean = x % y == 0
4
+ def isMultiple(x: Int): Boolean = factors exists isDivisibleBy(x)
5
+
6
+ val multiples = (1 until limit) filter isMultiple
7
+ multiples sum
8
+ }
9
+ }
10
+