trackler 2.2.1.68 → 2.2.1.69

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/lib/trackler/version.rb +1 -1
  3. data/problem-specifications/exercises/pov/description.md +0 -2
  4. data/problem-specifications/exercises/protein-translation/canonical-data.json +3 -3
  5. data/problem-specifications/exercises/simple-cipher/description.md +4 -6
  6. data/tracks/csharp/exercises/all-your-base/AllYourBaseTest.cs +7 -7
  7. data/tracks/csharp/exercises/dominoes/README.md +2 -11
  8. data/tracks/csharp/exercises/reverse-string/ReverseStringTest.cs +2 -2
  9. data/tracks/dart/CONTRIBUTING.md +7 -4
  10. data/tracks/delphi/config.json +23 -20
  11. data/tracks/ecmascript/CONTRIBUTING.md +3 -0
  12. data/tracks/ecmascript/README.md +2 -5
  13. data/tracks/fsharp/config.json +11 -0
  14. data/tracks/fsharp/exercises/Exercises.sln +6 -0
  15. data/tracks/fsharp/exercises/all-your-base/AllYourBaseTest.fs +7 -7
  16. data/tracks/fsharp/exercises/diamond/Diamond.fsproj +1 -0
  17. data/tracks/fsharp/exercises/diamond/DiamondTest.fs +111 -114
  18. data/tracks/fsharp/exercises/diamond/README.md +2 -1
  19. data/tracks/fsharp/exercises/dominoes/README.md +2 -5
  20. data/tracks/fsharp/exercises/palindrome-products/Example.fs +27 -19
  21. data/tracks/fsharp/exercises/palindrome-products/PalindromeProducts.fs +3 -3
  22. data/tracks/fsharp/exercises/palindrome-products/PalindromeProductsTest.fs +52 -49
  23. data/tracks/fsharp/exercises/reverse-string/ReverseStringTest.fs +2 -2
  24. data/tracks/fsharp/exercises/spiral-matrix/Example.fs +35 -0
  25. data/tracks/fsharp/exercises/spiral-matrix/Program.fs +1 -0
  26. data/tracks/fsharp/exercises/spiral-matrix/README.md +25 -0
  27. data/tracks/fsharp/exercises/spiral-matrix/SpiralMatrix.fs +3 -0
  28. data/tracks/fsharp/exercises/spiral-matrix/SpiralMatrix.fsproj +23 -0
  29. data/tracks/fsharp/exercises/spiral-matrix/SpiralMatrixTest.fs +47 -0
  30. data/tracks/fsharp/generators/Generators.fs +42 -5
  31. data/tracks/fsharp/generators/Properties/launchSettings.json +1 -2
  32. data/tracks/java/config.json +7 -2
  33. data/tracks/java/exercises/binary-search-tree/src/test/java/BinarySearchTreeTest.java +0 -1
  34. data/tracks/javascript/.eslintignore +1 -2
  35. data/tracks/javascript/exercises/wordy/example.js +2 -2
  36. data/tracks/perl6/exercises/atbash-cipher/AtbashCipher.pm6 +6 -0
  37. data/tracks/perl6/exercises/atbash-cipher/atbash-cipher.t +2 -9
  38. data/tracks/perl6/exercises/atbash-cipher/example.yaml +8 -9
  39. data/tracks/perl6/exercises/grade-school/Example.pm6 +1 -1
  40. data/tracks/perl6/exercises/grade-school/GradeSchool.pm6 +1 -1
  41. data/tracks/perl6/exercises/grade-school/example.yaml +19 -12
  42. data/tracks/perl6/exercises/grade-school/grade-school.t +19 -12
  43. data/tracks/python/.github/stale.yml +6 -3
  44. data/tracks/python/config.json +17 -0
  45. data/tracks/python/exercises/dot-dsl/.meta/hints.md +14 -0
  46. data/tracks/python/exercises/dot-dsl/README.md +52 -0
  47. data/tracks/python/exercises/dot-dsl/dot_dsl.py +27 -0
  48. data/tracks/python/exercises/dot-dsl/dot_dsl_test.py +117 -0
  49. data/tracks/python/exercises/dot-dsl/example.py +52 -0
  50. data/tracks/python/exercises/proverb/README.md +5 -2
  51. data/tracks/python/exercises/proverb/example.py +5 -5
  52. data/tracks/python/exercises/proverb/proverb.py +1 -1
  53. data/tracks/python/exercises/proverb/proverb_test.py +42 -52
  54. data/tracks/python/exercises/say/example.py +2 -2
  55. data/tracks/python/exercises/say/say_test.py +2 -2
  56. data/tracks/rust/README.md +2 -0
  57. data/tracks/rust/_test/count-ignores.sh +15 -8
  58. data/tracks/rust/bin/test-exercise +4 -1
  59. data/tracks/rust/exercises/perfect-numbers/.meta/ignore-count-ignores +6 -0
  60. data/tracks/rust/exercises/perfect-numbers/tests/perfect-numbers.rs +32 -22
  61. data/tracks/typescript/config.json +16 -0
  62. data/tracks/typescript/exercises/two-bucket/README.md +66 -0
  63. data/tracks/typescript/exercises/two-bucket/package.json +36 -0
  64. data/tracks/typescript/exercises/two-bucket/tsconfig.json +22 -0
  65. data/tracks/typescript/exercises/two-bucket/tslint.json +127 -0
  66. data/tracks/typescript/exercises/two-bucket/two-bucket.example.ts +97 -0
  67. data/tracks/typescript/exercises/two-bucket/two-bucket.test.ts +47 -0
  68. data/tracks/typescript/exercises/two-bucket/two-bucket.ts +0 -0
  69. data/tracks/typescript/exercises/two-bucket/yarn.lock +2624 -0
  70. metadata +23 -2
