trackler 1.0.0 → 1.0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (288) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +7 -0
  3. data/CHANGELOG.md +9 -1
  4. data/README.md +10 -0
  5. data/common/CONTRIBUTING.md +50 -2
  6. data/common/exercises/alphametics/canonical-data.json +10 -10
  7. data/common/exercises/markdown/canonical-data.json +4 -4
  8. data/common/exercises/pov/canonical-data.json +356 -0
  9. data/lib/trackler/version.rb +1 -1
  10. data/trackler.gemspec +1 -2
  11. data/tracks/c/config.json +11 -1
  12. data/tracks/c/exercises/binary-search/makefile +16 -0
  13. data/tracks/c/exercises/binary-search/src/example.c +21 -0
  14. data/tracks/c/exercises/binary-search/src/example.h +8 -0
  15. data/tracks/c/exercises/binary-search/test/test_binary_search.c +99 -0
  16. data/tracks/c/exercises/binary-search/test/vendor/unity.c +1300 -0
  17. data/tracks/c/exercises/binary-search/test/vendor/unity.h +274 -0
  18. data/tracks/c/exercises/binary-search/test/vendor/unity_internals.h +701 -0
  19. data/tracks/clojure/config.json +3 -2
  20. data/tracks/clojure/exercises/bank-account/project.clj +4 -0
  21. data/tracks/clojure/exercises/bank-account/src/example.clj +17 -0
  22. data/tracks/clojure/exercises/bank-account/test/bank_account_test.clj +44 -0
  23. data/tracks/clojure/exercises/isogram/project.clj +4 -0
  24. data/tracks/clojure/exercises/isogram/src/example.clj +5 -0
  25. data/tracks/clojure/exercises/isogram/test/isogram_test.clj +17 -0
  26. data/tracks/csharp/config.json +27 -87
  27. data/tracks/csharp/exercises/exercises.csproj +265 -1
  28. data/tracks/csharp/exercises/grep/Example.cs +114 -0
  29. data/tracks/csharp/exercises/grep/GrepTest.cs +376 -0
  30. data/tracks/csharp/exercises/paket.references +2 -1
  31. data/tracks/csharp/exercises/poker/Example.cs +96 -0
  32. data/tracks/csharp/exercises/poker/PokerTest.cs +171 -0
  33. data/tracks/csharp/exercises/sgf-parsing/Example.cs +61 -0
  34. data/tracks/csharp/exercises/sgf-parsing/SgfParsing.cs +13 -0
  35. data/tracks/csharp/exercises/sgf-parsing/SgfParsingTest.cs +158 -0
  36. data/tracks/csharp/paket.dependencies +2 -1
  37. data/tracks/csharp/paket.lock +72 -0
  38. data/tracks/ecmascript/exercises/simple-cipher/simple-cipher.spec.js +1 -1
  39. data/tracks/elisp/config.json +6 -1
  40. data/tracks/elisp/exercises/etl/etl-test.el +90 -0
  41. data/tracks/elisp/exercises/etl/etl.el +9 -0
  42. data/tracks/elisp/exercises/etl/example.el +22 -0
  43. data/tracks/elisp/exercises/nucleotide-count/example.el +19 -0
  44. data/tracks/elisp/exercises/nucleotide-count/nucleotide-count-test.el +34 -0
  45. data/tracks/elisp/exercises/nucleotide-count/nucleotide-count.el +9 -0
  46. data/tracks/elisp/exercises/perfect-numbers/example.el +28 -0
  47. data/tracks/elisp/exercises/perfect-numbers/perfect-numbers-test.el +24 -0
  48. data/tracks/elisp/exercises/perfect-numbers/perfect-numbers.el +10 -0
  49. data/tracks/elisp/exercises/roman-numerals/example.el +36 -0
  50. data/tracks/elisp/exercises/roman-numerals/roman-numerals-test.el +30 -0
  51. data/tracks/elisp/exercises/roman-numerals/roman-numerals.el +10 -0
  52. data/tracks/elisp/exercises/word-count/example.el +18 -0
  53. data/tracks/elisp/exercises/word-count/word-count-test.el +64 -0
  54. data/tracks/elisp/exercises/word-count/word-count.el +9 -0
  55. data/tracks/elixir/README.md +4 -4
  56. data/tracks/elixir/SETUP.md +3 -3
  57. data/tracks/elixir/docs/TESTS.md +3 -3
  58. data/tracks/elixir/exercises/accumulate/accumulate_test.exs +7 -7
  59. data/tracks/elixir/exercises/acronym/acronym_test.exs +5 -5
  60. data/tracks/elixir/exercises/allergies/allergies_test.exs +13 -13
  61. data/tracks/elixir/exercises/anagram/anagram_test.exs +12 -12
  62. data/tracks/elixir/exercises/atbash-cipher/atbash_cipher_test.exs +9 -9
  63. data/tracks/elixir/exercises/bank-account/bank_account_test.exs +5 -5
  64. data/tracks/elixir/exercises/beer-song/beer_song_test.exs +6 -6
  65. data/tracks/elixir/exercises/binary-search/binary_search_test.exs +7 -7
  66. data/tracks/elixir/exercises/binary/binary_test.exs +13 -13
  67. data/tracks/elixir/exercises/bob/bob_test.exs +15 -15
  68. data/tracks/elixir/exercises/bowling/bowling_test.exs +18 -18
  69. data/tracks/elixir/exercises/bracket-push/bracket_push_test.exs +12 -12
  70. data/tracks/elixir/exercises/change/change_test.exs +7 -7
  71. data/tracks/elixir/exercises/connect/connect_test.exs +9 -9
  72. data/tracks/elixir/exercises/crypto-square/crypto_square_test.exs +7 -7
  73. data/tracks/elixir/exercises/custom-set/custom_set_test.exs +11 -11
  74. data/tracks/elixir/exercises/diamond/diamond_test.exs +4 -4
  75. data/tracks/elixir/exercises/difference-of-squares/difference_of_squares_test.exs +10 -10
  76. data/tracks/elixir/exercises/dot-dsl/dot_dsl_test.exs +17 -17
  77. data/tracks/elixir/exercises/etl/etl_test.exs +5 -5
  78. data/tracks/elixir/exercises/flatten-array/flatten_array_test.exs +6 -6
  79. data/tracks/elixir/exercises/forth/forth_test.exs +16 -16
  80. data/tracks/elixir/exercises/gigasecond/gigasecond_test.exs +5 -5
  81. data/tracks/elixir/exercises/grade-school/grade_school_test.exs +6 -6
  82. data/tracks/elixir/exercises/grains/grains_test.exs +9 -9
  83. data/tracks/elixir/exercises/hamming/hamming_test.exs +6 -6
  84. data/tracks/elixir/exercises/hello-world/hello_world_test.exs +3 -3
  85. data/tracks/elixir/exercises/hexadecimal/hexadecimal_test.exs +11 -11
  86. data/tracks/elixir/exercises/isogram/isogram_test.exs +10 -10
  87. data/tracks/elixir/exercises/kindergarten-garden/garden_test.exs +7 -7
  88. data/tracks/elixir/exercises/largest-series-product/largest_series_product_test.exs +17 -17
  89. data/tracks/elixir/exercises/leap/leap_test.exs +5 -5
  90. data/tracks/elixir/exercises/list-ops/list_ops_test.exs +26 -26
  91. data/tracks/elixir/exercises/luhn/luhn_test.exs +7 -7
  92. data/tracks/elixir/exercises/markdown/markdown_test.exs +10 -10
  93. data/tracks/elixir/exercises/meetup/meetup_test.exs +92 -92
  94. data/tracks/elixir/exercises/minesweeper/minesweeper_test.exs +8 -8
  95. data/tracks/elixir/exercises/nth-prime/nth_prime_test.exs +6 -6
  96. data/tracks/elixir/exercises/nucleotide-count/example.exs +0 -5
  97. data/tracks/elixir/exercises/nucleotide-count/nucleotide_count_test.exs +7 -7
  98. data/tracks/elixir/exercises/palindrome-products/palindrome_products_test.exs +6 -6
  99. data/tracks/elixir/exercises/pangram/pangram_test.exs +11 -11
  100. data/tracks/elixir/exercises/parallel-letter-frequency/parallel_letter_frequency_test.exs +10 -10
  101. data/tracks/elixir/exercises/pascals-triangle/pascals_triangle_test.exs +7 -7
  102. data/tracks/elixir/exercises/phone-number/phone_number_test.exs +10 -10
  103. data/tracks/elixir/exercises/prime-factors/prime_factors_test.exs +13 -13
  104. data/tracks/elixir/exercises/pythagorean-triplet/pythagorean_triplet_test.exs +8 -8
  105. data/tracks/elixir/exercises/queen-attack/queen_attack_test.exs +16 -16
  106. data/tracks/elixir/exercises/rail-fence-cipher/rail_fence_cipher_test.exs +13 -13
  107. data/tracks/elixir/exercises/raindrops/raindrops_test.exs +17 -17
  108. data/tracks/elixir/exercises/rna-transcription/rna_transcription_test.exs +6 -6
  109. data/tracks/elixir/exercises/robot-simulator/robot_simulator_test.exs +6 -6
  110. data/tracks/elixir/exercises/roman-numerals/roman_numerals_test.exs +19 -19
  111. data/tracks/elixir/exercises/run-length-encoding/rle_test.exs +6 -6
  112. data/tracks/elixir/exercises/saddle-points/saddle_points_test.exs +11 -11
  113. data/tracks/elixir/exercises/scrabble-score/scrabble_score_test.exs +9 -9
  114. data/tracks/elixir/exercises/sieve/sieve_test.exs +3 -3
  115. data/tracks/elixir/exercises/space-age/space_age_test.exs +9 -9
  116. data/tracks/elixir/exercises/sublist/sublist_test.exs +20 -20
  117. data/tracks/elixir/exercises/sum-of-multiples/sum_of_multiples_test.exs +11 -11
  118. data/tracks/elixir/exercises/test_helper.exs +1 -1
  119. data/tracks/elixir/exercises/triangle/triangle_test.exs +16 -16
  120. data/tracks/elixir/exercises/word-count/word_count_test.exs +9 -9
  121. data/tracks/elixir/exercises/wordy/wordy_test.exs +16 -16
  122. data/tracks/elixir/exercises/zipper/zipper_test.exs +13 -13
  123. data/tracks/fsharp/build.fsx +2 -7
  124. data/tracks/fsharp/config.json +0 -104
  125. data/tracks/fsharp/exercises/grep/GrepTest.fs +7 -1
  126. data/tracks/go/config.json +1 -0
  127. data/tracks/go/exercises/acronym/acronym_test.go +36 -0
  128. data/tracks/go/exercises/acronym/example.go +21 -0
  129. data/tracks/go/exercises/palindrome-products/example.go +2 -0
  130. data/tracks/go/exercises/palindrome-products/palindrome_products_test.go +10 -0
  131. data/tracks/go/exercises/phone-number/example.go +2 -0
  132. data/tracks/go/exercises/phone-number/phone_number_test.go +44 -27
  133. data/tracks/go/exercises/robot-simulator/defs.go +6 -6
  134. data/tracks/go/exercises/robot-simulator/example.go +22 -22
  135. data/tracks/go/exercises/robot-simulator/robot_simulator_step2_test.go +28 -28
  136. data/tracks/go/exercises/robot-simulator/robot_simulator_step3_test.go +75 -76
  137. data/tracks/go/exercises/robot-simulator/robot_simulator_test.go +10 -4
  138. data/tracks/haskell/exercises/anagram/HINTS.md +22 -0
  139. data/tracks/haskell/exercises/anagram/package.yaml +3 -0
  140. data/tracks/haskell/exercises/anagram/src/Example.hs +10 -7
  141. data/tracks/haskell/exercises/anagram/test/Tests.hs +9 -3
  142. data/tracks/haskell/exercises/beer-song/HINTS.md +18 -0
  143. data/tracks/haskell/exercises/beer-song/src/Beer.hs +301 -3
  144. data/tracks/haskell/exercises/beer-song/src/Example.hs +5 -3
  145. data/tracks/haskell/exercises/beer-song/test/Tests.hs +332 -23
  146. data/tracks/haskell/exercises/crypto-square/src/CryptoSquare.hs +3 -17
  147. data/tracks/haskell/exercises/crypto-square/src/Example.hs +12 -20
  148. data/tracks/haskell/exercises/crypto-square/test/Tests.hs +46 -86
  149. data/tracks/haskell/exercises/leap/HINTS.md +11 -0
  150. data/tracks/haskell/exercises/leap/src/LeapYear.hs +1 -0
  151. data/tracks/java/exercises/pangram/src/test/java/PangramTest.java +34 -4
  152. data/tracks/lua/exercises/pov/pov_spec.lua +0 -13
  153. data/tracks/mips/docs/ABOUT.md +1 -1
  154. data/tracks/objective-c/config.json +225 -0
  155. data/tracks/objective-c/exercises/largest-series-product/LargestSeriesProductExample.h +8 -0
  156. data/tracks/objective-c/exercises/largest-series-product/LargestSeriesProductExample.m +63 -0
  157. data/tracks/objective-c/exercises/largest-series-product/LargestSeriesProductTest.m +84 -0
  158. data/tracks/objective-c/xcodeProject/ObjectiveC.xcodeproj/project.pbxproj +18 -0
  159. data/tracks/ocaml/.travis-ci.sh +23 -0
  160. data/tracks/ocaml/.travis.yml +5 -1
  161. data/tracks/ocaml/Makefile +41 -0
  162. data/tracks/ocaml/config.json +18 -0
  163. data/tracks/ocaml/exercises/anagram/Makefile +1 -0
  164. data/tracks/ocaml/exercises/beer-song/Makefile +1 -0
  165. data/tracks/ocaml/exercises/beer-song/{beer.mli → beer_song.mli} +0 -0
  166. data/tracks/ocaml/exercises/beer-song/example.ml +1 -1
  167. data/tracks/ocaml/exercises/beer-song/test.ml +7 -6
  168. data/tracks/ocaml/exercises/bob/Makefile +1 -0
  169. data/tracks/ocaml/exercises/bowling/Makefile +1 -0
  170. data/tracks/ocaml/exercises/custom-set/Makefile +1 -0
  171. data/tracks/ocaml/exercises/difference-of-squares/.merlin +5 -0
  172. data/tracks/ocaml/exercises/difference-of-squares/Makefile +11 -0
  173. data/tracks/ocaml/exercises/difference-of-squares/difference_of_squares.mli +8 -0
  174. data/tracks/ocaml/exercises/difference-of-squares/example.ml +21 -0
  175. data/tracks/ocaml/exercises/difference-of-squares/test.ml +32 -0
  176. data/tracks/ocaml/exercises/grade-school/Makefile +1 -0
  177. data/tracks/ocaml/exercises/grade-school/{school.mli → grade_school.mli} +0 -0
  178. data/tracks/ocaml/exercises/grade-school/test.ml +27 -27
  179. data/tracks/ocaml/exercises/hamming/Makefile +1 -0
  180. data/tracks/ocaml/exercises/hangman/Makefile +1 -0
  181. data/tracks/ocaml/exercises/hello-world/Makefile +1 -1
  182. data/tracks/ocaml/exercises/hello-world/{hello.ml → hello_world.ml} +0 -0
  183. data/tracks/ocaml/exercises/hello-world/{hello.mli → hello_world.mli} +0 -0
  184. data/tracks/ocaml/exercises/hello-world/test.ml +1 -1
  185. data/tracks/ocaml/exercises/hexadecimal/Makefile +1 -0
  186. data/tracks/ocaml/exercises/leap/Makefile +1 -1
  187. data/tracks/ocaml/exercises/list-ops/Makefile +1 -0
  188. data/tracks/ocaml/exercises/luhn/Makefile +1 -0
  189. data/tracks/ocaml/exercises/minesweeper/Makefile +1 -0
  190. data/tracks/ocaml/exercises/nucleotide-count/Makefile +1 -0
  191. data/tracks/ocaml/exercises/nucleotide-count/{dna.mli → nucleotide_count.mli} +0 -0
  192. data/tracks/ocaml/exercises/nucleotide-count/test.ml +7 -7
  193. data/tracks/ocaml/exercises/phone-number/Makefile +1 -0
  194. data/tracks/ocaml/exercises/phone-number/{phone.mli → phone_number.mli} +0 -0
  195. data/tracks/ocaml/exercises/phone-number/test.ml +10 -10
  196. data/tracks/ocaml/exercises/point-mutations/Makefile +8 -0
  197. data/tracks/ocaml/exercises/point-mutations/example.ml +0 -0
  198. data/tracks/ocaml/exercises/prime-factors/Makefile +1 -0
  199. data/tracks/ocaml/exercises/raindrops/.merlin +5 -0
  200. data/tracks/ocaml/exercises/raindrops/Makefile +11 -0
  201. data/tracks/ocaml/exercises/raindrops/example.ml +11 -0
  202. data/tracks/ocaml/exercises/raindrops/raindrops.mli +7 -0
  203. data/tracks/ocaml/exercises/raindrops/test.ml +48 -0
  204. data/tracks/ocaml/exercises/rna-transcription/Makefile +1 -0
  205. data/tracks/ocaml/exercises/rna-transcription/{dna.mli → rna_transcription.mli} +0 -0
  206. data/tracks/ocaml/exercises/rna-transcription/test.ml +6 -6
  207. data/tracks/ocaml/exercises/roman-numerals/Makefile +1 -0
  208. data/tracks/ocaml/exercises/say/.gitignore +1 -0
  209. data/tracks/ocaml/exercises/say/.merlin +5 -0
  210. data/tracks/ocaml/exercises/say/Makefile +11 -0
  211. data/tracks/ocaml/exercises/say/example.ml +52 -0
  212. data/tracks/ocaml/exercises/say/say.mli +8 -0
  213. data/tracks/ocaml/exercises/say/test.ml +65 -0
  214. data/tracks/ocaml/exercises/space-age/Makefile +1 -0
  215. data/tracks/ocaml/exercises/word-count/Makefile +1 -0
  216. data/tracks/ocaml/exercises/word-count/example.ml +1 -1
  217. data/tracks/ocaml/exercises/zipper/HINT.md +5 -6
  218. data/tracks/ocaml/exercises/zipper/Makefile +1 -0
  219. data/tracks/ocaml/exercises/zipper/example.ml +2 -2
  220. data/tracks/ocaml/exercises/zipper/tree.ml +1 -1
  221. data/tracks/php/config.json +7 -1
  222. data/tracks/php/exercises/variable-length-quantity/example.php +56 -0
  223. data/tracks/php/exercises/variable-length-quantity/variable-length-quantity_test.php +149 -0
  224. data/tracks/python/config.json +1 -1
  225. data/tracks/ruby/.rubocop.yml +1915 -26
  226. data/tracks/ruby/bin/generate-acronym +7 -0
  227. data/tracks/ruby/bin/generate-nth-prime +7 -0
  228. data/tracks/ruby/config.json +482 -0
  229. data/tracks/ruby/exercises/acronym/.version +1 -0
  230. data/tracks/ruby/exercises/acronym/acronym_test.rb +45 -21
  231. data/tracks/ruby/exercises/acronym/example.rb +1 -1
  232. data/tracks/ruby/exercises/acronym/example.tt +19 -0
  233. data/tracks/ruby/exercises/anagram/anagram_test.rb +1 -1
  234. data/tracks/ruby/exercises/nth-prime/.version +1 -0
  235. data/tracks/ruby/exercises/nth-prime/example.rb +4 -0
  236. data/tracks/ruby/exercises/nth-prime/example.tt +23 -0
  237. data/tracks/ruby/exercises/nth-prime/nth_prime_test.rb +33 -10
  238. data/tracks/ruby/exercises/raindrops/.version +1 -1
  239. data/tracks/ruby/exercises/raindrops/example.rb +1 -1
  240. data/tracks/ruby/exercises/raindrops/raindrops_test.rb +20 -5
  241. data/tracks/ruby/lib/acronym_cases.rb +19 -0
  242. data/tracks/ruby/lib/generator.rb +3 -2
  243. data/tracks/ruby/lib/nth_prime_cases.rb +23 -0
  244. data/tracks/ruby/lib/raindrop_cases.rb +1 -1
  245. data/tracks/rust/README.md +1 -1
  246. data/tracks/scala/exercises/leap/src/test/scala/leap_test.scala +10 -0
  247. data/tracks/scala/exercises/prime-factors/example.scala +2 -5
  248. data/tracks/scala/exercises/prime-factors/src/test/scala/primefactors_test.scala +11 -13
  249. data/tracks/scheme/{anagram → exercises/anagram}/anagram-test.scm +0 -0
  250. data/tracks/scheme/{anagram → exercises/anagram}/anagram.scm +0 -0
  251. data/tracks/scheme/{anagram → exercises/anagram}/example.scm +0 -0
  252. data/tracks/scheme/{bob → exercises/bob}/bob-test.scm +0 -0
  253. data/tracks/scheme/{bob → exercises/bob}/bob.scm +0 -0
  254. data/tracks/scheme/{bob → exercises/bob}/example.scm +0 -0
  255. data/tracks/scheme/{difference-of-squares → exercises/difference-of-squares}/difference-of-squares-test.scm +0 -0
  256. data/tracks/scheme/{difference-of-squares → exercises/difference-of-squares}/example.scm +0 -0
  257. data/tracks/scheme/{difference-of-squares → exercises/difference-of-squares}/squares.scm +0 -0
  258. data/tracks/scheme/{grains → exercises/grains}/example.scm +0 -0
  259. data/tracks/scheme/{grains → exercises/grains}/grains-test.scm +0 -0
  260. data/tracks/scheme/{grains → exercises/grains}/grains.scm +0 -0
  261. data/tracks/scheme/{hamming → exercises/hamming}/example.scm +0 -0
  262. data/tracks/scheme/{hamming → exercises/hamming}/hamming-test.scm +0 -0
  263. data/tracks/scheme/{hamming → exercises/hamming}/hamming.scm +0 -0
  264. data/tracks/scheme/{hello-world → exercises/hello-world}/example.scm +0 -0
  265. data/tracks/scheme/{hello-world → exercises/hello-world}/hello-world-test.scm +0 -0
  266. data/tracks/scheme/{hello-world → exercises/hello-world}/hello-world.scm +0 -0
  267. data/tracks/scheme/{leap → exercises/leap}/example.scm +0 -0
  268. data/tracks/scheme/{leap → exercises/leap}/leap-test.scm +0 -0
  269. data/tracks/scheme/{leap → exercises/leap}/leap-year.scm +0 -0
  270. data/tracks/scheme/{list-ops → exercises/list-ops}/example.scm +0 -0
  271. data/tracks/scheme/{list-ops → exercises/list-ops}/list-ops-test.scm +0 -0
  272. data/tracks/scheme/{list-ops → exercises/list-ops}/list-ops.scm +0 -0
  273. data/tracks/scheme/{nucleotide-count → exercises/nucleotide-count}/example.scm +0 -0
  274. data/tracks/scheme/{nucleotide-count → exercises/nucleotide-count}/nucleotide-count-test.scm +0 -0
  275. data/tracks/scheme/{nucleotide-count → exercises/nucleotide-count}/nucleotide-count.scm +0 -0
  276. data/tracks/scheme/{phone-number → exercises/phone-number}/example.scm +0 -0
  277. data/tracks/scheme/{phone-number → exercises/phone-number}/phone-number-test.scm +0 -0
  278. data/tracks/scheme/{phone-number → exercises/phone-number}/phone-number.scm +0 -0
  279. data/tracks/scheme/{raindrops → exercises/raindrops}/example.scm +0 -0
  280. data/tracks/scheme/{raindrops → exercises/raindrops}/raindrops-test.scm +0 -0
  281. data/tracks/scheme/{raindrops → exercises/raindrops}/raindrops.scm +0 -0
  282. data/tracks/scheme/{rna-transcription → exercises/rna-transcription}/dna.scm +0 -0
  283. data/tracks/scheme/{rna-transcription → exercises/rna-transcription}/example.scm +0 -0
  284. data/tracks/scheme/{rna-transcription → exercises/rna-transcription}/rna-transcription-test.scm +0 -0
  285. data/tracks/scheme/{robot-name → exercises/robot-name}/example.scm +0 -0
  286. data/tracks/scheme/{robot-name → exercises/robot-name}/robot-name-test.scm +0 -0
  287. data/tracks/scheme/{robot-name → exercises/robot-name}/robot.scm +0 -0
  288. metadata +125 -64
