trackler 2.2.1.117 → 2.2.1.118

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/lib/trackler/version.rb +1 -1
  3. data/tracks/c/exercises/palindrome-products/src/example.c +73 -64
  4. data/tracks/c/exercises/palindrome-products/src/example.h +2 -4
  5. data/tracks/ceylon/exercises/largest-series-product/example/Series.ceylon +17 -5
  6. data/tracks/ceylon/exercises/largest-series-product/source/largestseriesproduct/Series.ceylon +12 -1
  7. data/tracks/ceylon/exercises/largest-series-product/source/largestseriesproduct/SeriesTest.ceylon +7 -12
  8. data/tracks/haskell/config.json +2 -2
  9. data/tracks/haskell/exercises/all-your-base/examples/success-standard/src/Base.hs +9 -6
  10. data/tracks/haskell/exercises/all-your-base/src/Base.hs +5 -2
  11. data/tracks/haskell/exercises/all-your-base/test/Tests.hs +28 -27
  12. data/tracks/haskell/exercises/largest-series-product/examples/success-standard/src/Series.hs +11 -5
  13. data/tracks/haskell/exercises/largest-series-product/src/Series.hs +4 -2
  14. data/tracks/haskell/exercises/largest-series-product/test/Tests.hs +16 -16
  15. data/tracks/java/config.json +1 -1
  16. data/tracks/java/exercises/bowling/.meta/version +1 -1
  17. data/tracks/java/exercises/bowling/src/test/java/BowlingTest.java +30 -5
  18. data/tracks/javascript/config.json +5 -5
  19. data/tracks/ocaml/README.md +3 -2
  20. data/tracks/typescript/config.json +28 -0
  21. data/tracks/typescript/exercises/sieve/README.md +60 -0
  22. data/tracks/typescript/exercises/sieve/package.json +36 -0
  23. data/tracks/typescript/exercises/sieve/sieve.example.ts +37 -0
  24. data/tracks/typescript/exercises/sieve/sieve.test.ts +41 -0
  25. data/tracks/typescript/exercises/sieve/sieve.ts +0 -0
  26. data/tracks/typescript/exercises/sieve/tsconfig.json +22 -0
  27. data/tracks/typescript/exercises/sieve/tslint.json +127 -0
  28. data/tracks/typescript/exercises/sieve/yarn.lock +2624 -0
  29. data/tracks/typescript/exercises/sublist/README.md +46 -0
  30. data/tracks/typescript/exercises/sublist/package.json +36 -0
  31. data/tracks/typescript/exercises/sublist/sublist.example.ts +30 -0
  32. data/tracks/typescript/exercises/sublist/sublist.test.ts +139 -0
  33. data/tracks/typescript/exercises/sublist/sublist.ts +0 -0
  34. data/tracks/typescript/exercises/sublist/tsconfig.json +22 -0
  35. data/tracks/typescript/exercises/sublist/tslint.json +127 -0
  36. data/tracks/typescript/exercises/sublist/yarn.lock +2624 -0
  37. metadata +18 -2
@@ -1,4 +1,4 @@
1
- module Series (largestProduct) where
1
+ module Series (Error(..), largestProduct) where
2
2
 
3
3
  import Control.Monad ((>=>))
4
4
  import Data.Char (digitToInt, isDigit)
@@ -7,10 +7,16 @@ import Data.Maybe (mapMaybe)
7
7
  import Safe (maximumMay)
8
8
  import Safe.Exact (takeExactMay)
9
9
 
10
- largestProduct :: (Integral a, Num b, Ord b) => a -> String -> Maybe b
11
- largestProduct n = traverse charToNum >=> maximumMay . products
10
+ data Error = InvalidSpan | InvalidDigit Char deriving (Show, Eq)
11
+
12
+ rightOr :: a -> Maybe b -> Either a b
13
+ rightOr a Nothing = Left a
14
+ rightOr _ (Just x) = Right x
15
+
16
+ largestProduct :: (Integral a, Num b, Ord b) => a -> String -> Either Error b
17
+ largestProduct n = traverse charToNum >=> rightOr InvalidSpan . maximumMay . products
12
18
  where
13
19
  products = mapMaybe (fmap product . takeExactMay (fromIntegral n)) . tails
14
20
  charToNum x
