trackler 2.0.8.18 → 2.0.8.19

Sign up to get free protection for your applications and to get access to all the features.
Files changed (165) hide show
  1. checksums.yaml +4 -4
  2. data/common/.gitignore +1 -0
  3. data/common/.travis.yml +5 -8
  4. data/common/README.md +18 -5
  5. data/common/exercises/grep/canonical-data.json +290 -269
  6. data/common/exercises/phone-number/canonical-data.json +2 -2
  7. data/common/exercises/pov/canonical-data.json +2 -5
  8. data/common/exercises/roman-numerals/canonical-data.json +112 -74
  9. data/common/exercises/tournament/canonical-data.json +86 -85
  10. data/common/exercises/two-bucket/canonical-data.json +55 -47
  11. data/common/package.json +16 -0
  12. data/common/yarn.lock +195 -0
  13. data/lib/trackler/version.rb +1 -1
  14. data/tracks/c/docs/LEARNING.md +1 -1
  15. data/tracks/c/exercises/space-age/src/example.c +15 -47
  16. data/tracks/c/exercises/space-age/src/example.h +12 -8
  17. data/tracks/c/exercises/space-age/test/test_space_age.c +8 -8
  18. data/tracks/ceylon/docs/TESTS.md +5 -2
  19. data/tracks/ceylon/exercises/TRACK_HINTS.md +5 -2
  20. data/tracks/csharp/.gitignore +0 -4
  21. data/tracks/csharp/.travis.yml +9 -20
  22. data/tracks/csharp/appveyor.yml +2 -4
  23. data/tracks/csharp/build.cake +95 -0
  24. data/tracks/csharp/build.ps1 +189 -0
  25. data/tracks/csharp/build.sh +99 -31
  26. data/tracks/csharp/circle.yml +3 -12
  27. data/tracks/delphi/config.json +8 -0
  28. data/tracks/delphi/exercises/minesweeper/MineSweeper.dpr +60 -0
  29. data/tracks/delphi/exercises/minesweeper/uMineSweeperExample.pas +70 -0
  30. data/tracks/delphi/exercises/minesweeper/uMineSweeperTest.pas +270 -0
  31. data/tracks/dlang/config.json +86 -31
  32. data/tracks/elixir/config.json +7 -0
  33. data/tracks/elixir/exercises/rotational-cipher/example.exs +35 -0
  34. data/tracks/elixir/exercises/rotational-cipher/rotational_cipher.exs +13 -0
  35. data/tracks/elixir/exercises/rotational-cipher/rotational_cipher_test.exs +80 -0
  36. data/tracks/go/exercises/raindrops/raindrops_test.go +4 -1
  37. data/tracks/go/exercises/react/react_test.go +6 -8
  38. data/tracks/go/exercises/rna-transcription/rna_transcription_test.go +4 -1
  39. data/tracks/go/exercises/robot-simulator/robot_simulator_test.go +5 -2
  40. data/tracks/haskell/exercises/allergies/src/Allergies.hs +2 -2
  41. data/tracks/haskell/exercises/atbash-cipher/src/Atbash.hs +2 -2
  42. data/tracks/haskell/exercises/bank-account/src/BankAccount.hs +3 -3
  43. data/tracks/haskell/exercises/binary-search-tree/src/BST.hs +7 -7
  44. data/tracks/haskell/exercises/bowling/src/Bowling.hs +1 -1
  45. data/tracks/haskell/exercises/clock/src/Clock.hs +4 -4
  46. data/tracks/haskell/exercises/connect/src/Connect.hs +1 -1
  47. data/tracks/haskell/exercises/crypto-square/src/CryptoSquare.hs +1 -1
  48. data/tracks/haskell/exercises/custom-set/src/CustomSet.hs +12 -12
  49. data/tracks/haskell/exercises/difference-of-squares/src/Squares.hs +3 -3
  50. data/tracks/haskell/exercises/etl/src/ETL.hs +1 -1
  51. data/tracks/haskell/exercises/forth/src/Forth.hs +2 -2
  52. data/tracks/haskell/exercises/go-counting/src/Counting.hs +2 -2
  53. data/tracks/haskell/exercises/kindergarten-garden/src/Garden.hs +3 -3
  54. data/tracks/haskell/exercises/largest-series-product/src/Series.hs +1 -1
  55. data/tracks/haskell/exercises/lens-person/src/Person.hs +4 -4
  56. data/tracks/julia/.travis.yml +3 -2
  57. data/tracks/ocaml/exercises/all-your-base/test.ml +2 -2
  58. data/tracks/ocaml/exercises/beer-song/test.ml +25 -24
  59. data/tracks/ocaml/exercises/phone-number/test.ml +22 -22
  60. data/tracks/ocaml/exercises/run-length-encoding/test.ml +5 -5
  61. data/tracks/ocaml/exercises/word-count/test.ml +1 -1
  62. data/tracks/ocaml/tools/test-generator/templates/beer-song/template.ml +20 -1
  63. data/tracks/purescript/config.json +7 -0
  64. data/tracks/purescript/exercises/word-count/bower.json +17 -0
  65. data/tracks/purescript/exercises/word-count/examples/src/WordCount.purs +31 -0
  66. data/tracks/purescript/exercises/word-count/src/WordCount.purs +3 -0
  67. data/tracks/purescript/exercises/word-count/test/Main.purs +89 -0
  68. data/tracks/python/exercises/accumulate/accumulate.py +2 -0
  69. data/tracks/python/exercises/acronym/acronym.py +2 -0
  70. data/tracks/python/exercises/allergies/allergies.py +3 -0
  71. data/tracks/python/exercises/allergies/example.py +1 -1
  72. data/tracks/python/exercises/anagram/anagram.py +2 -0
  73. data/tracks/python/exercises/atbash-cipher/atbash_cipher.py +6 -0
  74. data/tracks/python/exercises/beer-song/beer_song.py +6 -0
  75. data/tracks/python/exercises/binary-search/binary_search.py +2 -0
  76. data/tracks/python/exercises/binary/binary.py +2 -0
  77. data/tracks/python/exercises/bob/bob.py +2 -8
  78. data/tracks/python/exercises/bracket-push/bracket_push.py +2 -0
  79. data/tracks/python/exercises/circular-buffer/circular_buffer.py +11 -0
  80. data/tracks/python/exercises/clock/clock.py +3 -0
  81. data/tracks/python/exercises/clock/example.py +1 -1
  82. data/tracks/python/exercises/crypto-square/crypto_square.py +2 -0
  83. data/tracks/python/exercises/diamond/diamond.py +2 -0
  84. data/tracks/python/exercises/difference-of-squares/difference_of_squares.py +10 -0
  85. data/tracks/python/exercises/etl/etl.py +2 -0
  86. data/tracks/python/exercises/flatten-array/flatten_array.py +2 -0
  87. data/tracks/python/exercises/gigasecond/gigasecond.py +2 -0
  88. data/tracks/python/exercises/grade-school/grade_school.py +3 -0
  89. data/tracks/python/exercises/grains/grains.py +6 -0
  90. data/tracks/python/exercises/hamming/hamming.py +2 -0
  91. data/tracks/python/exercises/hello-world/hello_world.py +2 -7
  92. data/tracks/python/exercises/hexadecimal/hexadecimal.py +2 -0
  93. data/tracks/python/exercises/house/house.py +6 -0
  94. data/tracks/python/exercises/kindergarten-garden/kindergarten_garden.py +3 -0
  95. data/tracks/python/exercises/largest-series-product/largest_series_product.py +2 -0
  96. data/tracks/python/exercises/leap/leap.py +2 -0
  97. data/tracks/python/exercises/linked-list/linked_list.py +2 -8
  98. data/tracks/python/exercises/list-ops/list_ops.py +18 -22
  99. data/tracks/python/exercises/luhn/luhn.py +3 -0
  100. data/tracks/python/exercises/matrix/matrix.py +3 -0
  101. data/tracks/python/exercises/meetup/meetup.py +2 -0
  102. data/tracks/python/exercises/minesweeper/minesweeper.py +2 -0
  103. data/tracks/python/exercises/nth-prime/nth_prime.py +2 -0
  104. data/tracks/python/exercises/nucleotide-count/nucleotide_count.py +6 -0
  105. data/tracks/python/exercises/ocr-numbers/ocr_numbers.py +6 -0
  106. data/tracks/python/exercises/ocr-numbers/{ocr_test.py → ocr_numbers_test.py} +0 -0
  107. data/tracks/python/exercises/octal/octal.py +2 -0
  108. data/tracks/python/exercises/palindrome-products/palindrome_products.py +6 -0
  109. data/tracks/python/exercises/pangram/pangram.py +2 -0
  110. data/tracks/python/exercises/pascals-triangle/pascals_triangle.py +10 -0
  111. data/tracks/python/exercises/perfect-numbers/perfect_numbers.py +6 -0
  112. data/tracks/python/exercises/phone-number/phone_number.py +3 -0
  113. data/tracks/python/exercises/pig-latin/pig_latin.py +2 -0
  114. data/tracks/python/exercises/point-mutations/point_mutations.py +2 -0
  115. data/tracks/python/exercises/poker/poker.py +2 -0
  116. data/tracks/python/exercises/prime-factors/prime_factors.py +2 -0
  117. data/tracks/python/exercises/proverb/proverb.py +2 -0
  118. data/tracks/python/exercises/pythagorean-triplet/pythagorean_triplet.py +10 -0
  119. data/tracks/python/exercises/queen-attack/queen_attack.py +6 -0
  120. data/tracks/python/exercises/rail-fence-cipher/rail_fence_cipher.py +10 -0
  121. data/tracks/python/exercises/raindrops/raindrops.py +2 -0
  122. data/tracks/python/exercises/rectangles/example.py +1 -1
  123. data/tracks/python/exercises/rectangles/rectangles.py +2 -0
  124. data/tracks/python/exercises/rectangles/{rectangles_count_test.py → rectangles_test.py} +0 -0
  125. data/tracks/python/exercises/rna-transcription/rna_transcription.py +2 -0
  126. data/tracks/python/exercises/robot-name/robot_name.py +3 -0
  127. data/tracks/python/exercises/robot-simulator/robot_simulator.py +3 -0
  128. data/tracks/python/exercises/roman-numerals/roman_numerals.py +2 -0
  129. data/tracks/python/exercises/run-length-encoding/run_length_encoding.py +6 -0
  130. data/tracks/python/exercises/run-length-encoding/{run_length_test.py → run_length_encoding_test.py} +1 -1
  131. data/tracks/python/exercises/saddle-points/saddle_points.py +2 -0
  132. data/tracks/python/exercises/say/example.py +1 -1
  133. data/tracks/python/exercises/say/say.py +2 -0
  134. data/tracks/python/exercises/say/say_test.py +3 -0
  135. data/tracks/python/exercises/scrabble-score/scrabble_score.py +2 -0
  136. data/tracks/python/exercises/secret-handshake/secret_handshake.py +6 -0
  137. data/tracks/python/exercises/secret-handshake/{handshake_test.py → secret_handshake_test.py} +0 -0
  138. data/tracks/python/exercises/series/series.py +2 -0
  139. data/tracks/python/exercises/sieve/sieve.py +2 -0
  140. data/tracks/python/exercises/simple-cipher/example.py +1 -1
  141. data/tracks/python/exercises/simple-cipher/simple_cipher.py +8 -0
  142. data/tracks/python/exercises/space-age/space_age.py +3 -0
  143. data/tracks/python/exercises/strain/strain.py +6 -0
  144. data/tracks/python/exercises/sublist/sublist.py +2 -0
  145. data/tracks/python/exercises/sum-of-multiples/sum_of_multiples.py +2 -0
  146. data/tracks/python/exercises/triangle/triangle.py +7 -0
  147. data/tracks/python/exercises/trinary/trinary.py +2 -0
  148. data/tracks/python/exercises/twelve-days/twelve_days.py +10 -0
  149. data/tracks/python/exercises/word-count/word_count.py +2 -0
  150. data/tracks/python/exercises/wordy/wordy.py +2 -0
  151. data/tracks/python/exercises/zebra-puzzle/zebra_puzzle.py +2 -0
  152. data/tracks/ruby/exercises/beer-song/.meta/.version +1 -0
  153. data/tracks/ruby/exercises/beer-song/beer_song_test.rb +62 -36
  154. data/tracks/ruby/exercises/beer-song/example.rb +1 -5
  155. data/tracks/ruby/exercises/beer-song/example.tt +22 -0
  156. data/tracks/ruby/lib/beer_song_cases.rb +43 -0
  157. data/tracks/swift/exercises/matrix/Tests/MatrixTests/MatrixTests.swift +1 -1
  158. metadata +94 -13
  159. data/common/bin/jsonlint +0 -27
  160. data/tracks/csharp/.paket/paket.bootstrapper.exe +0 -0
  161. data/tracks/csharp/Zipper.cs +0 -137
  162. data/tracks/csharp/build.cmd +0 -14
  163. data/tracks/csharp/build.fsx +0 -78
  164. data/tracks/csharp/paket.dependencies +0 -2
  165. data/tracks/csharp/paket.lock +0 -3