@@ -3,59 +3,49 @@ import unittest
3
3
  from proverb import proverb
4
4
 
5
5
 
6
+ # Tests adapted from `problem-specifications//canonical-data.json` @ v1.0.0
7
+
6
8
  class ProverbTest(unittest.TestCase):
7
- def test_a_single_consequence(self):
8
- expected = 'For want of a nail the shoe was lost.\n'\
9
- 'And all for the want of a nail.'
10
- self.assertEqual(proverb(['nail', 'shoe']), expected)
11
-
12
- def test_short_list(self):
13
- expected = 'For want of a nail the shoe was lost.\n'\
14
- 'For want of a shoe the horse was lost.\n'\
15
- 'And all for the want of a nail.'
16
- self.assertEqual(proverb(['nail', 'shoe', 'horse']), expected)
17
-
18
- def test_long_list(self):
19
- expected = 'For want of a nail the shoe was lost.\n'\
20
- 'For want of a shoe the horse was lost.\n'\
21
- 'For want of a horse the rider was lost.\n'\
22
- 'And all for the want of a nail.'
23
- self.assertEqual(proverb(['nail', 'shoe', 'horse', 'rider']), expected)
24
-
25
- def test_new_itens(self):
26
- expected = 'For want of a key the value was lost.\n'\
27
- 'And all for the want of a key.'
28
- self.assertEqual(proverb(['key', 'value']), expected)
29
-
30
- def test_whole_proverb(self):
31
- expected = 'For want of a nail the shoe was lost.\n'\
32
- 'For want of a shoe the horse was lost.\n'\
33
- 'For want of a horse the rider was lost.\n'\
34
- 'For want of a rider the message was lost.\n'\
35
- 'For want of a message the battle was lost.\n'\
36
- 'For want of a battle the kingdom was lost.\n'\
37
- 'And all for the want of a nail.'
38
- self.assertEqual(
39
- proverb([
40
- 'nail', 'shoe', 'horse', 'rider', 'message', 'battle',
41
- 'kingdom'
42
- ]), expected)
43
-
44
- def test_qualifier(self):
45
- expected = 'For want of a nail the shoe was lost.\n'\
46
- 'For want of a shoe the horse was lost.\n'\
47
- 'For want of a horse the rider was lost.\n'\
48
- 'For want of a rider the message was lost.\n'\
49
- 'For want of a message the battle was lost.\n'\
50
- 'For want of a battle the kingdom was lost.\n'\
51
- 'And all for the want of a horseshoe nail.'
52
- self.assertEqual(
53
- proverb(
54
- [
55
- 'nail', 'shoe', 'horse', 'rider', 'message', 'battle',
56
- 'kingdom'
57
- ],
58
- qualifier='horseshoe'), expected)
9
+ def test_zero_pieces(self):
10
+ self.assertEqual(proverb([]), "")
11
+
12
+ def test_one_piece(self):
13
+ inputs = ["nail"]
14
+ expected = "And all for the want of a nail."
15
+ self.assertEqual(proverb(inputs), expected)
16
+
17
+ def test_two_pieces(self):
18
+ inputs = ["nail", "shoe"]
19
+ expected = "\n".join(["For want of a nail the shoe was lost.",
20
+ "And all for the want of a nail."])
21
+ self.assertEqual(proverb(inputs), expected)
22
+
23
+ def test_three_pieces(self):
24
+ inputs = ["nail", "shoe", "horse"]
25
+ expected = "\n".join(["For want of a nail the shoe was lost.",
26
+ "For want of a shoe the horse was lost.",
27
+ "And all for the want of a nail."])
28
+ self.assertEqual(proverb(inputs), expected)
29
+
30
+ def test_full_proverb(self):
31
+ inputs = ["nail", "shoe", "horse", "rider",
32
+ "message", "battle", "kingdom"]
33
+ expected = "\n".join(["For want of a nail the shoe was lost.",
34
+ "For want of a shoe the horse was lost.",
35
+ "For want of a horse the rider was lost.",
36
+ "For want of a rider the message was lost.",
37
+ "For want of a message the battle was lost.",
38
+ "For want of a battle the kingdom was lost.",
39
+ "And all for the want of a nail."])
40
+ self.assertEqual(proverb(inputs), expected)
41
+
42
+ def test_four_pieces_modernised(self):
43
+ inputs = ["pin", "gun", "soldier", "battle"]
44
+ expected = "\n".join(["For want of a pin the gun was lost.",
45
+ "For want of a gun the soldier was lost.",
46
+ "For want of a soldier the battle was lost.",
47
+ "And all for the want of a pin."])
48
+ self.assertEqual(proverb(inputs), expected)
59
49
 
