trackler 2.2.0.0 → 2.2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/trackler/version.rb +1 -1
- data/problem-specifications/CONTRIBUTING.md +1 -1
- data/tracks/bash/.travis.yml +1 -1
- data/tracks/bash/config.json +30 -3
- data/tracks/c/README.md +1 -1
- data/tracks/c/config.json +131 -39
- data/tracks/ceylon/README.md +6 -6
- data/tracks/ceylon/config.json +21 -3
- data/tracks/chapel/.travis.yml +1 -1
- data/tracks/clojurescript/.travis.yml +1 -1
- data/tracks/clojurescript/README.md +6 -6
- data/tracks/clojurescript/exercises/.keep +0 -0
- data/tracks/coffeescript/.travis.yml +1 -1
- data/tracks/coldfusion/.travis.yml +1 -1
- data/tracks/coq/.travis.yml +1 -1
- data/tracks/cpp/CMakeLists.txt +1 -0
- data/tracks/cpp/README.md +1 -1
- data/tracks/cpp/config.json +8 -0
- data/tracks/cpp/exercises/atbash-cipher/CMakeLists.txt +52 -0
- data/tracks/cpp/exercises/atbash-cipher/atbash_cipher_test.cpp +68 -0
- data/tracks/cpp/exercises/atbash-cipher/example.cpp +54 -0
- data/tracks/cpp/exercises/atbash-cipher/example.h +13 -0
- data/tracks/csharp/config.json +315 -6
- data/tracks/d/.travis.yml +1 -1
- data/tracks/dart/README.md +2 -2
- data/tracks/dart/config.json +21 -3
- data/tracks/delphi/README.md +1 -1
- data/tracks/delphi/config.json +83 -1
- data/tracks/ecmascript/config.json +10 -0
- data/tracks/ecmascript/exercises/accumulate/accumulate.spec.js +3 -9
- data/tracks/ecmascript/exercises/acronym/acronym.spec.js +2 -2
- data/tracks/ecmascript/exercises/all-your-base/all-your-base.spec.js +131 -133
- data/tracks/ecmascript/exercises/all-your-base/example.js +1 -3
- data/tracks/ecmascript/exercises/allergies/allergies.spec.js +8 -10
- data/tracks/ecmascript/exercises/allergies/example.js +3 -5
- data/tracks/ecmascript/exercises/alphametics/alphametics.spec.js +61 -63
- data/tracks/ecmascript/exercises/alphametics/example.js +99 -99
- data/tracks/ecmascript/exercises/anagram/anagram.spec.js +35 -37
- data/tracks/ecmascript/exercises/anagram/example.js +1 -3
- data/tracks/ecmascript/exercises/atbash-cipher/atbash-cipher.spec.js +1 -3
- data/tracks/ecmascript/exercises/atbash-cipher/example.js +3 -3
- data/tracks/ecmascript/exercises/beer-song/beer-song.spec.js +0 -2
- data/tracks/ecmascript/exercises/beer-song/example.js +9 -9
- data/tracks/ecmascript/exercises/binary/binary.spec.js +1 -2
- data/tracks/ecmascript/exercises/binary/example.js +3 -3
- data/tracks/ecmascript/exercises/binary-search/binary-search.spec.js +1 -3
- data/tracks/ecmascript/exercises/binary-search-tree/binary-search-tree.spec.js +13 -15
- data/tracks/ecmascript/exercises/binary-search-tree/example.js +2 -2
- data/tracks/ecmascript/exercises/bob/bob.spec.js +1 -3
- data/tracks/ecmascript/exercises/bob/example.js +3 -3
- data/tracks/ecmascript/exercises/bracket-push/example.js +2 -2
- data/tracks/ecmascript/exercises/circular-buffer/circular-buffer.spec.js +10 -12
- data/tracks/ecmascript/exercises/circular-buffer/example.js +12 -11
- data/tracks/ecmascript/exercises/clock/clock.spec.js +0 -8
- data/tracks/ecmascript/exercises/clock/example.js +11 -11
- data/tracks/ecmascript/exercises/connect/connect.spec.js +75 -77
- data/tracks/ecmascript/exercises/connect/example.js +27 -29
- data/tracks/ecmascript/exercises/crypto-square/crypto-square.spec.js +11 -11
- data/tracks/ecmascript/exercises/crypto-square/example.js +11 -10
- data/tracks/ecmascript/exercises/custom-set/custom-set.spec.js +2 -4
- data/tracks/ecmascript/exercises/custom-set/example.js +1 -1
- data/tracks/ecmascript/exercises/diamond/diamond.spec.js +20 -21
- data/tracks/ecmascript/exercises/diamond/example.js +12 -13
- data/tracks/ecmascript/exercises/difference-of-squares/difference-of-squares.spec.js +0 -5
- data/tracks/ecmascript/exercises/diffie-hellman/diffie-hellman.spec.js +7 -28
- data/tracks/ecmascript/exercises/etl/etl.spec.js +36 -18
- data/tracks/ecmascript/exercises/etl/example.js +3 -3
- data/tracks/ecmascript/exercises/flatten-array/example.js +1 -1
- data/tracks/ecmascript/exercises/flatten-array/flatten-array.spec.js +2 -3
- data/tracks/ecmascript/exercises/food-chain/example.js +12 -12
- data/tracks/ecmascript/exercises/food-chain/food-chain.spec.js +0 -1
- data/tracks/ecmascript/exercises/gigasecond/example.js +1 -1
- data/tracks/ecmascript/exercises/gigasecond/gigasecond.spec.js +0 -1
- data/tracks/ecmascript/exercises/grade-school/grade-school.spec.js +18 -19
- data/tracks/ecmascript/exercises/grains/grains.spec.js +0 -1
- data/tracks/ecmascript/exercises/hamming/example.js +3 -3
- data/tracks/ecmascript/exercises/hamming/hamming.spec.js +5 -6
- data/tracks/ecmascript/exercises/hello-world/example.js +1 -1
- data/tracks/ecmascript/exercises/hello-world/hello-world.spec.js +1 -1
- data/tracks/ecmascript/exercises/hexadecimal/example.js +2 -2
- data/tracks/ecmascript/exercises/hexadecimal/hexadecimal.spec.js +9 -11
- data/tracks/ecmascript/exercises/isogram/isogram.spec.js +22 -23
- data/tracks/ecmascript/exercises/kindergarten-garden/example.js +7 -7
- data/tracks/ecmascript/exercises/kindergarten-garden/kindergarten-garden.spec.js +0 -5
- data/tracks/ecmascript/exercises/largest-series-product/example.js +4 -8
- data/tracks/ecmascript/exercises/largest-series-product/largest-series-product.spec.js +5 -7
- data/tracks/ecmascript/exercises/leap/leap.spec.js +4 -6
- data/tracks/ecmascript/exercises/linked-list/example.js +2 -2
- data/tracks/ecmascript/exercises/list-ops/example.js +19 -19
- data/tracks/ecmascript/exercises/list-ops/list-ops.spec.js +2 -18
- data/tracks/ecmascript/exercises/luhn/example.js +1 -1
- data/tracks/ecmascript/exercises/luhn/luhn.spec.js +1 -3
- data/tracks/ecmascript/exercises/matrix/example.js +2 -4
- data/tracks/ecmascript/exercises/matrix/matrix.spec.js +0 -2
- data/tracks/ecmascript/exercises/meetup/example.js +12 -15
- data/tracks/ecmascript/exercises/meetup/meetup.spec.js +0 -2
- data/tracks/ecmascript/exercises/minesweeper/example.js +60 -0
- data/tracks/ecmascript/exercises/minesweeper/minesweeper.spec.js +174 -0
- data/tracks/ecmascript/exercises/minesweeper/package.json +69 -0
- data/tracks/ecmascript/exercises/nth-prime/example.js +3 -2
- data/tracks/ecmascript/exercises/nth-prime/nth-prime.spec.js +0 -1
- data/tracks/ecmascript/exercises/ocr-numbers/example.js +3 -3
- data/tracks/ecmascript/exercises/ocr-numbers/ocr-numbers.spec.js +16 -18
- data/tracks/ecmascript/exercises/octal/example.js +1 -1
- data/tracks/ecmascript/exercises/octal/octal.spec.js +0 -2
- data/tracks/ecmascript/exercises/palindrome-products/example.js +14 -11
- data/tracks/ecmascript/exercises/palindrome-products/palindrome-products.spec.js +15 -18
- data/tracks/ecmascript/exercises/pangram/example.js +6 -5
- data/tracks/ecmascript/exercises/pangram/pangram.spec.js +10 -12
- data/tracks/ecmascript/exercises/pascals-triangle/example.js +2 -2
- data/tracks/ecmascript/exercises/pascals-triangle/pascals-triangle.spec.js +6 -8
- data/tracks/ecmascript/exercises/perfect-numbers/example.js +3 -5
- data/tracks/ecmascript/exercises/perfect-numbers/perfect-numbers.spec.js +0 -10
- data/tracks/ecmascript/exercises/phone-number/example.js +2 -2
- data/tracks/ecmascript/exercises/phone-number/phone-number.spec.js +0 -2
- data/tracks/ecmascript/exercises/pig-latin/example.js +4 -4
- data/tracks/ecmascript/exercises/pig-latin/pig-latin.spec.js +0 -1
- data/tracks/ecmascript/exercises/prime-factors/example.js +2 -2
- data/tracks/ecmascript/exercises/prime-factors/prime-factors.spec.js +0 -2
- data/tracks/ecmascript/exercises/pythagorean-triplet/pythagorean-triplet.spec.js +3 -11
- data/tracks/ecmascript/exercises/queen-attack/example.js +17 -17
- data/tracks/ecmascript/exercises/queen-attack/queen-attack.spec.js +7 -8
- data/tracks/ecmascript/exercises/raindrops/example.js +1 -1
- data/tracks/ecmascript/exercises/raindrops/raindrops.spec.js +1 -2
- data/tracks/ecmascript/exercises/rna-transcription/example.js +5 -5
- data/tracks/ecmascript/exercises/rna-transcription/rna-transcription.spec.js +4 -5
- data/tracks/ecmascript/exercises/robot-name/example.js +6 -6
- data/tracks/ecmascript/exercises/robot-name/robot-name.spec.js +10 -11
- data/tracks/ecmascript/exercises/robot-simulator/example.js +1 -1
- data/tracks/ecmascript/exercises/robot-simulator/robot-simulator.spec.js +31 -32
- data/tracks/ecmascript/exercises/roman-numerals/example.js +16 -16
- data/tracks/ecmascript/exercises/saddle-points/saddle-points.spec.js +3 -3
- data/tracks/ecmascript/exercises/say/example.js +25 -25
- data/tracks/ecmascript/exercises/say/say.spec.js +2 -3
- data/tracks/ecmascript/exercises/scrabble-score/example.js +27 -9
- data/tracks/ecmascript/exercises/scrabble-score/scrabble-score.spec.js +6 -7
- data/tracks/ecmascript/exercises/secret-handshake/example.js +2 -3
- data/tracks/ecmascript/exercises/secret-handshake/secret-handshake.spec.js +3 -5
- data/tracks/ecmascript/exercises/series/series.spec.js +1 -3
- data/tracks/ecmascript/exercises/sieve/example.js +4 -3
- data/tracks/ecmascript/exercises/sieve/sieve.spec.js +0 -2
- data/tracks/ecmascript/exercises/simple-cipher/example.js +8 -9
- data/tracks/ecmascript/exercises/simple-cipher/simple-cipher.spec.js +4 -4
- data/tracks/ecmascript/exercises/space-age/example.js +1 -1
- data/tracks/ecmascript/exercises/space-age/space-age.spec.js +9 -11
- data/tracks/ecmascript/exercises/strain/example.js +4 -4
- data/tracks/ecmascript/exercises/strain/strain.spec.js +14 -16
- data/tracks/ecmascript/exercises/sum-of-multiples/example.js +4 -4
- data/tracks/ecmascript/exercises/triangle/triangle.spec.js +2 -4
- data/tracks/ecmascript/exercises/trinary/example.js +3 -3
- data/tracks/ecmascript/exercises/trinary/trinary.spec.js +0 -2
- data/tracks/ecmascript/exercises/two-bucket/example.js +30 -27
- data/tracks/ecmascript/exercises/two-bucket/two-bucket.spec.js +4 -8
- data/tracks/ecmascript/exercises/word-count/example.js +2 -2
- data/tracks/ecmascript/exercises/word-count/word-count.spec.js +2 -3
- data/tracks/ecmascript/exercises/wordy/example.js +6 -6
- data/tracks/ecmascript/exercises/wordy/wordy.spec.js +2 -4
- data/tracks/factor/config.json +15 -6
- data/tracks/fortran/.travis.yml +1 -1
- data/tracks/fsharp/config.json +312 -10
- data/tracks/go/README.md +1 -1
- data/tracks/go/config.json +523 -155
- data/tracks/haskell/README.md +2 -2
- data/tracks/haskell/config.json +256 -7
- data/tracks/haxe/.travis.yml +1 -1
- data/tracks/haxe/Makefile +2 -2
- data/tracks/haxe/config.json +8 -5
- data/tracks/java/CONTRIBUTING.md +2 -2
- data/tracks/java/config.json +277 -17
- data/tracks/java/exercises/rotational-cipher/build.gradle +17 -0
- data/tracks/java/exercises/rotational-cipher/src/example/java/RotationalCipher.java +37 -0
- data/tracks/java/exercises/rotational-cipher/src/main/java/.keep +0 -0
- data/tracks/java/exercises/rotational-cipher/src/test/java/RotationalCipherTest.java +81 -0
- data/tracks/java/exercises/settings.gradle +1 -0
- data/tracks/java/exercises/twelve-days/src/main/java/TwelveDays.java +4 -0
- data/tracks/julia/.travis.yml +1 -1
- data/tracks/julia/README.md +1 -1
- data/tracks/kotlin/README.md +2 -2
- data/tracks/kotlin/exercises/hello-world/TUTORIAL.md +3 -3
- data/tracks/lisp/config.json +97 -3
- data/tracks/lisp/exercises/pascals-triangle/example.lisp +21 -0
- data/tracks/lisp/exercises/pascals-triangle/pascal.lisp +7 -0
- data/tracks/lisp/exercises/pascals-triangle/pascals-triangle-test.lisp +34 -0
- data/tracks/lua/.travis.yml +1 -1
- data/tracks/lua/README.md +1 -1
- data/tracks/mips/.travis.yml +1 -1
- data/tracks/mips/config.json +56 -17
- data/tracks/nasm/.travis.yml +1 -1
- data/tracks/nim/.travis.yml +1 -1
- data/tracks/ocaml/README.md +3 -3
- data/tracks/ocaml/config.json +130 -4
- data/tracks/perl5/docs/TESTS.md +40 -26
- data/tracks/plsql/.travis.yml +1 -1
- data/tracks/plsql/config.json +40 -13
- data/tracks/pony/.travis.yml +1 -1
- data/tracks/pony/bin/install-deps +4 -3
- data/tracks/prolog/.travis.yml +1 -1
- data/tracks/r/README.md +5 -5
- data/tracks/r/config.json +102 -30
- data/tracks/rust/.travis.yml +1 -1
- data/tracks/rust/config.json +172 -4
- data/tracks/rust/docs/EXERCISE_README_INSERT.md +1 -1
- data/tracks/sml/config.json +26 -3
- data/tracks/vimscript/config.json +60 -3
- metadata +16 -1
@@ -1,136 +1,136 @@
|
|
1
1
|
import Robot from './robot-simulator';
|
2
2
|
|
3
|
-
describe('Robot',
|
4
|
-
|
3
|
+
describe('Robot', () => {
|
4
|
+
const robot = new Robot();
|
5
5
|
|
6
|
-
test('robot bearing',
|
7
|
-
const directions = [
|
6
|
+
test('robot bearing', () => {
|
7
|
+
const directions = ['east', 'west', 'north', 'south'];
|
8
8
|
|
9
|
-
directions.forEach(currentDirection => {
|
9
|
+
directions.forEach((currentDirection) => {
|
10
10
|
robot.orient(currentDirection);
|
11
11
|
expect(robot.bearing).toEqual(currentDirection);
|
12
12
|
});
|
13
13
|
});
|
14
14
|
|
15
|
-
xtest('invalid robot bearing',
|
15
|
+
xtest('invalid robot bearing', () => {
|
16
16
|
try {
|
17
17
|
robot.orient('crood');
|
18
|
-
} catch(exception) {
|
18
|
+
} catch (exception) {
|
19
19
|
expect(exception).toEqual('Invalid Robot Bearing');
|
20
20
|
}
|
21
21
|
});
|
22
22
|
|
23
|
-
xtest('turn right from north',
|
23
|
+
xtest('turn right from north', () => {
|
24
24
|
robot.orient('north');
|
25
25
|
robot.turnRight();
|
26
26
|
expect(robot.bearing).toEqual('east');
|
27
27
|
});
|
28
28
|
|
29
|
-
xtest('turn right from east',
|
29
|
+
xtest('turn right from east', () => {
|
30
30
|
robot.orient('east');
|
31
31
|
robot.turnRight();
|
32
32
|
expect(robot.bearing).toEqual('south');
|
33
33
|
});
|
34
34
|
|
35
|
-
xtest('turn right from south',
|
35
|
+
xtest('turn right from south', () => {
|
36
36
|
robot.orient('south');
|
37
37
|
robot.turnRight();
|
38
38
|
expect(robot.bearing).toEqual('west');
|
39
39
|
});
|
40
40
|
|
41
|
-
xtest('turn right from west',
|
41
|
+
xtest('turn right from west', () => {
|
42
42
|
robot.orient('west');
|
43
43
|
robot.turnRight();
|
44
44
|
expect(robot.bearing).toEqual('north');
|
45
45
|
});
|
46
46
|
|
47
|
-
xtest('turn left from north',
|
47
|
+
xtest('turn left from north', () => {
|
48
48
|
robot.orient('north');
|
49
49
|
robot.turnLeft();
|
50
50
|
expect(robot.bearing).toEqual('west');
|
51
51
|
});
|
52
52
|
|
53
|
-
xtest('turn left from east',
|
53
|
+
xtest('turn left from east', () => {
|
54
54
|
robot.orient('east');
|
55
55
|
robot.turnLeft();
|
56
56
|
expect(robot.bearing).toEqual('north');
|
57
57
|
});
|
58
58
|
|
59
|
-
xtest('turn left from south',
|
59
|
+
xtest('turn left from south', () => {
|
60
60
|
robot.orient('south');
|
61
61
|
robot.turnLeft();
|
62
62
|
expect(robot.bearing).toEqual('east');
|
63
63
|
});
|
64
64
|
|
65
|
-
xtest('turn left from west',
|
65
|
+
xtest('turn left from west', () => {
|
66
66
|
robot.orient('west');
|
67
67
|
robot.turnLeft();
|
68
68
|
expect(robot.bearing).toEqual('south');
|
69
69
|
});
|
70
70
|
|
71
|
-
xtest('robot coordinates',
|
71
|
+
xtest('robot coordinates', () => {
|
72
72
|
robot.at(3, 0);
|
73
73
|
expect(robot.coordinates).toEqual([3, 0]);
|
74
74
|
});
|
75
75
|
|
76
|
-
xtest('other robot coordinates',
|
76
|
+
xtest('other robot coordinates', () => {
|
77
77
|
robot.at(-2, 5);
|
78
78
|
expect(robot.coordinates).toEqual([-2, 5]);
|
79
79
|
});
|
80
80
|
|
81
|
-
xtest('advance when facing north',
|
81
|
+
xtest('advance when facing north', () => {
|
82
82
|
robot.at(0, 0);
|
83
83
|
robot.orient('north');
|
84
84
|
robot.advance();
|
85
85
|
expect(robot.coordinates).toEqual([0, 1]);
|
86
86
|
});
|
87
87
|
|
88
|
-
xtest('advance when facing east',
|
88
|
+
xtest('advance when facing east', () => {
|
89
89
|
robot.at(0, 0);
|
90
90
|
robot.orient('east');
|
91
91
|
robot.advance();
|
92
92
|
expect(robot.coordinates).toEqual([1, 0]);
|
93
93
|
});
|
94
94
|
|
95
|
-
xtest('advance when facing south',
|
95
|
+
xtest('advance when facing south', () => {
|
96
96
|
robot.at(0, 0);
|
97
97
|
robot.orient('south');
|
98
98
|
robot.advance();
|
99
99
|
expect(robot.coordinates).toEqual([0, -1]);
|
100
100
|
});
|
101
101
|
|
102
|
-
xtest('advance when facing west',
|
102
|
+
xtest('advance when facing west', () => {
|
103
103
|
robot.at(0, 0);
|
104
104
|
robot.orient('west');
|
105
105
|
robot.advance();
|
106
106
|
expect(robot.coordinates).toEqual([-1, 0]);
|
107
107
|
});
|
108
108
|
|
109
|
-
xtest('instructions for turning left',
|
110
|
-
expect(robot.instructions('L')).toEqual([
|
109
|
+
xtest('instructions for turning left', () => {
|
110
|
+
expect(robot.instructions('L')).toEqual(['turnLeft']);
|
111
111
|
});
|
112
112
|
|
113
|
-
xtest('instructions for turning right',
|
114
|
-
expect(robot.instructions('R')).toEqual([
|
113
|
+
xtest('instructions for turning right', () => {
|
114
|
+
expect(robot.instructions('R')).toEqual(['turnRight']);
|
115
115
|
});
|
116
116
|
|
117
|
-
xtest('instructions for advancing',
|
118
|
-
expect(robot.instructions('A')).toEqual([
|
117
|
+
xtest('instructions for advancing', () => {
|
118
|
+
expect(robot.instructions('A')).toEqual(['advance']);
|
119
119
|
});
|
120
120
|
|
121
|
-
xtest('series of instructions',
|
121
|
+
xtest('series of instructions', () => {
|
122
122
|
expect(robot.instructions('RAAL'))
|
123
|
-
.toEqual([
|
123
|
+
.toEqual(['turnRight', 'advance', 'advance', 'turnLeft']);
|
124
124
|
});
|
125
125
|
|
126
|
-
xtest('instruct robot',
|
126
|
+
xtest('instruct robot', () => {
|
127
127
|
robot.place({ x: -2, y: 1, direction: 'east' });
|
128
128
|
robot.evaluate('RLAALAL');
|
129
129
|
expect(robot.coordinates).toEqual([0, 2]);
|
130
130
|
expect(robot.bearing).toEqual('west');
|
131
131
|
});
|
132
132
|
|
133
|
-
xtest('instruct many robots',
|
133
|
+
xtest('instruct many robots', () => {
|
134
134
|
const robot1 = new Robot();
|
135
135
|
const robot2 = new Robot();
|
136
136
|
const robot3 = new Robot();
|
@@ -150,5 +150,4 @@ describe('Robot', function() {
|
|
150
150
|
expect(robot3.coordinates).toEqual([11, 5]);
|
151
151
|
expect(robot3.bearing).toEqual('north');
|
152
152
|
});
|
153
|
-
|
154
153
|
});
|
@@ -1,25 +1,25 @@
|
|
1
1
|
function toRoman(number) {
|
2
2
|
let result = '';
|
3
3
|
const mappings = [
|
4
|
-
{ arabic: 1000, roman:
|
5
|
-
{ arabic:
|
6
|
-
{ arabic:
|
7
|
-
{ arabic:
|
8
|
-
{ arabic:
|
9
|
-
{ arabic:
|
10
|
-
{ arabic:
|
11
|
-
{ arabic:
|
12
|
-
{ arabic:
|
13
|
-
{ arabic:
|
14
|
-
{ arabic:
|
15
|
-
{ arabic:
|
16
|
-
{ arabic:
|
4
|
+
{ arabic: 1000, roman: 'M' },
|
5
|
+
{ arabic: 900, roman: 'CM' },
|
6
|
+
{ arabic: 500, roman: 'D' },
|
7
|
+
{ arabic: 400, roman: 'CD' },
|
8
|
+
{ arabic: 100, roman: 'C' },
|
9
|
+
{ arabic: 90, roman: 'XC' },
|
10
|
+
{ arabic: 50, roman: 'L' },
|
11
|
+
{ arabic: 40, roman: 'XL' },
|
12
|
+
{ arabic: 10, roman: 'X' },
|
13
|
+
{ arabic: 9, roman: 'IX' },
|
14
|
+
{ arabic: 5, roman: 'V' },
|
15
|
+
{ arabic: 4, roman: 'IV' },
|
16
|
+
{ arabic: 1, roman: 'I' },
|
17
17
|
];
|
18
18
|
|
19
|
-
mappings.forEach(mapping => {
|
19
|
+
mappings.forEach((mapping) => {
|
20
20
|
while (number >= mapping.arabic) {
|
21
|
-
result
|
22
|
-
number
|
21
|
+
result += mapping.roman;
|
22
|
+
number -= mapping.arabic;
|
23
23
|
}
|
24
24
|
});
|
25
25
|
|
@@ -3,7 +3,7 @@ import Matrix from './saddle-points';
|
|
3
3
|
describe('Matrix', () => {
|
4
4
|
test('extracts a row', () => {
|
5
5
|
const matrix = new Matrix('1 2\n10 20');
|
6
|
-
expect(matrix.rows[0]).toEqual([1,2]);
|
6
|
+
expect(matrix.rows[0]).toEqual([1, 2]);
|
7
7
|
});
|
8
8
|
|
9
9
|
xtest('extracts other row', () => {
|
@@ -28,12 +28,12 @@ describe('Matrix', () => {
|
|
28
28
|
|
29
29
|
xtest('a saddle point', () => {
|
30
30
|
const matrix = new Matrix('1 2\n3 4');
|
31
|
-
expect(matrix.saddlePoints).toEqual([[0,1]]);
|
31
|
+
expect(matrix.saddlePoints).toEqual([[0, 1]]);
|
32
32
|
});
|
33
33
|
|
34
34
|
xtest('another saddle point', () => {
|
35
35
|
const matrix = new Matrix('18 3 39 19 91\n38 10 8 77 320\n3 4 8 6 7');
|
36
|
-
expect(matrix.saddlePoints).toEqual([[2,2]]);
|
36
|
+
expect(matrix.saddlePoints).toEqual([[2, 2]]);
|
37
37
|
});
|
38
38
|
|
39
39
|
xtest('multiple saddle points', () => {
|
@@ -1,14 +1,14 @@
|
|
1
1
|
const smallNumbers = {
|
2
|
-
0:
|
3
|
-
1:
|
4
|
-
2:
|
5
|
-
3:
|
6
|
-
4:
|
7
|
-
5:
|
8
|
-
6:
|
9
|
-
7:
|
10
|
-
8:
|
11
|
-
9:
|
2
|
+
0: 'zero',
|
3
|
+
1: 'one',
|
4
|
+
2: 'two',
|
5
|
+
3: 'three',
|
6
|
+
4: 'four',
|
7
|
+
5: 'five',
|
8
|
+
6: 'six',
|
9
|
+
7: 'seven',
|
10
|
+
8: 'eight',
|
11
|
+
9: 'nine',
|
12
12
|
10: 'ten',
|
13
13
|
11: 'eleven',
|
14
14
|
12: 'twelve',
|
@@ -18,7 +18,7 @@ const smallNumbers = {
|
|
18
18
|
16: 'sixteen',
|
19
19
|
17: 'seventeen',
|
20
20
|
18: 'eighteen',
|
21
|
-
19: 'nineteen'
|
21
|
+
19: 'nineteen',
|
22
22
|
};
|
23
23
|
|
24
24
|
const decades = {
|
@@ -29,31 +29,32 @@ const decades = {
|
|
29
29
|
60: 'sixty',
|
30
30
|
70: 'seventy',
|
31
31
|
80: 'eighty',
|
32
|
-
90: 'ninety'
|
32
|
+
90: 'ninety',
|
33
33
|
};
|
34
34
|
|
35
35
|
const bigNumbers = {
|
36
|
-
1000:
|
37
|
-
1000000:
|
38
|
-
1000000000: 'billion'
|
36
|
+
1000: 'thousand',
|
37
|
+
1000000: 'million',
|
38
|
+
1000000000: 'billion',
|
39
39
|
};
|
40
40
|
|
41
41
|
function bigPart(number) {
|
42
|
-
let factor,
|
42
|
+
let factor,
|
43
|
+
result = '';
|
43
44
|
for (let bigNumber = 1000000000; bigNumber >= 1000; bigNumber /= 1000) {
|
44
45
|
if (number.current >= bigNumber) {
|
45
46
|
factor = Math.floor(number.current / bigNumber);
|
46
|
-
result += threeDigit(factor)
|
47
|
-
number.current
|
47
|
+
result += `${threeDigit(factor)} ${bigNumbers[bigNumber]} `;
|
48
|
+
number.current -= factor * bigNumber;
|
48
49
|
}
|
49
50
|
}
|
50
51
|
return result;
|
51
52
|
}
|
52
53
|
|
53
|
-
const sayDecade = n => {
|
54
|
+
const sayDecade = (n) => {
|
54
55
|
for (let decade = 90; decade >= 20; decade -= 10) {
|
55
56
|
if (n >= decade) {
|
56
|
-
return decades[decade]
|
57
|
+
return `${decades[decade]}-${smallNumbers[n - decade]}`;
|
57
58
|
}
|
58
59
|
}
|
59
60
|
};
|
@@ -61,19 +62,18 @@ const sayDecade = n => {
|
|
61
62
|
const twoDigit = n => n < 20 ? smallNumbers[n] : sayDecade(n);
|
62
63
|
|
63
64
|
const threeDigit = n => n < 100 ? twoDigit(n)
|
64
|
-
: smallNumbers[Math.floor(n / 100)]
|
65
|
+
: `${smallNumbers[Math.floor(n / 100)]} hundred ${twoDigit(n % 100)}`;
|
65
66
|
|
66
67
|
export default class Say {
|
67
68
|
inEnglish(n) {
|
68
69
|
let result;
|
69
|
-
const number = {current: n};
|
70
|
+
const number = { current: n };
|
70
71
|
|
71
|
-
if (
|
72
|
+
if (n >= 0 && n < 1000000000000) {
|
72
73
|
result = bigPart(number);
|
73
74
|
result += threeDigit(number.current);
|
74
75
|
return result.replace(/.zero/, '');
|
75
|
-
} else {
|
76
|
-
throw new Error('Number must be between 0 and 999,999,999,999.');
|
77
76
|
}
|
77
|
+
throw new Error('Number must be between 0 and 999,999,999,999.');
|
78
78
|
}
|
79
79
|
}
|
@@ -65,14 +65,13 @@ describe('say', () => {
|
|
65
65
|
|
66
66
|
xtest('raises an error below zero', () => {
|
67
67
|
expect(() => {
|
68
|
-
say.inEnglish(-1)
|
68
|
+
say.inEnglish(-1);
|
69
69
|
}).toThrow(new Error('Number must be between 0 and 999,999,999,999.'));
|
70
70
|
});
|
71
71
|
|
72
72
|
xtest('raises an error above 999,999,999,999', () => {
|
73
73
|
expect(() => {
|
74
|
-
say.inEnglish(1000000000000)
|
74
|
+
say.inEnglish(1000000000000);
|
75
75
|
}).toThrow(new Error('Number must be between 0 and 999,999,999,999.'));
|
76
76
|
});
|
77
|
-
|
78
77
|
});
|
@@ -1,17 +1,35 @@
|
|
1
1
|
const letterScores = {
|
2
|
-
a
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
2
|
+
a: 1,
|
3
|
+
e: 1,
|
4
|
+
i: 1,
|
5
|
+
o: 1,
|
6
|
+
u: 1,
|
7
|
+
l: 1,
|
8
|
+
n: 1,
|
9
|
+
r: 1,
|
10
|
+
s: 1,
|
11
|
+
t: 1,
|
12
|
+
d: 2,
|
13
|
+
g: 2,
|
14
|
+
b: 3,
|
15
|
+
c: 3,
|
16
|
+
m: 3,
|
17
|
+
p: 3,
|
18
|
+
f: 4,
|
19
|
+
h: 4,
|
20
|
+
v: 4,
|
21
|
+
w: 4,
|
22
|
+
y: 4,
|
23
|
+
k: 5,
|
24
|
+
j: 8,
|
25
|
+
x: 8,
|
26
|
+
q: 10,
|
27
|
+
z: 10,
|
9
28
|
};
|
10
29
|
|
11
|
-
const letterScore =
|
30
|
+
const letterScore = letter => letterScores[letter] || 0;
|
12
31
|
|
13
32
|
export default (word) => {
|
14
|
-
|
15
33
|
word = word ? word.toLowerCase() : '';
|
16
34
|
|
17
35
|
let sum = 0;
|
@@ -1,16 +1,15 @@
|
|
1
1
|
import score from './scrabble-score';
|
2
2
|
|
3
|
-
describe('Scrabble',
|
4
|
-
test('scores an empty word as zero',() => expect(score('')).toEqual(0));
|
3
|
+
describe('Scrabble', () => {
|
4
|
+
test('scores an empty word as zero', () => expect(score('')).toEqual(0));
|
5
5
|
|
6
|
-
xtest('scores a null as zero',() => expect(score(null)).toEqual(0));
|
6
|
+
xtest('scores a null as zero', () => expect(score(null)).toEqual(0));
|
7
7
|
|
8
|
-
xtest('scores a very short word',() => expect(score('a')).toEqual(1));
|
8
|
+
xtest('scores a very short word', () => expect(score('a')).toEqual(1));
|
9
9
|
|
10
10
|
xtest('scores the word by the number of letters', () => expect(score('street')).toEqual(6));
|
11
11
|
|
12
|
-
xtest('scores more complicated words with more',() => expect(score('quirky')).toEqual(22));
|
13
|
-
|
14
|
-
xtest('scores case insensitive words',() => expect(score('OXYPHENBUTAZONE')).toEqual(41));
|
12
|
+
xtest('scores more complicated words with more', () => expect(score('quirky')).toEqual(22));
|
15
13
|
|
14
|
+
xtest('scores case insensitive words', () => expect(score('OXYPHENBUTAZONE')).toEqual(41));
|
16
15
|
});
|
@@ -1,5 +1,5 @@
|
|
1
1
|
export default function (handshake) {
|
2
|
-
const HANDSHAKE_COMMANDS = [
|
2
|
+
const HANDSHAKE_COMMANDS = ['wink', 'double blink', 'close your eyes', 'jump', 'REVERSE'];
|
3
3
|
|
4
4
|
if (typeof handshake !== 'number') {
|
5
5
|
throw new Error('Handshake must be a number');
|
@@ -12,7 +12,7 @@ export default function (handshake) {
|
|
12
12
|
|
13
13
|
for (let i = 0; i < HANDSHAKE_COMMANDS.length; i++) {
|
14
14
|
const currentCommand = HANDSHAKE_COMMANDS[i];
|
15
|
-
const handshakeHasCommand = handshake & Math.pow(2,i);
|
15
|
+
const handshakeHasCommand = handshake & Math.pow(2, i);
|
16
16
|
|
17
17
|
if (handshakeHasCommand) {
|
18
18
|
if (currentCommand === 'REVERSE') {
|
@@ -27,5 +27,4 @@ export default function (handshake) {
|
|
27
27
|
};
|
28
28
|
|
29
29
|
this.shakeWith = this.calculateHandshake(handshake);
|
30
|
-
|
31
30
|
}
|
@@ -1,7 +1,6 @@
|
|
1
1
|
import SecretHandshake from './secret-handshake';
|
2
2
|
|
3
3
|
describe('Secret Handshake', () => {
|
4
|
-
|
5
4
|
test('binary 1 (hexadecimal 0x01) is a wink', () => {
|
6
5
|
const handshake = new SecretHandshake(0x01);
|
7
6
|
expect(handshake.commands()).toEqual(['wink']);
|
@@ -24,23 +23,22 @@ describe('Secret Handshake', () => {
|
|
24
23
|
|
25
24
|
xtest('binary 11 (hexadecimal 0x03) is wink and double blink', () => {
|
26
25
|
const handshake = new SecretHandshake(0x03);
|
27
|
-
expect(handshake.commands()).toEqual(['wink','double blink']);
|
26
|
+
expect(handshake.commands()).toEqual(['wink', 'double blink']);
|
28
27
|
});
|
29
28
|
|
30
29
|
xtest('binary 10011 (hexadecimal 0x13) is double blink and wink', () => {
|
31
30
|
const handshake = new SecretHandshake(0x13);
|
32
|
-
expect(handshake.commands()).toEqual(['double blink','wink']);
|
31
|
+
expect(handshake.commands()).toEqual(['double blink', 'wink']);
|
33
32
|
});
|
34
33
|
|
35
34
|
xtest('binary 11111 (hexadecimal 0x1F) is jump, close your eyes, double blink, and wink', () => {
|
36
35
|
const handshake = new SecretHandshake(0x1F);
|
37
|
-
expect(handshake.commands()).toEqual(['jump','close your eyes','double blink','wink']);
|
36
|
+
expect(handshake.commands()).toEqual(['jump', 'close your eyes', 'double blink', 'wink']);
|
38
37
|
});
|
39
38
|
|
40
39
|
xtest('text is an invalid secret handshake', () => {
|
41
40
|
expect(() => new SecretHandshake('piggies'))
|
42
41
|
.toThrow(new Error('Handshake must be a number'));
|
43
42
|
});
|
44
|
-
|
45
43
|
});
|
46
44
|
|
@@ -1,7 +1,6 @@
|
|
1
1
|
import Series from './series';
|
2
2
|
|
3
3
|
describe('Series', () => {
|
4
|
-
|
5
4
|
test('has digits (short)', () => {
|
6
5
|
expect(new Series('01234').digits).toEqual([0, 1, 2, 3, 4]);
|
7
6
|
});
|
@@ -52,9 +51,8 @@ describe('Series', () => {
|
|
52
51
|
});
|
53
52
|
|
54
53
|
xtest('throws an error if not enough digits to slice', () => {
|
55
|
-
expect(
|
54
|
+
expect(() => {
|
56
55
|
new Series('01032987583').slices(12);
|
57
56
|
}).toThrow(new Error('Slice size is too big.'));
|
58
57
|
});
|
59
|
-
|
60
58
|
});
|
@@ -1,7 +1,7 @@
|
|
1
1
|
function newArrayWithRange(first, last) {
|
2
2
|
let i;
|
3
3
|
const array = [];
|
4
|
-
for (
|
4
|
+
for (i = first; i <= last; i++) {
|
5
5
|
array.push(i);
|
6
6
|
}
|
7
7
|
return array;
|
@@ -12,7 +12,8 @@ function indivisibleBy(value) {
|
|
12
12
|
}
|
13
13
|
|
14
14
|
function sieve(n) {
|
15
|
-
let prime,
|
15
|
+
let prime,
|
16
|
+
possibilities;
|
16
17
|
const primes = [];
|
17
18
|
|
18
19
|
possibilities = newArrayWithRange(2, n);
|
@@ -20,7 +21,7 @@ function sieve(n) {
|
|
20
21
|
do {
|
21
22
|
prime = possibilities.shift();
|
22
23
|
primes.push(prime);
|
23
|
-
possibilities = possibilities.filter(
|
24
|
+
possibilities = possibilities.filter(indivisibleBy, prime);
|
24
25
|
} while (possibilities.length > 0);
|
25
26
|
|
26
27
|
return primes;
|
@@ -1,7 +1,6 @@
|
|
1
1
|
import Sieve from './sieve';
|
2
2
|
|
3
3
|
describe('Sieve', () => {
|
4
|
-
|
5
4
|
test('finds primes up to 10', () => {
|
6
5
|
expect(new Sieve(10).primes).toEqual([2, 3, 5, 7]);
|
7
6
|
});
|
@@ -13,5 +12,4 @@ describe('Sieve', () => {
|
|
13
12
|
xtest('finds primes up to 1000', () => {
|
14
13
|
expect(new Sieve(1000).primes).toEqual([2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997]);
|
15
14
|
});
|
16
|
-
|
17
15
|
});
|
@@ -1,7 +1,7 @@
|
|
1
1
|
const ALPHA = 'abcdefghijklmnopqrstuvwxyz';
|
2
2
|
|
3
3
|
function generateKey() {
|
4
|
-
return Array
|
4
|
+
return Array(...Array(100))
|
5
5
|
.map(() => ALPHA[Math.floor(Math.random() * ALPHA.length)])
|
6
6
|
.join('');
|
7
7
|
}
|
@@ -18,20 +18,19 @@ function xCode(key, inText, sign) {
|
|
18
18
|
const mod = (n, m) => (n % m + m) % m;
|
19
19
|
|
20
20
|
export default function (key) {
|
21
|
-
|
22
21
|
if (typeof key === 'undefined') {
|
23
22
|
key = generateKey();
|
24
|
-
} else if (key.length === 0 || key.match(/[^a-z]/,
|
25
|
-
throw new Error(
|
23
|
+
} else if (key.length === 0 || key.match(/[^a-z]/, 'g')) {
|
24
|
+
throw new Error('Bad key');
|
26
25
|
}
|
27
26
|
|
28
27
|
return {
|
29
|
-
key
|
30
|
-
encode
|
28
|
+
key,
|
29
|
+
encode(plainText) {
|
31
30
|
return xCode(this.key, plainText, 1);
|
32
31
|
},
|
33
|
-
decode
|
32
|
+
decode(encodedText) {
|
34
33
|
return xCode(this.key, encodedText, -1);
|
35
|
-
}
|
36
|
-
}
|
34
|
+
},
|
35
|
+
};
|
37
36
|
}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import Cipher from './simple-cipher';
|
2
2
|
|
3
|
-
describe('Random key cipher',
|
3
|
+
describe('Random key cipher', () => {
|
4
4
|
const cipher = new Cipher();
|
5
5
|
|
6
6
|
test('has a key made of letters', () => {
|
@@ -26,19 +26,19 @@ describe('Random key cipher', () => {
|
|
26
26
|
|
27
27
|
describe('Incorrect key cipher', () => {
|
28
28
|
xtest('throws an error with an all caps key', () => {
|
29
|
-
expect(
|
29
|
+
expect(() => {
|
30
30
|
new Cipher('ABCDEF');
|
31
31
|
}).toThrow(new Error('Bad key'));
|
32
32
|
});
|
33
33
|
|
34
34
|
xtest('throws an error with a numeric key', () => {
|
35
|
-
expect(
|
35
|
+
expect(() => {
|
36
36
|
new Cipher('12345');
|
37
37
|
}).toThrow(new Error('Bad key'));
|
38
38
|
});
|
39
39
|
|
40
40
|
xtest('throws an error with an empty key', () => {
|
41
|
-
expect(
|
41
|
+
expect(() => {
|
42
42
|
new Cipher('');
|
43
43
|
}).toThrow(new Error('Bad key'));
|
44
44
|
});
|