@@ -1,4 +1,4 @@
1
1
  module Series (largestProduct) where
2
2
 
3
3
  largestProduct :: Int -> String -> Maybe Integer
4
- largestProduct = error "You need to implement this function."
4
+ largestProduct series digits = error "You need to implement this function."
@@ -31,13 +31,13 @@ data Address = Address { _street :: String
31
31
  }
32
32
 
33
33
  bornStreet :: Born -> String
34
- bornStreet = error "You need to implement this function."
34
+ bornStreet born = error "You need to implement this function."
35
35
 
36
36
  setCurrentStreet :: String -> Person -> Person
37
- setCurrentStreet = error "You need to implement this function."
37
+ setCurrentStreet street person = error "You need to implement this function."
38
38
 
39
39
  setBirthMonth :: Int -> Person -> Person
40
- setBirthMonth = error "You need to implement this function."
40
+ setBirthMonth month person = error "You need to implement this function."
41
41
 
42
42
  renameStreets :: (String -> String) -> Person -> Person
43
- renameStreets = error "You need to implement this function."
43
+ renameStreets f person = error "You need to implement this function."
@@ -4,13 +4,14 @@ os:
4
4
  - linux
5
5
 
6
6
  julia:
7
- - release
8
7
  - nightly
9
- - 0.5.0
8
+ - 0.6
9
+ - 0.5
10
10
 