60
50
 
61
51
  if __name__ == '__main__':
@@ -10,9 +10,9 @@ def say(number, recursive=False):
10
10
  k, m, b, t = 1e3, 1e6, 1e9, 1e12
11
11
 
12
12
  if number < 0:
13
- raise AttributeError('number is negative')
13
+ raise ValueError('number is negative')
14
14
  if number >= t:
15
- raise AttributeError('number is too large: %s' % str(number))
15
+ raise ValueError('number is too large: %s' % str(number))
16
16
 
17
17
  if number < 20:
18
18
  return small[number] if not recursive else 'and ' + small[number]
@@ -64,11 +64,11 @@ class SayTest(unittest.TestCase):
64
64
  "one hundred and twenty-three"))
65
65
 
66
66
  def test_number_to_large(self):
67
- with self.assertRaises(AttributeError):
67
+ with self.assertRaises(ValueError):
68
68
  say(1e12)
69
69
 
70
70
  def test_number_negative(self):
71
- with self.assertRaises(AttributeError):
71
+ with self.assertRaises(ValueError):
72
72
  say(-1)
73
73
 
74
74
 
@@ -96,6 +96,8 @@ Note that:
96
96
 
97
97
  - If the test suite is appreciably sped up by running in release mode, and there is reason to be confident that the example implementation does not contain any overflow errors, consider adding a file `.meta/test-in-release-mode`. This should contain brief comments explaining the situation.
98
98
 