15
- | isDigit x = Just . fromIntegral . digitToInt $ x
16
- | otherwise = Nothing
21
+ | isDigit x = Right . fromIntegral . digitToInt $ x
22
+ | otherwise = Left (InvalidDigit x)
@@ -1,4 +1,6 @@
1
- module Series (largestProduct) where
1
+ module Series (Error(..), largestProduct) where
2
2
 
3
- largestProduct :: Int -> String -> Maybe Integer
3
+ data Error = InvalidSpan | InvalidDigit Char deriving (Show, Eq)
4
+
5
+ largestProduct :: Int -> String -> Either Error Integer
4
6
  largestProduct size digits = error "You need to implement this function."
@@ -3,7 +3,7 @@
3
3
  import Test.Hspec (Spec, describe, it, shouldBe)
4
4
  import Test.Hspec.Runner (configFastFail, defaultConfig, hspecWith)
5
5
 
6
- import Series (largestProduct)
6
+ import Series (Error(..), largestProduct)
7
7
 
8
8
  main :: IO ()
9
9
  main = hspecWith defaultConfig {configFastFail = True} specs
@@ -13,60 +13,60 @@ specs = describe "largestProduct" $ do
13
13
 
14
14
  it "finds the largest product if span equals length" $
15
15
  largestProduct 2 "29"
16
- `shouldBe` Just 18
16
+ `shouldBe` Right 18
17
17
 
18
18
  it "can find the largest product of 2 with numbers in order" $
19
19
  largestProduct 2 "0123456789"
20
- `shouldBe` Just 72
20
+ `shouldBe` Right 72
21
21
 
22
22
  it "can find the largest product of 2" $
23
23
  largestProduct 2 "576802143"
24
- `shouldBe` Just 48
24
+ `shouldBe` Right 48
25
25
 
26
26
  it "can find the largest product of 3 with numbers in order" $
27
27
  largestProduct 3 "0123456789"
28
- `shouldBe` Just 504
28
+ `shouldBe` Right 504
29
29
 
30
30
  it "can find the largest product of 3" $
31
31
  largestProduct 3 "1027839564"
32
- `shouldBe` Just 270
32
+ `shouldBe` Right 270
33
33
 
34
34
  it "can find the largest product of 5 with numbers in order" $
35
35
  largestProduct 5 "0123456789"
36
- `shouldBe` Just 15120
36
+ `shouldBe` Right 15120
37
37
 
38
38
  it "can get the largest product of a big number" $
39
39
  largestProduct 6 "73167176531330624919225119674426574742355349194934"
40
- `shouldBe` Just 23520
40
+ `shouldBe` Right 23520
41
41
 
42
42
  it "reports zero if the only digits are zero" $
43
43
  largestProduct 2 "0000"
44
- `shouldBe` Just 0
44
+ `shouldBe` Right 0
45
45
 
46
46
  it "reports zero if all spans include zero" $
47
47
  largestProduct 3 "99099"
48
- `shouldBe` Just 0
48
+ `shouldBe` Right 0
49
49
 
50
50
  it "rejects span longer than string length" $
51
51
  largestProduct 4 "123"
52
- `shouldBe` Nothing
52
+ `shouldBe` Left InvalidSpan
53
53
 
54
54
  it "reports 1 for empty string and empty product (0 span)" $
55
55
  largestProduct 0 ""
56
- `shouldBe` Just 1
56
+ `shouldBe` Right 1
57
57
 
58
58
  it "reports 1 for nonempty string and empty product (0 span)" $
59
59
  largestProduct 0 "123"
60
- `shouldBe` Just 1
60
+ `shouldBe` Right 1
61
61
 
62
62
  it "rejects empty string and nonzero span" $
63
63
  largestProduct 1 ""
64
- `shouldBe` Nothing
64
+ `shouldBe` Left InvalidSpan
65
65
 
66
66
  it "rejects invalid character in digits" $
67
67
  largestProduct 2 "1234a5"
68
- `shouldBe` Nothing
68
+ `shouldBe` Left (InvalidDigit 'a')
69
69
 
70
70
  it "rejects negative span" $
71
71
  largestProduct (-1) "12345"
72
- `shouldBe` Nothing
72
+ `shouldBe` Left InvalidSpan
@@ -197,7 +197,7 @@
197
197
  "loops",