11
11
  matrix:
12
12
  allow_failures:
13
13
  - julia: nightly
14
+ - julia: 0.6
14
15
 
15
16
  script:
16
17
  - julia runtests.jl
@@ -33,7 +33,7 @@ let tests = [
33
33
  "multiple zeros" >::
34
34
  ae (Some [0]) (convert_bases ~from:10 ~digits:[0; 0; 0] ~target:2);
35
35
  "leading zeros" >::
36
- ae (Some [4; 2]) (convert_bases ~from:7 ~digits:[0; 0; 6; 0] ~target:10);
36
+ ae (Some [4; 2]) (convert_bases ~from:7 ~digits:[0; 6; 0] ~target:10);
37
37
  "negative digit" >::
38
38
  ae None (convert_bases ~from:2 ~digits:[1; -1; 1; 0; 1; 0] ~target:10);
39
39
  "invalid positive digit" >::
@@ -55,4 +55,4 @@ let tests = [
55
55
  ]
56
56
 
57
57
  let () =
58
- run_test_tt_main ("all-your-bases tests" >::: tests)
58
+ run_test_tt_main ("all-your-bases tests" >::: tests)
@@ -6,40 +6,41 @@ let zip s1 s2 =
6
6
  let rec go s1 s2 acc = match (s1,s2) with
7
7
  | ([], _) -> acc
8
8
  | (_, []) -> acc
9
- | (x::xs, y::ys) -> go xs ys ((x,y)::acc) in
10
- List.rev @@ go s1 s2 []
9
+ | (x::xs, y::ys) -> go xs ys ((x,y)::acc) in List.rev @@ go s1 s2 []
11
10
 
12
- let find_diffs s1 s2 =
13
- let s1 = String.to_list s1 in
14
- let s2 = String.to_list s2 in
15
- let both = zip s1 s2 in
16
- List.find_mapi both ~f:(fun i (c1, c2) -> if c1 = c2 then None else Some (sprintf "Diff at index %d: %c <> %c" i c1 c2))
17
-
18
- let diff_message s1 s2 = match find_diffs s1 s2 with
19
- | None -> if String.length s1 = String.length s2 then "" else "Lengths of expected and actual differ but have a common prefix."
20
- | Some m -> m
21
-
22
- let ae exp got _test_ctxt =
23
- if exp = got
24
- then ()
25
- else failwith @@ "Expected differs from actual: " ^ (diff_message exp got)
11
+ let find_diffs s1 s2 =
12
+ let s1 = String.to_list s1 in
13
+ let s2 = String.to_list s2 in
14
+ let both = zip s1 s2 in
15
+ List.find_mapi both ~f:(fun i (c1, c2) -> if c1 = c2 then None else Some (sprintf "Diff at index %d: %c <> %c" i c1 c2))
16
+
17
+ let diff_message s1 s2 = match find_diffs s1 s2 with
18
+ | None -> if String.length s1 = String.length s2 then "" else "Lengths of expected and actual differ but have a common prefix."
19
+ | Some m -> m
20
+
21
+ let ae exp got _test_ctxt =
22
+ if exp = got
23
+ then ()
24
+ else failwith @@ "Expected differs from actual: " ^ (diff_message exp got)
26
25
 
27
26
  let verse_tests = [
28
- "first verse" >::
27
+ "first generic verse" >::
29
28
  ae "99 bottles of beer on the wall, 99 bottles of beer.\nTake one down and pass it around, 98 bottles of beer on the wall.\n" (verse 99);
30
- "middle verse" >::
31
- ae "44 bottles of beer on the wall, 44 bottles of beer.\nTake one down and pass it around, 43 bottles of beer on the wall.\n" (verse 44);
32
- "third to last verse" >::
29
+ "last generic verse" >::
30
+ ae "3 bottles of beer on the wall, 3 bottles of beer.\nTake one down and pass it around, 2 bottles of beer on the wall.\n" (verse 3);
31
+ "verse 2" >::
33
32
  ae "2 bottles of beer on the wall, 2 bottles of beer.\nTake one down and pass it around, 1 bottle of beer on the wall.\n" (verse 2);
34
- "penultimate verse" >::
33
+ "verse 1" >::
35
34
  ae "1 bottle of beer on the wall, 1 bottle of beer.\nTake it down and pass it around, no more bottles of beer on the wall.\n" (verse 1);
36
- "last verse" >::
35
+ "verse 0" >::
37
36
  ae "No more bottles of beer on the wall, no more bottles of beer.\nGo to the store and buy some more, 99 bottles of beer on the wall.\n" (verse 0);
38
37
  ]
39
38
 
40
39
  let lyrics_tests = [
41
- "last 4 verses" >::
42
- ae "3 bottles of beer on the wall, 3 bottles of beer.\nTake one down and pass it around, 2 bottles of beer on the wall.\n\n2 bottles of beer on the wall, 2 bottles of beer.\nTake one down and pass it around, 1 bottle of beer on the wall.\n\n1 bottle of beer on the wall, 1 bottle of beer.\nTake it down and pass it around, no more bottles of beer on the wall.\n\nNo more bottles of beer on the wall, no more bottles of beer.\nGo to the store and buy some more, 99 bottles of beer on the wall.\n" (lyrics ~from:3 ~until:0);
40
+ "first two verses" >::
41
+ ae "99 bottles of beer on the wall, 99 bottles of beer.\nTake one down and pass it around, 98 bottles of beer on the wall.\n\n98 bottles of beer on the wall, 98 bottles of beer.\nTake one down and pass it around, 97 bottles of beer on the wall.\n" (lyrics ~from:99 ~until:98);
42
+ "last three verses" >::
43
+ ae "2 bottles of beer on the wall, 2 bottles of beer.\nTake one down and pass it around, 1 bottle of beer on the wall.\n\n1 bottle of beer on the wall, 1 bottle of beer.\nTake it down and pass it around, no more bottles of beer on the wall.\n\nNo more bottles of beer on the wall, no more bottles of beer.\nGo to the store and buy some more, 99 bottles of beer on the wall.\n" (lyrics ~from:2 ~until:0);
43
44
  "all verses" >::
44
45
  ae "99 bottles of beer on the wall, 99 bottles of beer.\nTake one down and pass it around, 98 bottles of beer on the wall.\n\n98 bottles of beer on the wall, 98 bottles of beer.\nTake one down and pass it around, 97 bottles of beer on the wall.\n\n97 bottles of beer on the wall, 97 bottles of beer.\nTake one down and pass it around, 96 bottles of beer on the wall.\n\n96 bottles of beer on the wall, 96 bottles of beer.\nTake one down and pass it around, 95 bottles of beer on the wall.\n\n95 bottles of beer on the wall, 95 bottles of beer.\nTake one down and pass it around, 94 bottles of beer on the wall.\n\n94 bottles of beer on the wall, 94 bottles of beer.\nTake one down and pass it around, 93 bottles of beer on the wall.\n\n93 bottles of beer on the wall, 93 bottles of beer.\nTake one down and pass it around, 92 bottles of beer on the wall.\n\n92 bottles of beer on the wall, 92 bottles of beer.\nTake one down and pass it around, 91 bottles of beer on the wall.\n\n91 bottles of beer on the wall, 91 bottles of beer.\nTake one down and pass it around, 90 bottles of beer on the wall.\n\n90 bottles of beer on the wall, 90 bottles of beer.\nTake one down and pass it around, 89 bottles of beer on the wall.\n\n89 bottles of beer on the wall, 89 bottles of beer.\nTake one down and pass it around, 88 bottles of beer on the wall.\n\n88 bottles of beer on the wall, 88 bottles of beer.\nTake one down and pass it around, 87 bottles of beer on the wall.\n\n87 bottles of beer on the wall, 87 bottles of beer.\nTake one down and pass it around, 86 bottles of beer on the wall.\n\n86 bottles of beer on the wall, 86 bottles of beer.\nTake one down and pass it around, 85 bottles of beer on the wall.\n\n85 bottles of beer on the wall, 85 bottles of beer.\nTake one down and pass it around, 84 bottles of beer on the wall.\n\n84 bottles of beer on the wall, 84 bottles of beer.\nTake one down and pass it around, 83 bottles of beer on the wall.\n\n83 bottles of beer on the wall, 83 bottles of beer.\nTake one down and pass it around, 82 bottles of beer on the wall.\n\n82 bottles of beer on the wall, 82 bottles of beer.\nTake one down and pass it around, 81 bottles of beer on the wall.\n\n81 bottles of beer on the wall, 81 bottles of beer.\nTake one down and pass it around, 80 bottles of beer on the wall.\n\n80 bottles of beer on the wall, 80 bottles of beer.\nTake one down and pass it around, 79 bottles of beer on the wall.\n\n79 bottles of beer on the wall, 79 bottles of beer.\nTake one down and pass it around, 78 bottles of beer on the wall.\n\n78 bottles of beer on the wall, 78 bottles of beer.\nTake one down and pass it around, 77 bottles of beer on the wall.\n\n77 bottles of beer on the wall, 77 bottles of beer.\nTake one down and pass it around, 76 bottles of beer on the wall.\n\n76 bottles of beer on the wall, 76 bottles of beer.\nTake one down and pass it around, 75 bottles of beer on the wall.\n\n75 bottles of beer on the wall, 75 bottles of beer.\nTake one down and pass it around, 74 bottles of beer on the wall.\n\n74 bottles of beer on the wall, 74 bottles of beer.\nTake one down and pass it around, 73 bottles of beer on the wall.\n\n73 bottles of beer on the wall, 73 bottles of beer.\nTake one down and pass it around, 72 bottles of beer on the wall.\n\n72 bottles of beer on the wall, 72 bottles of beer.\nTake one down and pass it around, 71 bottles of beer on the wall.\n\n71 bottles of beer on the wall, 71 bottles of beer.\nTake one down and pass it around, 70 bottles of beer on the wall.\n\n70 bottles of beer on the wall, 70 bottles of beer.\nTake one down and pass it around, 69 bottles of beer on the wall.\n\n69 bottles of beer on the wall, 69 bottles of beer.\nTake one down and pass it around, 68 bottles of beer on the wall.\n\n68 bottles of beer on the wall, 68 bottles of beer.\nTake one down and pass it around, 67 bottles of beer on the wall.\n\n67 bottles of beer on the wall, 67 bottles of beer.\nTake one down and pass it around, 66 bottles of beer on the wall.\n\n66 bottles of beer on the wall, 66 bottles of beer.\nTake one down and pass it around, 65 bottles of beer on the wall.\n\n65 bottles of beer on the wall, 65 bottles of beer.\nTake one down and pass it around, 64 bottles of beer on the wall.\n\n64 bottles of beer on the wall, 64 bottles of beer.\nTake one down and pass it around, 63 bottles of beer on the wall.\n\n63 bottles of beer on the wall, 63 bottles of beer.\nTake one down and pass it around, 62 bottles of beer on the wall.\n\n62 bottles of beer on the wall, 62 bottles of beer.\nTake one down and pass it around, 61 bottles of beer on the wall.\n\n61 bottles of beer on the wall, 61 bottles of beer.\nTake one down and pass it around, 60 bottles of beer on the wall.\n\n60 bottles of beer on the wall, 60 bottles of beer.\nTake one down and pass it around, 59 bottles of beer on the wall.\n\n59 bottles of beer on the wall, 59 bottles of beer.\nTake one down and pass it around, 58 bottles of beer on the wall.\n\n58 bottles of beer on the wall, 58 bottles of beer.\nTake one down and pass it around, 57 bottles of beer on the wall.\n\n57 bottles of beer on the wall, 57 bottles of beer.\nTake one down and pass it around, 56 bottles of beer on the wall.\n\n56 bottles of beer on the wall, 56 bottles of beer.\nTake one down and pass it around, 55 bottles of beer on the wall.\n\n55 bottles of beer on the wall, 55 bottles of beer.\nTake one down and pass it around, 54 bottles of beer on the wall.\n\n54 bottles of beer on the wall, 54 bottles of beer.\nTake one down and pass it around, 53 bottles of beer on the wall.\n\n53 bottles of beer on the wall, 53 bottles of beer.\nTake one down and pass it around, 52 bottles of beer on the wall.\n\n52 bottles of beer on the wall, 52 bottles of beer.\nTake one down and pass it around, 51 bottles of beer on the wall.\n\n51 bottles of beer on the wall, 51 bottles of beer.\nTake one down and pass it around, 50 bottles of beer on the wall.\n\n50 bottles of beer on the wall, 50 bottles of beer.\nTake one down and pass it around, 49 bottles of beer on the wall.\n\n49 bottles of beer on the wall, 49 bottles of beer.\nTake one down and pass it around, 48 bottles of beer on the wall.\n\n48 bottles of beer on the wall, 48 bottles of beer.\nTake one down and pass it around, 47 bottles of beer on the wall.\n\n47 bottles of beer on the wall, 47 bottles of beer.\nTake one down and pass it around, 46 bottles of beer on the wall.\n\n46 bottles of beer on the wall, 46 bottles of beer.\nTake one down and pass it around, 45 bottles of beer on the wall.\n\n45 bottles of beer on the wall, 45 bottles of beer.\nTake one down and pass it around, 44 bottles of beer on the wall.\n\n44 bottles of beer on the wall, 44 bottles of beer.\nTake one down and pass it around, 43 bottles of beer on the wall.\n\n43 bottles of beer on the wall, 43 bottles of beer.\nTake one down and pass it around, 42 bottles of beer on the wall.\n\n42 bottles of beer on the wall, 42 bottles of beer.\nTake one down and pass it around, 41 bottles of beer on the wall.\n\n41 bottles of beer on the wall, 41 bottles of beer.\nTake one down and pass it around, 40 bottles of beer on the wall.\n\n40 bottles of beer on the wall, 40 bottles of beer.\nTake one down and pass it around, 39 bottles of beer on the wall.\n\n39 bottles of beer on the wall, 39 bottles of beer.\nTake one down and pass it around, 38 bottles of beer on the wall.\n\n38 bottles of beer on the wall, 38 bottles of beer.\nTake one down and pass it around, 37 bottles of beer on the wall.\n\n37 bottles of beer on the wall, 37 bottles of beer.\nTake one down and pass it around, 36 bottles of beer on the wall.\n\n36 bottles of beer on the wall, 36 bottles of beer.\nTake one down and pass it around, 35 bottles of beer on the wall.\n\n35 bottles of beer on the wall, 35 bottles of beer.\nTake one down and pass it around, 34 bottles of beer on the wall.\n\n34 bottles of beer on the wall, 34 bottles of beer.\nTake one down and pass it around, 33 bottles of beer on the wall.\n\n33 bottles of beer on the wall, 33 bottles of beer.\nTake one down and pass it around, 32 bottles of beer on the wall.\n\n32 bottles of beer on the wall, 32 bottles of beer.\nTake one down and pass it around, 31 bottles of beer on the wall.\n\n31 bottles of beer on the wall, 31 bottles of beer.\nTake one down and pass it around, 30 bottles of beer on the wall.\n\n30 bottles of beer on the wall, 30 bottles of beer.\nTake one down and pass it around, 29 bottles of beer on the wall.\n\n29 bottles of beer on the wall, 29 bottles of beer.\nTake one down and pass it around, 28 bottles of beer on the wall.\n\n28 bottles of beer on the wall, 28 bottles of beer.\nTake one down and pass it around, 27 bottles of beer on the wall.\n\n27 bottles of beer on the wall, 27 bottles of beer.\nTake one down and pass it around, 26 bottles of beer on the wall.\n\n26 bottles of beer on the wall, 26 bottles of beer.\nTake one down and pass it around, 25 bottles of beer on the wall.\n\n25 bottles of beer on the wall, 25 bottles of beer.\nTake one down and pass it around, 24 bottles of beer on the wall.\n\n24 bottles of beer on the wall, 24 bottles of beer.\nTake one down and pass it around, 23 bottles of beer on the wall.\n\n23 bottles of beer on the wall, 23 bottles of beer.\nTake one down and pass it around, 22 bottles of beer on the wall.\n\n22 bottles of beer on the wall, 22 bottles of beer.\nTake one down and pass it around, 21 bottles of beer on the wall.\n\n21 bottles of beer on the wall, 21 bottles of beer.\nTake one down and pass it around, 20 bottles of beer on the wall.\n\n20 bottles of beer on the wall, 20 bottles of beer.\nTake one down and pass it around, 19 bottles of beer on the wall.\n\n19 bottles of beer on the wall, 19 bottles of beer.\nTake one down and pass it around, 18 bottles of beer on the wall.\n\n18 bottles of beer on the wall, 18 bottles of beer.\nTake one down and pass it around, 17 bottles of beer on the wall.\n\n17 bottles of beer on the wall, 17 bottles of beer.\nTake one down and pass it around, 16 bottles of beer on the wall.\n\n16 bottles of beer on the wall, 16 bottles of beer.\nTake one down and pass it around, 15 bottles of beer on the wall.\n\n15 bottles of beer on the wall, 15 bottles of beer.\nTake one down and pass it around, 14 bottles of beer on the wall.\n\n14 bottles of beer on the wall, 14 bottles of beer.\nTake one down and pass it around, 13 bottles of beer on the wall.\n\n13 bottles of beer on the wall, 13 bottles of beer.\nTake one down and pass it around, 12 bottles of beer on the wall.\n\n12 bottles of beer on the wall, 12 bottles of beer.\nTake one down and pass it around, 11 bottles of beer on the wall.\n\n11 bottles of beer on the wall, 11 bottles of beer.\nTake one down and pass it around, 10 bottles of beer on the wall.\n\n10 bottles of beer on the wall, 10 bottles of beer.\nTake one down and pass it around, 9 bottles of beer on the wall.\n\n9 bottles of beer on the wall, 9 bottles of beer.\nTake one down and pass it around, 8 bottles of beer on the wall.\n\n8 bottles of beer on the wall, 8 bottles of beer.\nTake one down and pass it around, 7 bottles of beer on the wall.\n\n7 bottles of beer on the wall, 7 bottles of beer.\nTake one down and pass it around, 6 bottles of beer on the wall.\n\n6 bottles of beer on the wall, 6 bottles of beer.\nTake one down and pass it around, 5 bottles of beer on the wall.\n\n5 bottles of beer on the wall, 5 bottles of beer.\nTake one down and pass it around, 4 bottles of beer on the wall.\n\n4 bottles of beer on the wall, 4 bottles of beer.\nTake one down and pass it around, 3 bottles of beer on the wall.\n\n3 bottles of beer on the wall, 3 bottles of beer.\nTake one down and pass it around, 2 bottles of beer on the wall.\n\n2 bottles of beer on the wall, 2 bottles of beer.\nTake one down and pass it around, 1 bottle of beer on the wall.\n\n1 bottle of beer on the wall, 1 bottle of beer.\nTake it down and pass it around, no more bottles of beer on the wall.\n\nNo more bottles of beer on the wall, no more bottles of beer.\nGo to the store and buy some more, 99 bottles of beer on the wall.\n"
45
46
  (lyrics ~from:99 ~until:0);
@@ -9,28 +9,28 @@ let option_to_string f = function
9
9
  let ae exp got _test_ctxt =
10
10
  assert_equal ~printer:(option_to_string String.to_string) exp got
11
11
 
12
- let number_tests = [
13
- "cleans the number" >::
14
- ae (Some "1234567890") (number "(123) 456-7890");
15
- "cleans numbers with dots" >::
16
- ae (Some "1234567890") (number "123.456.7890");
17
- "cleans numbers with multiple spaces" >::
18
- ae (Some "1234567890") (number "123 456 7890 ");
19
- "invalid when 9 digits" >::
20
- ae None (number "123456789");
21
- "invalid when 11 digits" >::
22
- ae None (number "21234567890");
23
- "valid when 11 digits and starting with 1" >::
24
- ae (Some "1234567890") (number "11234567890");
25
- "invalid when 12 digits" >::
26
- ae None (number "321234567890");
27
- "invalid with letters" >::
28
- ae None (number "123-abc-7890");
29
- "invalid with punctuations" >::
30
- ae None (number "123-@:!-7890");
31
- "invalid with right number of digits but letters mixed in" >::
32
- ae None (number "1a2b3c4d5e6f7g8h9i0j");
12
+ let tests = [
13
+ "cleans the number" >::
14
+ ae (Some "1234567890") (number "(123) 456-7890");
15
+ "cleans numbers with dots" >::
16
+ ae (Some "1234567890") (number "123.456.7890");
17
+ "cleans numbers with multiple spaces" >::
18
+ ae (Some "1234567890") (number "123 456 7890 ");
19
+ "invalid when 9 digits" >::
20
+ ae None (number "123456789");
21
+ "invalid when 11 digits" >::
22
+ ae None (number "21234567890");
23
+ "valid when 11 digits and starting with 1" >::
24
+ ae (Some "1234567890") (number "11234567890");
25
+ "invalid when 12 digits" >::
26
+ ae None (number "321234567890");
27
+ "invalid with letters" >::
28
+ ae None (number "123-abc-7890");
29
+ "invalid with punctuations" >::
30
+ ae None (number "123-@:!-7890");
31
+ "invalid with right number of digits but letters mixed in" >::
32
+ ae None (number "1a2b3c4d5e6f7g8h9i0j");
33
33
  ]
34
34
 
35
35
  let () =
36
- run_test_tt_main ("phone-number tests" >::: number_tests)
36
+ run_test_tt_main ("phone-number tests" >::: tests)
@@ -4,7 +4,7 @@ open Run_length_encoding
4
4
 
5
5
  let ae exp got _test_ctxt = assert_equal exp got ~printer:Fn.id
6
6
 
7
- let encode_tests = [
7
+ let run_length_encode_a_string_tests = [
8
8
  "empty string" >::
9
9
  ae "" (encode "");
10
10
  "single characters only are encoded without count" >::
@@ -19,7 +19,7 @@ let encode_tests = [
19
19
  ae "2a3b4c" (encode "aabbbcccc");
20
20
  ]
21
21
 
22
- let decode_tests = [
22
+ let run_length_decode_a_string_tests = [
23
23
  "empty string" >::
24
24
  ae "" (decode "");
25
25
  "single characters only" >::
@@ -34,13 +34,13 @@ let decode_tests = [
34
34
  ae "aabbbcccc" (decode "2a3b4c");
35
35
  ]
36
36
 
37
- let consistency_tests = [
37
+ let encode_and_then_decode_tests = [
38
38
  "encode followed by decode gives original string" >::
39
- ae "zzz ZZ zZ" (decode "zzz ZZ zZ");
39
+ ae "zzz ZZ zZ" (decode @@ encode "zzz ZZ zZ");
40
40
  ]
41
41
 
42
42
  let () =
43
43
  run_test_tt_main (
44
44
  "run length encoding tests" >:::
45
- List.concat [encode_tests; decode_tests; consistency_tests]
45
+ List.concat [run_length_encode_a_string_tests; run_length_decode_a_string_tests; encode_and_then_decode_tests]
46
46
  )
@@ -36,7 +36,7 @@ let tests = [
36
36
  "with apostrophes" >::
37
37
  ae [("first", 1); ("don't", 2); ("laugh", 1); ("then", 1); ("cry", 1)]
38
38
  (word_count "First: don't laugh. Then: don't cry.");
39
- "with_quotations" >::
39
+ "with quotations" >::
40
40
  ae [("joe", 1); ("can't", 1); ("tell", 1); ("between", 1); ("large", 2); ("and", 1)]
41
41
  (word_count "Joe can't tell between 'large' and large.");
42
42
  ]
@@ -2,7 +2,26 @@ open Core.Std
2
2
  open OUnit2
3
3
  open Beer_song
4
4
 
5
- let ae exp got _test_ctxt = assert_equal exp got ~printer:Fn.id
5
+ let zip s1 s2 =
6
+ let rec go s1 s2 acc = match (s1,s2) with
7
+ | ([], _) -> acc
8
+ | (_, []) -> acc
9
+ | (x::xs, y::ys) -> go xs ys ((x,y)::acc) in List.rev @@ go s1 s2 []
10
+
11
+ let find_diffs s1 s2 =
12
+ let s1 = String.to_list s1 in
13
+ let s2 = String.to_list s2 in
14
+ let both = zip s1 s2 in
15
+ List.find_mapi both ~f:(fun i (c1, c2) -> if c1 = c2 then None else Some (sprintf "Diff at index %d: %c <> %c" i c1 c2))
16
+
17
+ let diff_message s1 s2 = match find_diffs s1 s2 with
18
+ | None -> if String.length s1 = String.length s2 then "" else "Lengths of expected and actual differ but have a common prefix."
19
+ | Some m -> m
20
+
21
+ let ae exp got _test_ctxt =
22
+ if exp = got
23
+ then ()
24
+ else failwith @@ "Expected differs from actual: " ^ (diff_message exp got)
6
25
 
7
26
  let (* SUITE *)$(suite_name)_tests = [
8
27
  (* TEST
@@ -72,6 +72,13 @@
72
72
  "algebraic data types",
73
73
  "type classes"
74
74
  ]
75
+ },
76
+ {
77
+ "slug": "word-count",
78
+ "difficulty": 1,
79
+ "topics": [
80
+ "strings"
81
+ ]
75
82
  }
76
83
  ],
77
84
  "deprecated": [
@@ -0,0 +1,17 @@
1
+ {
2
+ "name": "word-count",
3
+ "ignore": [
4
+ "**/.*",
5
+ "node_modules",
6
+ "bower_components",
7
+ "output"
8
+ ],
9
+ "dependencies": {
10
+ "purescript-prelude": "^2.5.0",
11
+ "purescript-maps": "^2.1.2"
12
+ },
13
+ "devDependencies": {
14
+ "purescript-psci-support": "^2.0.0",
15
+ "purescript-test-unit": "^10.1.0"
16
+ }
17
+ }
@@ -0,0 +1,31 @@
1
+ module WordCount
2
+ ( wordCount
3
+ ) where
4
+
5
+ import Prelude
6
+ import Data.Array (foldl)
7
+ import Data.Maybe (Maybe(Just), maybe)
8
+ import Data.StrMap (StrMap, alter, empty)
9
+ import Data.String (Pattern(..), split, toLower, trim)
10
+ import Data.String.Regex (replace)
11
+ import Data.String.Regex.Flags (global)
12
+ import Data.String.Regex.Unsafe (unsafeRegex)
13
+
14
+ prepare :: String -> Array String
15
+ prepare = whitePunc
16
+ >>> remQuot
17
+ >>> aggWhite
18
+ >>> trim
19
+ >>> toLower
20
+ >>> split (Pattern " ")
21
+ where whitePunc = replace (unsafeRegex "[,\n:!&@$%^&.]" global) " "
22
+ remQuot = replace (unsafeRegex "'(\\w+)'" global) "$1"
23
+ aggWhite = replace (unsafeRegex " +" global) " "
24
+
25
+ freq :: Array String -> StrMap Int
26
+ freq = foldl mupd empty
27
+ where mupd acc word = alter cupd word acc
28
+ cupd = maybe 1 ((+) 1) >>> Just
29
+
30
+ wordCount :: String -> StrMap Int
31
+ wordCount = prepare >>> freq
@@ -0,0 +1,3 @@
1
+ module WordCount
2
+ ( wordCount
3
+ ) where
@@ -0,0 +1,89 @@
1
+ module Test.Main where
2
+
3
+ import Prelude
4
+ import Test.Unit.Assert as Assert
5
+ import Control.Monad.Eff (Eff)
6
+ import Data.StrMap (fromFoldable)
7
+ import Data.Tuple (Tuple(..))
8
+ import Test.Unit (suite, test)
9
+ import Test.Unit.Main (runTest)
10
+ import WordCount (wordCount)
11
+
12
+ main :: Eff _ Unit
13
+ main = runTest do
14
+ suite "WordCount.wordCount" do
15
+
16
+ test "count one word" $
17
+ Assert.equal (fromFoldable [Tuple "word" 1])
18
+ (wordCount "word")
19
+
20
+ test "count one of each word" $
21
+ Assert.equal (fromFoldable [ Tuple "one" 1
22
+ , Tuple "of" 1
23
+ , Tuple "each" 1
24
+ ])
25
+ (wordCount "one of each")
26
+
27
+ test "multiple occurrences of a word" $
28
+ Assert.equal (fromFoldable [ Tuple "one" 1
29
+ , Tuple "fish" 4
30
+ , Tuple "two" 1
31
+ , Tuple "red" 1
32
+ , Tuple "blue" 1
33
+ ])
34
+ (wordCount "one fish two fish red fish blue fish")
35
+
36
+ test "handles cramped lists" $
37
+ Assert.equal (fromFoldable [ Tuple "one" 1
38
+ , Tuple "two" 1
39
+ , Tuple "three" 1
40
+ ])
41
+ (wordCount "one,two,three")
42
+
43
+ test "handles expanded lists" $
44
+ Assert.equal (fromFoldable [ Tuple "one" 1
45
+ , Tuple "two" 1
46
+ , Tuple "three" 1
47
+ ])
48
+ (wordCount "one,\ntwo,\nthree")
49
+
50
+ test "ignore punctuation" $
51
+ Assert.equal (fromFoldable [ Tuple "car" 1
52
+ , Tuple "carpet" 1
53
+ , Tuple "as" 1
54
+ , Tuple "java" 1
55
+ , Tuple "javascript" 1
56
+ ])
57
+ (wordCount "car: carpet as java: javascript!!&@$%^&")
58
+
59
+ test "include numbers" $
60
+ Assert.equal (fromFoldable [ Tuple "testing" 2
61
+ , Tuple "1" 1
62
+ , Tuple "2" 1
63
+ ])
64
+ (wordCount "testing, 1, 2 testing")
65
+
66
+ test "normalize case" $
67
+ Assert.equal (fromFoldable [ Tuple "go" 3
68
+ , Tuple "stop" 2
69
+ ])
70
+ (wordCount "go Go GO Stop stop")
71
+
72
+ test "with apostrophes" $
73
+ Assert.equal (fromFoldable [ Tuple "first" 1
74
+ , Tuple "don't" 2
75
+ , Tuple "laugh" 1
76
+ , Tuple "then" 1
77
+ , Tuple "cry" 1
78
+ ])
79
+ (wordCount "First: don't laugh. Then: don't cry.")
80
+
81
+ test "with quotations" $
82
+ Assert.equal (fromFoldable [ Tuple "joe" 1
83
+ , Tuple "can't" 1
84
+ , Tuple "tell" 1
85
+ , Tuple "between" 1
86
+ , Tuple "large" 2
87
+ , Tuple "and" 1
88
+ ])
89
+ (wordCount "Joe can't tell between 'large' and large.")
@@ -0,0 +1,2 @@
1
+ def accumulate():
2
+ pass
@@ -0,0 +1,2 @@
1
+ def abbreviate():
2
+ pass
@@ -0,0 +1,3 @@
1
+ class Allergies(object):
2
+ def __init__(self):
3
+ pass
@@ -1,4 +1,4 @@
1
- class Allergies:
1
+ class Allergies(object):
2
2
 
3
3
  _allergies = [
4
4
  "eggs",
@@ -0,0 +1,2 @@
1
+ def detect_anagrams():
2
+ pass
@@ -0,0 +1,6 @@
1
+ def encode():
2
+ pass
3
+
4
+
5
+ def decode():
6
+ pass