99
+ - If your exercise implements macro-based testing (see [#392](https://github.com/exercism/rust/issues/392#issuecomment-343865993) and [`perfect-numbers.rs`](https://github.com/exercism/rust/blob/master/exercises/perfect-numbers/tests/perfect-numbers.rs)), you will likely run afoul of a CI check which counts the `#[ignore]` lines and compares the result to the number of `#[test]` lines. To fix this, add a file `.meta/ignore-count-ignores` to disable that check for your exercise.
100
+
99
101
  - `README.md` may be [regenerated](https://github.com/exercism/docs/blob/master/maintaining-a-track/regenerating-exercise-readmes.md) from Exercism data. The generator will use the `description.md` from the exercise directory in the [problem-specifications repository](https://github.com/exercism/problem-specifications/tree/master/exercises), then any hints in `.meta/hints.md`, then the [Rust-specific instructions](https://github.com/exercism/rust/blob/master/config/exercise-readme-insert.md). The `## Source` section comes from the `metadata.yml` in the same directory. Convention is that the description of the source remains text and the link is both name and hyperlink of the markdown link.
100
102
 
101
103
  - Be sure to add the exercise to an appropriate place in the `config.json` file. The position in the file determines the order exercises are sent. Generate a unique UUID for the exercise. Current difficuly levels in use are 1, 4, 7 and 10.
@@ -3,14 +3,21 @@
3
3
  repo=$(cd "$(dirname "$0")/.." && pwd)
4
4
  exitcode=0
5
5
 
6
- for t in $repo/exercises/*/tests/*.rs; do
7
- tests=$(grep "^\s*\#\[test\]" $t | wc -l | tr -d '[:space:]')
8
- ignores=$(grep "^\s*\#\[ignore\]" $t | wc -l | tr -d '[:space:]')
9
- want_ignores=$(expr $tests - 1)
10
- if [ "$ignores" != "$want_ignores" ]; then
11
- echo "\033[1;31m$t: Has $tests tests and $ignores ignores (should be $want_ignores)\033[0m"
12
- exitcode=1
13
- fi
6
+ for e in $repo/exercises/*; do
7
+ if [ -f "$e/.meta/ignore-count-ignores" ]; then
8
+ continue
9
+ fi
10
+ if [ -d "$e/tests" ]; then
11
+ for t in $e/tests/*.rs; do
12
+ tests=$(grep "^\s*\#\[test\]" $t | wc -l | tr -d '[:space:]')
13
+ ignores=$(grep "^\s*\#\[ignore\]" $t | wc -l | tr -d '[:space:]')
14
+ want_ignores=$(expr $tests - 1)
15
+ if [ "$ignores" != "$want_ignores" ]; then
16
+ echo "\033[1;31m$t: Has $tests tests and $ignores ignores (should be $want_ignores)\033[0m"
17
+ exitcode=1
18
+ fi
19
+ done
20
+ fi
14
21
  done
15
22
 
16
23
  exit $exitcode
@@ -72,7 +72,10 @@ fi
72
72
 
73
73
  # eliminate #[ignore] lines from tests
74
74
  for test in "$exercise/tests/*.rs"; do
75
- sed -i '/\[ignore\]/d' $test
75
+ sed -i -e '/#\[ignore\]/{
76
+ s/#\[ignore\]\s*//
77
+ /^\s*$/d
78
+ }' $test
76
79
  done
77
80
 
78
81
  # run tests from within exercise directory
@@ -0,0 +1,6 @@
1
+ Perfect numbers has tests generated by macro.
2
+ This breaks the count-ignores.sh script:
3
+
4
+ ```text
5
+ exercises/perfect-numbers/tests/perfect-numbers.rs: Has 2 tests and 11 ignores (should be 1)
6
+ ```
@@ -2,32 +2,42 @@ extern crate perfect_numbers;
2
2
 
3
3
  use perfect_numbers::{Classification, classify};
4
4
 
5
+ macro_rules! tests {
6
+ ($property_test_func:ident {
7
+ $( $(#[$attr:meta])* $test_name:ident( $( $param:expr ),* ); )+
8
+ }) => {
9
+ $(
10
+ $(#[$attr])*
11
+ #[test]
12
+ fn $test_name() {
13
+ $property_test_func($( $param ),* )
14
+ }
15
+ )+
16
+ }
17
+ }
18
+
19
+ fn test_classification(num: u64, result: Classification) {
20
+ assert_eq!(classify(num), Ok(result));
21
+ }
22
+
5
23
  #[test]
6
24
  fn basic() {
7
25
  assert_eq!(classify(0), Err("Number must be positive"));
8
26
  }
9
27
 
10
- #[test]
11
- #[ignore]
12
- fn test_all() {
13
- struct TestClassification {
14
- num: u64,
15
- result: perfect_numbers::Classification
16
- }
17
- let test_table: Vec<TestClassification> = vec![
18
- TestClassification { num: 6, result: Classification::Perfect },
19
- TestClassification { num: 28, result: Classification::Perfect },
20
- TestClassification { num: 33550336, result: Classification::Perfect },
21
- TestClassification { num: 12, result: Classification::Abundant },
22
- TestClassification { num: 30, result: Classification::Abundant },
23
- TestClassification { num: 33550335, result: Classification::Abundant },
24
- TestClassification { num: 2, result: Classification::Deficient },
25
- TestClassification { num: 4, result: Classification::Deficient },
26
- TestClassification { num: 32, result: Classification::Deficient },
27
- TestClassification { num: 33550337, result: Classification::Deficient },
28
- TestClassification { num: 1, result: Classification::Deficient },
29
- ];
30
- for t in test_table {
31
- assert_eq!(classify(t.num), Ok(t.result));
28
+
29
+ tests! {
30
+ test_classification {
31
+ #[ignore] test_1(1, Classification::Deficient);
32
+ #[ignore] test_2(2, Classification::Deficient);
33
+ #[ignore] test_4(4, Classification::Deficient);
34
+ #[ignore] test_6(6, Classification::Perfect);
35
+ #[ignore] test_12(12, Classification::Abundant);
36
+ #[ignore] test_28(28, Classification::Perfect);
37
+ #[ignore] test_30(30, Classification::Abundant);
38
+ #[ignore] test_32(32, Classification::Deficient);
39
+ #[ignore] test_33550335(33550335, Classification::Abundant);
40
+ #[ignore] test_33550336(33550336, Classification::Perfect);
41
+ #[ignore] test_33550337(33550337, Classification::Deficient);
32
42
  }
33
43
  }
@@ -525,6 +525,22 @@
525
525
  "Exception handling",
526
526
  "Text formatting"
527
527
  ]
528
+ },
529
+ {
530
+ "uuid": "7dd29a19-08f6-8480-2e01-1f7262d8860a",
531
+ "slug": "two-bucket",
532
+ "core": false,
533
+ "unlocked_by": "pangram",
534
+ "difficulty": 6,
535
+ "topics": [
536
+ "algorithms",
537
+ "arrays",
538
+ "control-flow-(conditionals)",
539
+ "control-flow-(loops)",
540
+ "exception-handling",
541
+ "games",
542
+ "parsing"
543
+ ]
528
544
  }
529
545
  ],
530
546
  "foregone": [],
@@ -0,0 +1,66 @@
1
+ # Two Bucket
2
+
3
+ Given two buckets of different size, demonstrate how to measure an exact number of liters by strategically transferring liters of fluid between the buckets.
4
+
5
+ Since this mathematical problem is fairly subject to interpretation / individual approach, the tests have been written specifically to expect one overarching solution.
6
+
7
+ To help, the tests provide you with which bucket to fill first. That means, when starting with the larger bucket full, you are NOT allowed at any point to have the smaller bucket full and the larger bucket empty (aka, the opposite starting point); that would defeat the purpose of comparing both approaches!
8
+
9
+ Your program will take as input:
10
+ - the size of bucket one, passed as a numeric value
11
+ - the size of bucket two, passed as a numeric value
12
+ - the desired number of liters to reach, passed as a numeric value
13
+ - which bucket to fill first, passed as a String (either 'one' or 'two')
14
+
15
+ Your program should determine:
16
+ - the total number of "moves" it should take to reach the desired number of liters, including the first fill - expects a numeric value
17
+ - which bucket should end up with the desired number of liters (let's say this is bucket A) - expects a String (either 'one' or 'two')
18
+ - how many liters are left in the other bucket (bucket B) - expects a numeric value
19
+
20
+ Note: any time a change is made to either or both buckets counts as one (1) move.
21
+
22
+ Example:
23
+ Bucket one can hold up to 7 liters, and bucket two can hold up to 11 liters. Let's say bucket one, at a given step, is holding 7 liters, and bucket two is holding 8 liters (7,8). If you empty bucket one and make no change to bucket two, leaving you with 0 liters and 8 liters respectively (0,8), that counts as one "move". Instead, if you had poured from bucket one into bucket two until bucket two was full, leaving you with 4 liters in bucket one and 11 liters in bucket two (4,11), that would count as only one "move" as well.
24
+
25
+ To conclude, the only valid moves are:
26
+ - pouring from one bucket to another
27
+ - emptying one bucket and doing nothing to the other
28
+ - filling one bucket and doing nothing to the other
29
+
30
+ Referenced with <3 by VestigeJ most of the work was done by [Lindsay](http://lindsaylevine.com).
31
+
32
+ ## Setup
33
+
34
+ Go through the setup instructions for Typescript to
35
+ install the necessary dependencies:
36
+
37
+ http://exercism.io/languages/typescript
38
+
39
+ ## Requirements
40
+
41
+ Install assignment dependencies:
42
+
43
+ ```bash
44
+ $ npm install
45
+ ```
46
+
47
+ ## Making the test suite pass
48
+
49
+ Execute the tests with:
50
+
51
+ ```bash
52
+ $ npm test
53
+ ```
54
+
55
+ In the test suites all tests but the first have been skipped.
56
+
57
+ Once you get a test passing, you can enable the next one by
58
+ changing `xtest` to `test`.
59
+
60
+
61
+ ## Source
62
+
63
+ Water Pouring Problem [http://demonstrations.wolfram.com/WaterPouringProblem/](http://demonstrations.wolfram.com/WaterPouringProblem/)
64
+
65
+ ## Submitting Incomplete Solutions
66
+ 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,22 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "es2017",
4
+ "module": "commonjs",
5
+ "alwaysStrict": true,
6
+ "noUnusedLocals": true,
7
+ "noUnusedParameters": true,
8
+ "noImplicitAny": true,
9
+ "strictNullChecks": true,
10
+ "preserveConstEnums": true,
11
+ "noFallthroughCasesInSwitch":true,
12
+ "noImplicitThis":true,
13
+ "noImplicitReturns":true,
14
+ "sourceMap": true,
15
+ "noEmitOnError": true,
16
+ "outDir": "./build"
17
+ },
18
+ "compileOnSave": true,
19
+ "exclude": [
20
+ "node_modules"
21
+ ]
22
+ }
@@ -0,0 +1,127 @@
1
+ {
2
+ "jsRules": {
3
+ "class-name": true,
4
+ "comment-format": [
5
+ true,
6
+ "check-space"
7
+ ],
8
+ "indent": [
9
+ true,
10
+ "spaces"
11
+ ],
12
+ "no-duplicate-variable": true,
13
+ "no-eval": true,
14
+ "no-trailing-whitespace": true,
15
+ "no-unsafe-finally": true,
16
+ "one-line": [
17
+ true,
18
+ "check-open-brace",
19
+ "check-whitespace"
20
+ ],
21
+ "quotemark": [
22
+ false,
23
+ "double"
24
+ ],
25
+ "semicolon": [
26
+ true,
27
+ "never"
28
+ ],
29
+ "triple-equals": [
30
+ true,
31
+ "allow-null-check"
32
+ ],
33
+ "variable-name": [
34
+ true,
35
+ "ban-keywords"
36
+ ],
37
+ "whitespace": [
38
+ true,
39
+ "check-branch",
40
+ "check-decl",
41
+ "check-operator",
42
+ "check-separator",
43
+ "check-type"
44
+ ]
45
+ },
46
+ "rules": {
47
+ "class-name": true,
48
+ "comment-format": [
49
+ true,
50
+ "check-space"
51
+ ],
52
+ "indent": [
53
+ true,
54
+ "spaces"
55
+ ],
56
+ "no-eval": true,
57
+ "no-internal-module": true,
58
+ "no-trailing-whitespace": true,
59
+ "no-unsafe-finally": true,
60
+ "no-var-keyword": true,
61
+ "one-line": [
62
+ true,
63
+ "check-open-brace",
64
+ "check-whitespace"
65
+ ],
66
+ "semicolon": [
67
+ true,
68
+ "never"
69
+ ],
70
+ "triple-equals": [
71
+ true,
72
+ "allow-null-check"
73
+ ],
74
+ "typedef-whitespace": [
75
+ true,
76
+ {
77
+ "call-signature": "nospace",
78
+ "index-signature": "nospace",
79
+ "parameter": "nospace",
80
+ "property-declaration": "nospace",
81
+ "variable-declaration": "nospace"
82
+ }
83
+ ],
84
+ "variable-name": [
85
+ true,
86
+ "ban-keywords"
87
+ ],
88
+ "whitespace": [
89
+ true,
90
+ "check-branch",
91
+ "check-decl",
92
+ "check-operator",
93
+ "check-separator",
94
+ "check-type"
95
+ ],
96
+ "no-namespace": true,
97
+ "prefer-for-of": true,
98
+ "only-arrow-functions": [true, "allow-declarations"],
99
+ "no-var-requires": true,
100
+ "no-any": true,
101
+ "curly": true,
102
+ "forin": true,
103
+ "no-arg": true,
104
+ "label-position": true,
105
+ "no-conditional-assignment": true,
106
+ "no-console": [true, "log", "error"],
107
+ "no-construct": true,
108
+ "no-duplicate-variable": true,
109
+ "no-empty": true,
110
+ "no-invalid-this": [true, "check-function-in-method"],
111
+ "no-misused-new": true,
112
+ "no-null-keyword": true,
113
+ "no-string-literal": true,
114
+ "radix": true,
115
+ "typeof-compare": true,
116
+ "use-isnan": true,
117
+ "prefer-const": true,
118
+ "array-type": [true, "array-simple"],
119
+ "arrow-parens": true,
120
+ "new-parens": true,
121
+ "no-consecutive-blank-lines": [true,1],
122
+ "no-parameter-properties": true,
123
+ "no-unnecessary-initializer": true,
124
+ "object-literal-shorthand": true,
125
+ "object-literal-key-quotes": [true, "as-needed"]
126
+ }
127
+ }
@@ -0,0 +1,97 @@
1
+
2
+ export enum Bucket {
3
+ One = "one",
4
+ Two = "two"
5
+ }
6
+
7
+ export class TwoBucket {
8
+ starter: Bucket
9
+ x: number
10
+ y: number
11
+ z: number
12
+ goalBucket: Bucket
13
+ otherBucket: number
14
+
15
+ constructor(x: number, y: number, z: number, starter: Bucket) {
16
+ this.starter = starter
17
+ this.x = x
18
+ this.y = y
19
+ this.z = z
20
+ }
21
+ reachedGoal(measurements: number[]): boolean {
22
+ if (measurements[0] === this.z || measurements[1] === this.z) {
23
+ if (measurements[0] === this.z) {
24
+ this.goalBucket = Bucket.One
25
+ this.otherBucket = measurements[1]
26
+ } else {
27
+ this.goalBucket = Bucket.Two
28
+ this.otherBucket = measurements[0]
29
+ }
30
+ return true
31
+ }
32
+ return false
33
+ }
34
+ bigFirst(measurements: number[], moveCount: number, prBool: boolean): number {
35
+ let j = measurements[0],
36
+ k = measurements[1]
37
+ while (!this.reachedGoal(measurements)) {
38
+ if (k > this.x && j === 0 && moveCount === 0) {
39
+ j = this.x
40
+ k = this.y - j
41
+ } else if (j === this.x) {
42
+ j = 0
43
+ } else if (k > this.x && j !== 0 || k > this.x && prBool) {
44
+ k -= (this.x - j)
45
+ j = this.x
46
+ } else if (k > this.x || j === 0) {
47
+ j = k
48
+ k -= j
49
+ } else if (k === 0) {
50
+ k = this.y
51
+ }
52
+ measurements = [j, k]
53
+ moveCount++
54
+ prBool = !prBool
55
+ }
56
+ return moveCount
57
+ }
58
+ smallFirst(measurements: number[], moveCount: number, prBool: boolean): number {
59
+ let j = measurements[0],
60
+ k = measurements[1]
61
+ while (!this.reachedGoal(measurements)) {
62
+ if (j === this.x && moveCount === 0) {
63
+ j = 0
64
+ k = this.x
65
+ } else if (j === 0) {
66
+ j = this.x
67
+ } else if (j === this.x && k < this.y) {
68
+ const tempK = k
69
+ k + j > this.y ? k = this.y : k = tempK + j
70
+ tempK + j > this.y ? j -= (this.y - tempK) : j = 0
71
+ } else if (k === this.y) {
72
+ k = 0
73
+ } else if (k === 0 && j < this.x) {
74
+ k = j
75
+ j = 0
76
+ }
77
+ measurements = [j, k]
78
+ moveCount++
79
+ prBool = !prBool
80
+ }
81
+ return moveCount
82
+ }
83
+ moves() {
84
+ let j = 0,
85
+ k = 0 // j will be running val of bucket one, k = running val of bucket two
86
+ this.starter === Bucket.One ? j = this.x : k = this.y
87
+ const measurements = [j, k]
88
+ let moveCount = 0
89
+ const prBool = true // pour / receive boolean - need to pour or receive every other turn
90
+ if (this.starter === Bucket.One) {
91
+ moveCount = this.smallFirst(measurements, moveCount, prBool)
92
+ } else {
93
+ moveCount = this.bigFirst(measurements, moveCount, prBool)
94
+ }
95
+ return moveCount + 1 // accounts for first move made before loop (and moveCount starts at zero before loop)
96
+ }
97
+ }