198
198
  "strings"
199
199
  ],
200
- "unlocked_by": "rna-transcription",
200
+ "unlocked_by": "two-fer",
201
201
  "uuid": "331073b3-bd1a-4868-b767-a64ce9fd9d97"
202
202
  },
203
203
  {
@@ -1 +1 @@
1
- 1.1.0
1
+ 1.2.0
@@ -199,7 +199,7 @@ public class BowlingTest {
199
199
 
200
200
  game.score();
201
201
  }
202
-
202
+
203
203
  @Ignore("Remove to run test")
204
204
  @Test
205
205
  public void twoBonusRollsAfterAStrikeInTheLastFrameCanNotScoreMoreThan10Points() {
@@ -222,7 +222,7 @@ public class BowlingTest {
222
222
 
223
223
  assertEquals(26, game.score());
224
224
  }
225
-
225
+
226
226
  @Ignore("Remove to run test")
227
227
  @Test
228
228
  public void theSecondBonusRollsAfterAStrikeInTheLastFrameCanNotBeAStrikeIfTheFirstOneIsNotAStrike() {
@@ -235,7 +235,7 @@ public class BowlingTest {
235
235
 
236
236
  game.score();
237
237
  }
238
-
238
+
239
239
  @Ignore("Remove to run test")
240
240
  @Test
241
241
  public void secondBonusRollAfterAStrikeInTheLastFrameCanNotScoreMoreThan10Points() {
@@ -248,7 +248,7 @@ public class BowlingTest {
248
248
 
249
249
  game.score();
250
250
  }
251
-
251
+
252
252
  @Ignore("Remove to run test")
253
253
  @Test
254
254
  public void anUnstartedGameCanNotBeScored() {
@@ -327,4 +327,29 @@ public class BowlingTest {
327
327
  game.score();
328
328
  }
329
329
 
330
- }
330
+ @Ignore("Remove to run test")
331
+ @Test
332
+ public void canNotRollAfterBonusRollForSpare() {
333
+ int[] rolls = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 3, 2, 2};
334
+
335
+ playGame(rolls);
336
+
337
+ expectedException.expect(IllegalStateException.class);
338
+ expectedException.expectMessage("Cannot roll after game is over");
339
+
340
+ game.score();
341
+ }
342
+
343
+ @Ignore("Remove to run test")
344
+ @Test
345
+ public void canNotRollAfterBonusRollForStrike() {
346
+ int[] rolls = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 3, 2, 2};
347
+
348
+ playGame(rolls);
349
+
350
+ expectedException.expect(IllegalStateException.class);
351
+ expectedException.expectMessage("Cannot roll after game is over");
352
+
353
+ game.score();
354
+ }
355
+ }
@@ -594,7 +594,7 @@
594
594
  "text-formatting",
595
595
  "transforming"
596
596
  ],
597
- "unlocked_by": "atbash-cipher",
597
+ "unlocked_by": "simple-cipher",
598
598
  "uuid": "a98e3593-d5b4-4c2b-8569-ae3ae7e07dad"
599
599
  },
600
600
  {
@@ -805,7 +805,7 @@
805
805
  "control-flow-(loops)",
806
806
  "recursion"
807
807
  ],
808
- "unlocked_by": "binary-search",
808
+ "unlocked_by": "linked-list",
809
809
  "uuid": "865806e0-950f-49a5-a6e5-26472b90ab85"
810
810
  },
811
811
  {
@@ -1130,7 +1130,7 @@
1130
1130
  "Algorithms",
1131
1131
  "Mathematics"
1132
1132
  ],
1133
- "unlocked_by": "null",
1133
+ "unlocked_by": null,
1134
1134
  "uuid" : "fd435dad-311a-4c40-9868-70863455831e"
1135
1135
  },