@@ -1 +1,2 @@
1
- NUnit
1
+ NUnit
2
+ Sprache
@@ -0,0 +1,96 @@
1
+ using System;
2
+ using System.Collections.Generic;
3
+ using System.Linq;
4
+
5
+ public static class Poker
6
+ {
7
+ private struct Card
8
+ {
9
+ public int Rank;
10
+ public int Suit;
11
+ }
12
+
13
+ private struct Hand
14
+ {
15
+ public string Input;
16
+ public int Score;
17
+ }
18
+
19
+ public static IEnumerable<string> BestHands(IEnumerable<string> hands)
20
+ {
21
+ var scoredHands = hands.Select(ParseHand).ToArray();
22
+ var maxScore = scoredHands.Max(h => h.Score);
23
+ return scoredHands.Where(h => h.Score == maxScore).Select(h => h.Input).ToList();
24
+ }
25
+
26
+ private static Hand ParseHand(string hand) => new Hand { Input = hand, Score = ScoreHand(ParseCards(hand)) };
27
+
28
+ private static Card[] ParseCards(string hand) => hand.Split(' ').Select(ParseCard).OrderByDescending(c => c.Rank).ToArray();
29
+
30
+ private static Card ParseCard(string card) => new Card { Rank = ParseRank(card), Suit = ParseSuit(card) };
31
+
32
+ private static int ParseRank(string card) => "..23456789TJQKA".IndexOf(card[0]);
33
+
34
+ private static int ParseSuit(string card) => ".HSDC".IndexOf(card[1]);
35
+
36
+ private static int ScoreHand(Card[] cards)
37
+ {
38
+ var cardsByRank = cards
39
+ .GroupBy(c => c.Rank)
40
+ .OrderByDescending(c => c.Count())
41
+ .Select(g => g.Max(c => c.Rank))
42
+ .ToArray();
43
+
44
+ var rankCounts = cards
45
+ .GroupBy(c => c.Rank)
46
+ .Select(g => g.Count())
47
+ .OrderByDescending(c => c)
48
+ .ToArray();
49
+
50
+ var ranks = cards.Select(c => c.Rank).ToArray();
51
+ var suits = cards.Select(c => c.Suit).ToArray();
52
+
53
+ if (ranks.SequenceEqual(new[] { 14, 5, 4, 3, 2 }))
54
+ {
55
+ ranks = new[] { 1, 2, 3, 4, 5 };
56
+ }
57
+
58
+ var flush = suits.Distinct().Count() == 1;
59
+ var straight = ranks.Distinct().Count() == 5 && ranks[0] - ranks[4] == 4;
60
+
61
+ if (straight && flush)
62
+ {
63
+ return 800 + ranks.First();
64
+ }
65
+ if (rankCounts.SequenceEqual(new [] { 4, 1 }))
66
+ {
67
+ return 700 + cardsByRank[0];
68
+ }
69
+ if (rankCounts.SequenceEqual(new[] { 3, 2 }))
70
+ {
71
+ return 600 + cardsByRank[0];
72
+ }
73
+ if (flush)
74
+ {
75
+ return 500 + ranks.First();
76
+ }
77
+ if (straight)
78
+ {
79
+ return 400 + ranks.First();
80
+ }
81
+ if (rankCounts.SequenceEqual(new[] { 3, 1, 1 }))
82
+ {
83
+ return 300 + cardsByRank[0];
84
+ }
85
+ if (rankCounts.SequenceEqual(new[] { 2, 2, 1 }))
86
+ {
87
+ return 200 + Math.Max(cardsByRank[0], cardsByRank[1]);
88
+ }
89
+ if (rankCounts.SequenceEqual(new[] { 2, 1, 1, 1 }))
90
+ {
91
+ return 100 + cardsByRank[0];
92
+ }
93
+
94
+ return ranks.Max();
95
+ }
96
+ }
@@ -0,0 +1,171 @@
1
+ using NUnit.Framework;
2
+
3
+ public class PokerTest
4
+ {
5
+ [Test]
6
+ public void One_hand()
7
+ {
8
+ const string hand = "4S 5S 7H 8D JC";
9
+ Assert.That(Poker.BestHands(new[] { hand }), Is.EqualTo(new[] { hand }));
10
+ }
11
+
12
+ [Ignore("Remove to run test")]
13
+ [Test]
14
+ public void Nothing_vs_one_pair()
15
+ {
16
+ const string nothing = "4S 5H 6S 8D JH";
17
+ const string pairOf4 = "2S 4H 6S 4D JH";
18
+ Assert.That(Poker.BestHands(new[] { nothing, pairOf4 }), Is.EqualTo(new[] { pairOf4 }));
19
+ }
20
+
21
+ [Ignore("Remove to run test")]
22
+ [Test]
23
+ public void Two_pairs()
24
+ {
25
+ const string pairOf2 = "4S 2H 6S 2D JH";
26
+ const string pairOf4 = "2S 4H 6S 4D JH";
27
+ Assert.That(Poker.BestHands(new[] { pairOf2, pairOf4 }), Is.EqualTo(new[] { pairOf4 }));
28
+ }
29
+
30
+ [Ignore("Remove to run test")]
31
+ [Test]
32
+ public void One_pair_vs_double_pair()
33
+ {
34
+ const string pairOf8 = "2S 8H 6S 8D JH";
35
+ const string doublePair = "4S 5H 4S 8D 5H";
36
+ Assert.That(Poker.BestHands(new[] { pairOf8, doublePair }), Is.EqualTo(new[] { doublePair }));
37
+ }
38
+
39
+ [Ignore("Remove to run test")]
40
+ [Test]
41
+ public void Two_double_pairs()
42
+ {
43
+ const string doublePair2And8 = "2S 8H 2S 8D JH";
44
+ const string doublePair4And5 = "4S 5H 4S 8D 5H";
45
+ Assert.That(Poker.BestHands(new[] { doublePair2And8, doublePair4And5 }), Is.EqualTo(new[] { doublePair2And8 }));
46
+ }
47
+
48
+ [Ignore("Remove to run test")]
49
+ [Test]
50
+ public void Double_pair_vs_three()
51
+ {
52
+ const string doublePair2And8 = "2S 8H 2S 8D JH";
53
+ const string threeOf4 = "4S 5H 4S 8D 4H";
54
+ Assert.That(Poker.BestHands(new[] { doublePair2And8, threeOf4 }), Is.EqualTo(new[] { threeOf4 }));
55
+ }
56
+
57
+ [Ignore("Remove to run test")]
58
+ [Test]
59
+ public void Two_threes()
60
+ {
61
+ const string threeOf2 = "2S 2H 2S 8D JH";
62
+ const string threeOf1 = "4S AH AS 8D AH";
63
+ Assert.That(Poker.BestHands(new[] { threeOf2, threeOf1 }), Is.EqualTo(new[] { threeOf1 }));
64
+ }
65
+
66
+ [Ignore("Remove to run test")]
67
+ [Test]
68
+ public void Three_vs_straight()
69
+ {
70
+ const string threeOf4 = "4S 5H 4S 8D 4H";
71
+ const string straight = "3S 4H 2S 6D 5H";
72
+ Assert.That(Poker.BestHands(new[] { threeOf4, straight }), Is.EqualTo(new[] { straight }));
73
+ }
74
+
75
+ [Ignore("Remove to run test")]
76
+ [Test]
77
+ public void Two_straights()
78
+ {
79
+ const string straightTo8 = "4S 6H 7S 8D 5H";
80
+ const string straightTo9 = "5S 7H 8S 9D 6H";
81
+ Assert.That(Poker.BestHands(new[] { straightTo8, straightTo9 }), Is.EqualTo(new[] { straightTo9 }));
82
+
83
+ const string straightTo1 = "AS QH KS TD JH";
84
+ const string straightTo5 = "4S AH 3S 2D 5H";
85
+ Assert.That(Poker.BestHands(new[] { straightTo1, straightTo5 }), Is.EqualTo(new[] { straightTo1 }));
86
+ }
87
+
88
+ [Ignore("Remove to run test")]
89
+ [Test]
90
+ public void Straight_vs_flush()
91
+ {
92
+ const string straightTo8 = "4S 6H 7S 8D 5H";
93
+ const string flushTo7 = "2S 4S 5S 6S 7S";
94
+ Assert.That(Poker.BestHands(new[] { straightTo8, flushTo7 }), Is.EqualTo(new[] { flushTo7 }));
95
+ }
96
+
97
+ [Ignore("Remove to run test")]
98
+ [Test]
99
+ public void Two_flushes()
100
+ {
101
+ const string flushTo8 = "3H 6H 7H 8H 5H";
102
+ const string flushTo7 = "2S 4S 5S 6S 7S";
103
+ Assert.That(Poker.BestHands(new[] { flushTo8, flushTo7 }), Is.EqualTo(new[] { flushTo8 }));
104
+ }
105
+
106
+ [Ignore("Remove to run test")]
107
+ [Test]
108
+ public void Flush_vs_full()
109
+ {
110
+ const string flushTo8 = "3H 6H 7H 8H 5H";
111
+ const string full = "4S 5H 4S 5D 4H";
112
+ Assert.That(Poker.BestHands(new[] { full, flushTo8 }), Is.EqualTo(new[] { full }));
113
+ }
114
+
115
+ [Ignore("Remove to run test")]
116
+ [Test]
117
+ public void Two_fulls()
118
+ {
119
+ const string fullOf4By9 = "4H 4S 4D 9S 9D";
120
+ const string fullOf5By8 = "5H 5S 5D 8S 8D";
121
+ Assert.That(Poker.BestHands(new[] { fullOf4By9, fullOf5By8 }), Is.EqualTo(new[] { fullOf5By8 }));
122
+ }
123
+
124
+ [Ignore("Remove to run test")]
125
+ [Test]
126
+ public void Full_vs_square()
127
+ {
128
+ const string full = "4S 5H 4S 5D 4H";
129
+ const string squareOf3 = "3S 3H 2S 3D 3H";
130
+ Assert.That(Poker.BestHands(new[] { full, squareOf3 }), Is.EqualTo(new[] { squareOf3 }));
131
+ }
132
+
133
+ [Ignore("Remove to run test")]
134
+ [Test]
135
+ public void Two_squares()
136
+ {
137
+ const string squareOf2 = "2S 2H 2S 8D 2H";
138
+ const string squareOf5 = "4S 5H 5S 5D 5H";
139
+ Assert.That(Poker.BestHands(new[] { squareOf2, squareOf5 }), Is.EqualTo(new[] { squareOf5 }));
140
+ }
141
+
142
+ [Ignore("Remove to run test")]
143
+ [Test]
144
+ public void Square_vs_straight_flush()
145
+ {
146
+ const string squareOf5 = "4S 5H 5S 5D 5H";
147
+ const string straightFlushTo9 = "5S 7S 8S 9S 6S";
148
+ Assert.That(Poker.BestHands(new[] { squareOf5, straightFlushTo9 }), Is.EqualTo(new[] { straightFlushTo9 }));
149
+ }
150
+
151
+ [Ignore("Remove to run test")]
152
+ [Test]
153
+ public void Two_straight_flushes()
154
+ {
155
+ const string straightFlushTo8 = "4H 6H 7H 8H 5H";
156
+ const string straightFlushTo9 = "5S 7S 8S 9S 6S";
157
+ Assert.That(Poker.BestHands(new[] { straightFlushTo8, straightFlushTo9 }),
158
+ Is.EqualTo(new[] { straightFlushTo9 }));
159
+ }
160
+
161
+ [Ignore("Remove to run test")]
162
+ [Test]
163
+ public void Three_hand_with_tie()
164
+ {
165
+ const string spadeStraightTo9 = "9S 8S 7S 6S 5S";
166
+ const string diamondStraightTo9 = "9D 8D 7D 6D 5D";
167
+ const string threeOf4 = "4D 4S 4H QS KS";
168
+ Assert.That(Poker.BestHands(new[] { spadeStraightTo9, diamondStraightTo9, threeOf4 }),
169
+ Is.EqualTo(new[] { spadeStraightTo9, diamondStraightTo9 }));
170
+ }
171
+ }
@@ -0,0 +1,61 @@
1
+ using System;
2
+ using System.Collections.Generic;
3
+ using System.Linq;
4
+ using Sprache;
5
+
6
+ public class SgfTree
7
+ {
8
+ public IDictionary<string, string[]> Data { get; }
9
+ public SgfTree[] Children { get; }
10
+
11
+ public SgfTree(IDictionary<string, string[]> data, params SgfTree[] children)
12
+ {
13
+ Data = data;
14
+ Children = children;
15
+ }
16
+ }
17
+
18
+ public static class SgfParser
19
+ {
20
+ private static char Unescape(char c) => c == 'n' || c == 'r' || c == 't' ? ' ' : c;
21
+ private static string ToString(IEnumerable<char> chars) => new string(chars.ToArray());
22
+
23
+ private static readonly Parser<char> NormalChar = Parse.Char(c => c != '\\' && c != ']', "Normal char");
24
+ private static readonly Parser<char> EscapedChar = Parse.Char('\\').Then(_ => Parse.AnyChar.Token().Select(Unescape));
25
+ private static readonly Parser<string> CValueType = EscapedChar.Or(NormalChar).Many().Select(ToString);
26
+ private static readonly Parser<string> PropValue = CValueType.Contained(Parse.Char('['), Parse.Char(']'));
27
+ private static readonly Parser<string> PropIdent = Parse.Char(char.IsUpper, "Upper case character").Select(c => c.ToString());
28
+ private static readonly Parser<IDictionary<string, string[]>> Property = PropIdent.Then(ident => PropValue.Many().Select(values => PropertyToData(ident, values)));
29
+ private static readonly Parser<IDictionary<string, string[]>> Node = Parse.Char(';').Then(_ => Property.Optional().Select(o => o.GetOrDefault() ?? new Dictionary<string, string[]>()));
30
+
31
+ private static Parser<SgfTree> GameTree() =>
32
+ Parse.Char('(').Then(c =>
33
+ Node.AtLeastOnce().Then(nodes =>
34
+ GameTree().Many().Then(trees => Parse.Char(')')
35
+ .Select(___ => NodesToTree(nodes, trees)))));
36
+
37
+ public static SgfTree ParseTree(string input) => GameTree().Parse(input);
38
+
39
+ private static SgfTree NodesToTree(IEnumerable<IDictionary<string, string[]>> properties, IEnumerable<SgfTree> trees)
40
+ {
41
+ var numberOfProperties = properties.Count();
42
+
43
+ if (numberOfProperties == 0)
44
+ {
45
+ throw new InvalidOperationException("Can only create tree from non-empty nodes list");
46
+ }
47
+
48
+ if (numberOfProperties == 1)
49
+ {
50
+ return new SgfTree(properties.First(), trees.ToArray());
51
+ }
52
+
53
+ return new SgfTree(properties.First(), NodesToTree(properties.Skip(1), trees));
54
+ }
55
+
56
+ private static IDictionary<string, string[]> PropertyToData(string key, IEnumerable<string> values) =>
57
+ new Dictionary<string, string[]>
58
+ {
59
+ [key] = values.ToArray()
60
+ };
61
+ }
@@ -0,0 +1,13 @@
1
+ using System.Collections.Generic;
2
+
3
+ public class SgfTree
4
+ {
5
+ public IDictionary<string, string[]> Data { get; }
6
+ public SgfTree[] Children { get; }
7
+
8
+ public SgfTree(IDictionary<string, string[]> data, params SgfTree[] children)
9
+ {
10
+ Data = data;
11
+ Children = children;
12
+ }
13
+ }
@@ -0,0 +1,158 @@
1
+ using System.Collections.Generic;
2
+ using System.Linq;
3
+ using NUnit.Framework;
4
+
5
+ public class SgfParsingTest
6
+ {
7
+ // This exercises requires you to do somewhat more complicated parsing.
8
+ // This is the perfect exercise to get to know a parser library, of which
9
+ // there are several available. A simple one is Sprache (https://github.com/sprache/Sprache),
10
+ // a more complex one is Antlr (http://www.antlr.org/). You can also build
11
+ // your own parser of course!
12
+
13
+ // A tree consists of two parts:
14
+ // - The node's data: a map of type Dictionary<string, string list>
15
+ // - A list of children (which are itself trees)
16
+
17
+ private static SgfTree TreeWithChildren(IDictionary<string, string[]> data, SgfTree[] children) => new SgfTree(data, children);
18
+ private static SgfTree TreeWithSingleChild(IDictionary<string, string[]> data, SgfTree child) => new SgfTree(data, child);
19
+ private static SgfTree TreeWithNoChildren(IDictionary<string, string[]> data) => new SgfTree(data);
20
+
21
+ private static IDictionary<string, string[]> CreateData(string key, params string[] values) => new Dictionary<string, string[]> { [key] = values };
22
+
23
+ [Test]
24
+ public void Empty_value()
25
+ {
26
+ const string input = "";
27
+ Assert.That(() => SgfParser.ParseTree(input), Throws.Exception);
28
+ }
29
+
30
+ [Ignore("Remove to run test")]
31
+ [Test]
32
+ public void Tree_without_nodes()
33
+ {
34
+ const string input = "()";
35
+ Assert.That(() => SgfParser.ParseTree(input), Throws.Exception);
36
+ }
37
+
38
+ [Ignore("Remove to run test")]
39
+ [Test]
40
+ public void Node_without_tree()
41
+ {
42
+ const string input = ";";
43
+ Assert.That(() => SgfParser.ParseTree(input), Throws.Exception);
44
+ }
45
+
46
+ [Ignore("Remove to run test")]
47
+ [Test]
48
+ public void Node_without_properties()
49
+ {
50
+ const string input = "(;)";
51
+ var expected = TreeWithNoChildren(new Dictionary<string, string[]>());
52
+ Assert.That(SgfParser.ParseTree(input), Is.EqualTo(expected).Using(SgfTreeEqualityComparer.Instance));
53
+ }
54
+
55
+ [Ignore("Remove to run test")]
56
+ [Test]
57
+ public void Single_node_tree()
58
+ {
59
+ const string input = "(;A[B])";
60
+ var expected = TreeWithNoChildren(CreateData("A", "B"));
61
+ Assert.That(SgfParser.ParseTree(input), Is.EqualTo(expected).Using(SgfTreeEqualityComparer.Instance));
62
+ }
63
+
64
+ [Ignore("Remove to run test")]
65
+ [Test]
66
+ public void Properties_without_delimiter()
67
+ {
68
+ const string input = "(;a)";
69
+ Assert.That(() => SgfParser.ParseTree(input), Throws.Exception);
70
+ }
71
+
72
+ [Ignore("Remove to run test")]
73
+ [Test]
74
+ public void All_lowercase_property()
75
+ {
76
+ const string input = "(;a[b])";
77
+ Assert.That(() => SgfParser.ParseTree(input), Throws.Exception);
78
+ }
79
+
80
+ [Ignore("Remove to run test")]
81
+ [Test]
82
+ public void Upper_and_lowercase_property()
83
+ {
84
+ const string input = "(;Aa[b])";
85
+ Assert.That(() => SgfParser.ParseTree(input), Throws.Exception);
86
+ }
87
+
88
+ [Ignore("Remove to run test")]
89
+ [Test]
90
+ public void Two_nodes()
91
+ {
92
+ const string input = "(;A[B];B[C])";
93
+ var expected = TreeWithSingleChild(CreateData("A", "B"), TreeWithNoChildren(CreateData("B", "C")));
94
+ Assert.That(SgfParser.ParseTree(input), Is.EqualTo(expected).Using(SgfTreeEqualityComparer.Instance));
95
+ }
96
+
97
+ [Ignore("Remove to run test")]
98
+ [Test]
99
+ public void Two_child_trees()
100
+ {
101
+ const string input = "(;A[B](;B[C])(;C[D]))";
102
+ var expected = TreeWithChildren(CreateData("A", "B"),
103
+ new[]
104
+ {
105
+ TreeWithNoChildren(CreateData("B", "C")),
106
+ TreeWithNoChildren(CreateData("C", "D"))
107
+ });
108
+ Assert.That(SgfParser.ParseTree(input), Is.EqualTo(expected).Using(SgfTreeEqualityComparer.Instance));
109
+ }
110
+
111
+ [Ignore("Remove to run test")]
112
+ [Test]
113
+ public void Multiple_properties()
114
+ {
115
+ const string input = "(;A[b][c][d])";
116
+ var expected = TreeWithNoChildren(CreateData("A", "b", "c", "d"));
117
+ Assert.That(SgfParser.ParseTree(input), Is.EqualTo(expected).Using(SgfTreeEqualityComparer.Instance));
118
+ }
119
+
120
+ [Ignore("Remove to run test")]
121
+ [Test]
122
+ public void Escaped_property()
123
+ {
124
+ const string input = @"(;A[\]b\nc\nd\t\te \n\]])";
125
+ var expected = TreeWithNoChildren(CreateData("A", @"]b c d e ]"));
126
+ Assert.That(SgfParser.ParseTree(input), Is.EqualTo(expected).Using(SgfTreeEqualityComparer.Instance));
127
+ }
128
+
129
+ private class SgfTreeEqualityComparer : IEqualityComparer<SgfTree>
130
+ {
131
+ public static readonly SgfTreeEqualityComparer Instance = new SgfTreeEqualityComparer();
132
+
133
+ public bool Equals(SgfTree x, SgfTree y)
134
+ {
135
+ return SgfDataEqualityComparer.Instance.Equals(x.Data, y.Data) && x.Children.SequenceEqual(y.Children, Instance);
136
+ }
137
+
138
+ public int GetHashCode(SgfTree obj)
139
+ {
140
+ throw new System.NotImplementedException();
141
+ }
142
+ }
143
+
144
+ private class SgfDataEqualityComparer : IEqualityComparer<IDictionary<string, string[]>>
145
+ {
146
+ public static readonly SgfDataEqualityComparer Instance = new SgfDataEqualityComparer();
147
+
148
+ public bool Equals(IDictionary<string, string[]> x, IDictionary<string, string[]> y)
149
+ {
150
+ return x.Keys.SequenceEqual(y.Keys) && x.Keys.All(key => x[key].SequenceEqual(y[key]));
151
+ }
152
+
153
+ public int GetHashCode(IDictionary<string, string[]> obj)
154
+ {
155
+ throw new System.NotImplementedException();
156
+ }
157
+ }
158
+ }