1136
1136
  {
@@ -1213,7 +1213,7 @@
1213
1213
  "uuid": "b3dbc935-536e-4910-994d-4a519b511b6a",
1214
1214
  "slug": "forth",
1215
1215
  "core": false,
1216
- "unlocked_by": "saddle-points",
1216
+ "unlocked_by": "matrix",
1217
1217
  "difficulty": 8,
1218
1218
  "topics": [
1219
1219
  "stacks",
@@ -1225,7 +1225,7 @@
1225
1225
  "uuid": "f82e470d-0bcc-4eba-b9b0-8a0c50a6fd19",
1226
1226
  "slug": "variable-length-quantity",
1227
1227
  "core": false,
1228
- "unlocked_by": "two-bucket",
1228
+ "unlocked_by": "grade-school",
1229
1229
  "difficulty": 5,
1230
1230
  "topics": [
1231
1231
  "bitwise_operations",
@@ -15,6 +15,7 @@ The OCaml track assumes installation of OCaml version 4.06.1, and installation o
15
15
  Assuming you have opam, these can be installed with
16
16
  ```bash
17
17
  opam install core_kernel ounit react
18
+ ```
18
19
 
19
20
  ## Notes on prerequisite libraries
20
21
 
@@ -24,14 +25,14 @@ an issue.
24
25
  OUnit is a unit testing library.
25
26
  React is a reactive library, just used in the hangman exercise.
26
27
 
27
- ```
28
-
29
28
  ## Running Tests
30
29
 
31
30
  To run all the tests, type `make` from the top level ocaml directory.
32
31
 
33
32
  To run tests for an individual exercise, `make test-assignment ASSIGNMENT=luhn`
34
33
 
34
+ The Makefile is a slim wrapper around [dune](https://github.com/ocaml/dune). Each exercise has a jbuild file which describes how to build it.
35
+
35
36
  ## Adding an Exercise
36
37
 
37
38
  The [contributing guide](https://github.com/exercism/docs/blob/master/contributing-to-language-tracks/README.md) provides guidance on
@@ -395,6 +395,34 @@
395
395
  "unlocked_by": "space-age",
396
396
  "uuid": "5a04b3f8-99b6-4aec-8afd-0d54930e4aff"
397
397
  },
398
+ {
399
+ "core": false,
400
+ "difficulty": 5,
401
+ "slug": "sieve",
402
+ "topics": [
403
+ "control_flow_conditionals",
404
+ "control_flow_loops",
405
+ "integers",
406
+ "mathematics",
407
+ "recursion"
408
+ ],
409
+ "unlocked_by": "prime-factors",
410
+ "uuid": "f3ad1525-c124-4b2f-b09f-4639eb4a6ad9"
411
+ },
412
+ {
413
+ "core": false,
414
+ "difficulty": 5,
415
+ "slug": "sublist",
416
+ "topics": [
417
+ "arrays",
418
+ "control_flow_conditionals",
419
+ "control_flow_loops",
420
+ "data_structures",
421
+ "lists"
422
+ ],
423
+ "unlocked_by": "linked-list",
424
+ "uuid": "c5ed4703-59cd-4e31-b109-ba5bfc48a578"
425
+ },
398
426
  {
399
427
  "core": true,
400
428
  "difficulty": 6,
@@ -0,0 +1,60 @@
1
+ # Sieve
2
+
3
+ Use the Sieve of Eratosthenes to find all the primes from 2 up to a given
4
+ number.
5
+
6
+ The Sieve of Eratosthenes is a simple, ancient algorithm for finding all
7
+ prime numbers up to any given limit. It does so by iteratively marking as
8
+ composite (i.e. not prime) the multiples of each prime,
9
+ starting with the multiples of 2.
10
+
11
+ Create your range, starting at two and continuing up to and including the given limit. (i.e. [2, limit])
12
+
13
+ The algorithm consists of repeating the following over and over:
14
+
15
+ - take the next available unmarked number in your list (it is prime)
16
+ - mark all the multiples of that number (they are not prime)
17
+
18
+ Repeat until you have processed each number in your range.
19
+
20
+ When the algorithm terminates, all the numbers in the list that have not
21
+ been marked are prime.
22
+
23
+ The wikipedia article has a useful graphic that explains the algorithm:
24
+ https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes
25
+
26
+ Notice that this is a very specific algorithm, and the tests don't check
27
+ that you've implemented the algorithm, only that you've come up with the
28
+ correct list of primes.
29
+
30
+ ## Setup
31
+
32
+ Go through the setup instructions for TypeScript to
33
+ install the necessary dependencies:
34
+
35
+ http://exercism.io/languages/typescript
36
+
37
+ ## Requirements
38
+
39
+ Install assignment dependencies:
40
+
41
+ ```bash
42
+ $ yarn install
43
+ ```
44
+
45
+ ## Making the test suite pass
46
+
47
+ Execute the tests with:
48
+
49
+ ```bash
50
+ $ yarn test
51
+ ```
52
+
53
+
54
+
55
+ ## Source
56
+
57
+ Sieve of Eratosthenes at Wikipedia [http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes](http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes)
58
+
59
+ ## Submitting Incomplete Solutions
60
+ It's possible to submit an incomplete solution so you can see how others have completed the exercise.
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "xtypescript",
3
+ "version": "1.0.0",
4
+ "description": "Exercism exercises in Typescript.",
5
+ "author": "",
6
+ "private": true,
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/exercism/xtypescript"
10
+ },
11
+ "devDependencies": {},
12
+ "scripts": {
13
+ "test": "tsc --noEmit -p . && jest --no-cache",
14
+ "lint": "tsc --noEmit -p . && tslint \"*.ts?(x)\"",
15
+ "lintci": "tslint \"*.ts?(x)\" --force"
16
+ },
17
+ "dependencies": {
18
+ "@types/jest": "^21.1.5",
19
+ "@types/node": "^8.0.47",
20
+ "jest": "^21.2.1",
21
+ "ts-jest": "^21.1.3",
22
+ "tslint": "^5.8.0",
23
+ "typescript": "^2.5.3"
24
+ },
25
+ "jest": {
26
+ "transform": {
27
+ ".(ts|tsx)": "<rootDir>/node_modules/ts-jest/preprocessor.js"
28
+ },
29
+ "testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$",
30
+ "moduleFileExtensions": [
31
+ "ts",
32
+ "tsx",
33
+ "js"
34
+ ]
35
+ }
36
+ }
@@ -0,0 +1,37 @@
1
+ class Sieve {
2
+ static primes(limit: number): number[] {
3
+ if (limit === 2) {
4
+ return [limit]
5
+ }
6
+
7
+ const sieve: boolean[] = []
8
+ for (let i = 0; i < limit; i++) {
9
+ sieve[i] = true
10
+ }
11
+
12
+ const primes: number[] = []
13
+ const maxCandidate = Math.floor(Math.sqrt(limit))
14
+ for (let candidate = 2; candidate <= maxCandidate + 1; candidate++) {
15
+ if (!sieve[candidate - 1]) {
16
+ continue
17
+ }
18
+
19
+ primes.push(candidate)
20
+ let multiple = candidate * candidate
21
+ while (multiple <= limit) {
22
+ sieve[multiple - 1] = false
23
+ multiple += candidate
24
+ }
25
+ }
26
+
27
+ for (let i = maxCandidate + 1; i <= limit; i++) {
28
+ if (sieve[i - 1]) {
29
+ primes.push(i)
30
+ }
31
+ }
32
+
33
+ return primes
34
+ }
35
+ }
36
+
37
+ export default Sieve
@@ -0,0 +1,41 @@
1
+ import Sieve from './sieve'
2
+
3
+ describe('Sieve', () => {
4
+ it('no primes under two', () => {
5
+ const expected: number[] = []
6
+ expect(Sieve.primes(1)).toEqual(expected)
7
+ })
8
+
9
+ xit('find first prime', () => {
10
+ const expected = [2]
11
+ expect(Sieve.primes(2)).toEqual(expected)
12
+ })
13
+
14
+ xit('find primes up to 10', () => {
15
+ const expected = [2, 3, 5, 7]
16
+ expect(Sieve.primes(10)).toEqual(expected)
17
+ })
18
+
19
+ xit('limit is prime', () => {
20
+ const expected = [2, 3, 5, 7, 11, 13]
21
+ expect(Sieve.primes(13)).toEqual(expected)
22
+ })
23
+
24
+ xit('find primes up to 1000', () => {
25
+ const expected: number[] = [
26
+ 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43,
27
+ 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107,
28
+ 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181,
29
+ 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263,
30
+ 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349,
31
+ 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433,
32
+ 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521,
33
+ 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613,
34
+ 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701,
35
+ 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809,
36
+ 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887,
37
+ 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997
38
+ ]
39
+ expect(Sieve.primes(1000)).toEqual(expected)
40
+ })
41
+ })