trackler 2.2.1.135 → 2.2.1.136
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.
- checksums.yaml +4 -4
- data/lib/trackler/version.rb +1 -1
- data/problem-specifications/exercises/pov/canonical-data.json +33 -1
- data/tracks/c/exercises/acronym/test/test_acronym.c +25 -17
- data/tracks/csharp/exercises/binary-search-tree/BinarySearchTreeTest.cs +37 -28
- data/tracks/csharp/generators/Exercises/BinarySearchTree.cs +69 -0
- data/tracks/haskell/config.json +1 -0
- data/tracks/haskell/exercises/accumulate/package.yaml +1 -1
- data/tracks/haskell/exercises/acronym/package.yaml +1 -1
- data/tracks/haskell/exercises/all-your-base/package.yaml +1 -1
- data/tracks/haskell/exercises/allergies/package.yaml +1 -1
- data/tracks/haskell/exercises/alphametics/package.yaml +1 -1
- data/tracks/haskell/exercises/anagram/package.yaml +1 -1
- data/tracks/haskell/exercises/atbash-cipher/package.yaml +1 -1
- data/tracks/haskell/exercises/bank-account/package.yaml +1 -1
- data/tracks/haskell/exercises/beer-song/package.yaml +1 -1
- data/tracks/haskell/exercises/binary-search-tree/package.yaml +1 -1
- data/tracks/haskell/exercises/binary/package.yaml +1 -1
- data/tracks/haskell/exercises/bob/package.yaml +1 -1
- data/tracks/haskell/exercises/bowling/package.yaml +1 -1
- data/tracks/haskell/exercises/bracket-push/package.yaml +1 -1
- data/tracks/haskell/exercises/change/package.yaml +1 -1
- data/tracks/haskell/exercises/clock/package.yaml +1 -1
- data/tracks/haskell/exercises/collatz-conjecture/package.yaml +1 -1
- data/tracks/haskell/exercises/complex-numbers/package.yaml +1 -1
- data/tracks/haskell/exercises/connect/package.yaml +1 -1
- data/tracks/haskell/exercises/crypto-square/package.yaml +1 -1
- data/tracks/haskell/exercises/custom-set/package.yaml +1 -1
- data/tracks/haskell/exercises/diamond/package.yaml +1 -1
- data/tracks/haskell/exercises/difference-of-squares/package.yaml +1 -1
- data/tracks/haskell/exercises/dominoes/package.yaml +1 -1
- data/tracks/haskell/exercises/etl/package.yaml +1 -1
- data/tracks/haskell/exercises/food-chain/package.yaml +1 -1
- data/tracks/haskell/exercises/forth/package.yaml +1 -1
- data/tracks/haskell/exercises/gigasecond/package.yaml +1 -1
- data/tracks/haskell/exercises/go-counting/package.yaml +1 -1
- data/tracks/haskell/exercises/grade-school/package.yaml +1 -1
- data/tracks/haskell/exercises/grains/package.yaml +1 -1
- data/tracks/haskell/exercises/hamming/package.yaml +1 -1
- data/tracks/haskell/exercises/hello-world/package.yaml +1 -1
- data/tracks/haskell/exercises/hexadecimal/package.yaml +1 -1
- data/tracks/haskell/exercises/house/package.yaml +1 -1
- data/tracks/haskell/exercises/isbn-verifier/package.yaml +1 -1
- data/tracks/haskell/exercises/isogram/package.yaml +1 -1
- data/tracks/haskell/exercises/kindergarten-garden/examples/success-standard/src/Garden.hs +1 -10
- data/tracks/haskell/exercises/kindergarten-garden/package.yaml +2 -3
- data/tracks/haskell/exercises/kindergarten-garden/src/Garden.hs +3 -7
- data/tracks/haskell/exercises/kindergarten-garden/test/Tests.hs +10 -16
- data/tracks/haskell/exercises/largest-series-product/package.yaml +1 -1
- data/tracks/haskell/exercises/leap/package.yaml +1 -1
- data/tracks/haskell/exercises/lens-person/examples/success-standard/package.yaml +0 -1
- data/tracks/haskell/exercises/lens-person/package.yaml +1 -1
- data/tracks/haskell/exercises/linked-list/package.yaml +1 -1
- data/tracks/haskell/exercises/list-ops/package.yaml +1 -1
- data/tracks/haskell/exercises/luhn/package.yaml +1 -1
- data/tracks/haskell/exercises/matrix/package.yaml +1 -1
- data/tracks/haskell/exercises/meetup/package.yaml +1 -1
- data/tracks/haskell/exercises/minesweeper/package.yaml +1 -1
- data/tracks/haskell/exercises/nth-prime/package.yaml +1 -1
- data/tracks/haskell/exercises/nucleotide-count/package.yaml +1 -1
- data/tracks/haskell/exercises/ocr-numbers/package.yaml +1 -1
- data/tracks/haskell/exercises/octal/package.yaml +1 -1
- data/tracks/haskell/exercises/palindrome-products/package.yaml +1 -1
- data/tracks/haskell/exercises/pangram/package.yaml +1 -1
- data/tracks/haskell/exercises/parallel-letter-frequency/package.yaml +1 -1
- data/tracks/haskell/exercises/pascals-triangle/package.yaml +1 -1
- data/tracks/haskell/exercises/perfect-numbers/package.yaml +1 -1
- data/tracks/haskell/exercises/phone-number/package.yaml +1 -1
- data/tracks/haskell/exercises/pig-latin/package.yaml +1 -1
- data/tracks/haskell/exercises/poker/package.yaml +1 -1
- data/tracks/haskell/exercises/pov/package.yaml +2 -2
- data/tracks/haskell/exercises/pov/test/Tests.hs +15 -0
- data/tracks/haskell/exercises/prime-factors/package.yaml +1 -1
- data/tracks/haskell/exercises/protein-translation/package.yaml +1 -1
- data/tracks/haskell/exercises/pythagorean-triplet/package.yaml +1 -1
- data/tracks/haskell/exercises/queen-attack/package.yaml +1 -1
- data/tracks/haskell/exercises/rail-fence-cipher/package.yaml +1 -1
- data/tracks/haskell/exercises/raindrops/package.yaml +1 -1
- data/tracks/haskell/exercises/rna-transcription/package.yaml +1 -1
- data/tracks/haskell/exercises/robot-name/package.yaml +1 -1
- data/tracks/haskell/exercises/robot-simulator/package.yaml +1 -1
- data/tracks/haskell/exercises/roman-numerals/package.yaml +1 -1
- data/tracks/haskell/exercises/rotational-cipher/package.yaml +1 -1
- data/tracks/haskell/exercises/run-length-encoding/package.yaml +1 -1
- data/tracks/haskell/exercises/saddle-points/package.yaml +1 -1
- data/tracks/haskell/exercises/say/package.yaml +1 -1
- data/tracks/haskell/exercises/scrabble-score/package.yaml +1 -1
- data/tracks/haskell/exercises/secret-handshake/package.yaml +1 -1
- data/tracks/haskell/exercises/series/package.yaml +1 -1
- data/tracks/haskell/exercises/sgf-parsing/package.yaml +1 -1
- data/tracks/haskell/exercises/sieve/package.yaml +1 -1
- data/tracks/haskell/exercises/simple-cipher/package.yaml +1 -1
- data/tracks/haskell/exercises/simple-linked-list/package.yaml +1 -1
- data/tracks/haskell/exercises/space-age/package.yaml +1 -1
- data/tracks/haskell/exercises/spiral-matrix/package.yaml +1 -1
- data/tracks/haskell/exercises/strain/package.yaml +1 -1
- data/tracks/haskell/exercises/sublist/package.yaml +1 -1
- data/tracks/haskell/exercises/sum-of-multiples/package.yaml +1 -1
- data/tracks/haskell/exercises/transpose/package.yaml +1 -1
- data/tracks/haskell/exercises/triangle/package.yaml +1 -1
- data/tracks/haskell/exercises/trinary/package.yaml +1 -1
- data/tracks/haskell/exercises/twelve-days/package.yaml +1 -1
- data/tracks/haskell/exercises/word-count/package.yaml +1 -1
- data/tracks/haskell/exercises/wordy/package.yaml +1 -1
- data/tracks/haskell/exercises/zebra-puzzle/package.yaml +1 -1
- data/tracks/haskell/exercises/zipper/package.yaml +1 -1
- data/tracks/java/CONTRIBUTING.md +39 -3
- data/tracks/java/POLICIES.md +68 -3
- data/tracks/java/exercises/crypto-square/README.md +4 -5
- data/tracks/java/exercises/error-handling/README.md +38 -0
- data/tracks/java/exercises/series/README.md +6 -6
- data/tracks/java/exercises/sieve/README.md +5 -3
- data/tracks/java/scripts/canonical_data_check.sh +1 -1
- data/tracks/python/exercises/react/example.py +54 -63
- data/tracks/python/exercises/react/react.py +10 -10
- data/tracks/python/exercises/react/react_test.py +197 -131
- data/tracks/python/exercises/sieve/README.md +5 -3
- data/tracks/rust/exercises/react/example.rs +103 -64
- data/tracks/rust/exercises/react/src/lib.rs +31 -17
- data/tracks/rust/exercises/react/tests/react.rs +52 -61
- data/tracks/swift/config.json +11 -0
- data/tracks/swift/exercises/circular-buffer/Sources/CircularBufferExample.swift +12 -12
- data/tracks/swift/exercises/circular-buffer/Tests/CircularBufferTests/CircularBufferTests.swift +1 -1
- data/tracks/swift/exercises/proverb/Package.swift +5 -0
- data/tracks/swift/exercises/proverb/README.md +25 -0
- data/tracks/swift/exercises/proverb/Sources/Proverb.swift +1 -0
- data/tracks/swift/exercises/proverb/Sources/ProverbExample.swift +28 -0
- data/tracks/swift/exercises/proverb/Tests/LinuxMain.swift +6 -0
- data/tracks/swift/exercises/proverb/Tests/ProverbTests/ProverbTests.swift +61 -0
- data/tracks/typescript/config.json +14 -0
- data/tracks/typescript/exercises/palindrome-products/README.md +65 -0
- data/tracks/typescript/exercises/palindrome-products/package.json +36 -0
- data/tracks/typescript/exercises/palindrome-products/palindrome-products.example.ts +38 -0
- data/tracks/typescript/exercises/palindrome-products/palindrome-products.test.ts +69 -0
- data/tracks/typescript/exercises/palindrome-products/palindrome-products.ts +0 -0
- data/tracks/typescript/exercises/palindrome-products/tsconfig.json +22 -0
- data/tracks/typescript/exercises/palindrome-products/tslint.json +127 -0
- data/tracks/typescript/exercises/palindrome-products/yarn.lock +2624 -0
- metadata +17 -2
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Proverb
|
|
2
|
+
|
|
3
|
+
For want of a horseshoe nail, a kingdom was lost, or so the saying goes.
|
|
4
|
+
|
|
5
|
+
Given a list of inputs, generate the relevant proverb. For example, given the list ["nail", "shoe", "horse", "rider", "message", "battle", "kingdom"], you will output the full text of this proverbial rhyme:
|
|
6
|
+
|
|
7
|
+
For want of a nail the shoe was lost.
|
|
8
|
+
For want of a shoe the horse was lost.
|
|
9
|
+
For want of a horse the rider was lost.
|
|
10
|
+
For want of a rider the message was lost.
|
|
11
|
+
For want of a message the battle was lost.
|
|
12
|
+
For want of a battle the kingdom was lost.
|
|
13
|
+
And all for the want of a nail.
|
|
14
|
+
|
|
15
|
+
Note that the list of inputs may vary; your solution should be able to handle lists of arbitrary length and content. No line of the output text should be a static, unchanging string; all should vary according to the input given.
|
|
16
|
+
|
|
17
|
+
## Setup
|
|
18
|
+
|
|
19
|
+
Go through the project setup instructions for Xcode using Swift:
|
|
20
|
+
|
|
21
|
+
http://exercism.io/languages/swift
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
## Submitting Incomplete Solutions
|
|
25
|
+
It's possible to submit an incomplete solution so you can see how others have completed the exercise.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//Solution goes in Sources
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
|
|
3
|
+
extension Array where Element == String {
|
|
4
|
+
|
|
5
|
+
func recite() -> String {
|
|
6
|
+
|
|
7
|
+
var saying = ""
|
|
8
|
+
|
|
9
|
+
if let firstPiece = self.first {
|
|
10
|
+
|
|
11
|
+
for (position, piece) in self.enumerated() {
|
|
12
|
+
|
|
13
|
+
if position != self.count - 1 {
|
|
14
|
+
|
|
15
|
+
let nextPiece = self[position + 1]
|
|
16
|
+
saying.append("For want of a \(piece) the \(nextPiece) was lost.\n")
|
|
17
|
+
} else {
|
|
18
|
+
|
|
19
|
+
saying.append("And all for the want of a \(firstPiece).")
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return saying
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import XCTest
|
|
2
|
+
@testable import Proverb
|
|
3
|
+
|
|
4
|
+
class ProverbTests: XCTestCase {
|
|
5
|
+
|
|
6
|
+
func testZeroPiecesOfProverb() {
|
|
7
|
+
|
|
8
|
+
let expectedResult = ""
|
|
9
|
+
let actualResult = [String]().recite()
|
|
10
|
+
XCTAssertEqual(expectedResult, actualResult)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
func testOnePieceOfProverb() {
|
|
14
|
+
|
|
15
|
+
let expectedResult = "And all for the want of a nail."
|
|
16
|
+
let actualResult = ["nail"].recite()
|
|
17
|
+
XCTAssertEqual(expectedResult, actualResult)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
func testTwoPiecesOfProverb() {
|
|
21
|
+
|
|
22
|
+
let expectedResult = "For want of a nail the shoe was lost.\nAnd all for the want of a nail."
|
|
23
|
+
let actualResult = ["nail", "shoe"].recite()
|
|
24
|
+
XCTAssertEqual(expectedResult, actualResult)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
func testThreePiecesOfProverb() {
|
|
28
|
+
|
|
29
|
+
let expectedResult = "For want of a nail the shoe was lost.\nFor want of a shoe the horse was lost.\nAnd all for the want of a nail."
|
|
30
|
+
let actualResult = ["nail", "shoe", "horse"].recite()
|
|
31
|
+
XCTAssertEqual(expectedResult, actualResult)
|
|
32
|
+
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
func testFullProverb() {
|
|
36
|
+
|
|
37
|
+
let expectedResult = "For want of a nail the shoe was lost.\nFor want of a shoe the horse was lost.\nFor want of a horse the rider was lost.\nFor want of a rider the message was lost.\nFor want of a message the battle was lost.\nFor want of a battle the kingdom was lost.\nAnd all for the want of a nail."
|
|
38
|
+
let actualResult = ["nail", "shoe", "horse", "rider", "message", "battle", "kingdom"].recite()
|
|
39
|
+
XCTAssertEqual(expectedResult, actualResult)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
func testFourPiecesOfProverbModernized() {
|
|
43
|
+
|
|
44
|
+
let expectedResult = "For want of a pin the gun was lost.\nFor want of a gun the soldier was lost.\nFor want of a soldier the battle was lost.\nAnd all for the want of a pin."
|
|
45
|
+
let actualResult = ["pin", "gun", "soldier", "battle"].recite()
|
|
46
|
+
XCTAssertEqual(expectedResult, actualResult)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
static var allTests: [(String, (ProverbTests) -> () throws -> Void)] {
|
|
50
|
+
return [
|
|
51
|
+
("testZeroPiecesOfProverb", testZeroPiecesOfProverb),
|
|
52
|
+
("testOnePieceOfProverb", testOnePieceOfProverb),
|
|
53
|
+
("testTwoPiecesOfProverb", testTwoPiecesOfProverb),
|
|
54
|
+
("testThreePiecesOfProverb", testThreePiecesOfProverb),
|
|
55
|
+
("testFullProverb", testFullProverb),
|
|
56
|
+
("testFourPiecesOfProverbModernized", testFourPiecesOfProverbModernized),
|
|
57
|
+
|
|
58
|
+
]
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
}
|
|
@@ -674,6 +674,20 @@
|
|
|
674
674
|
"unlocked_by": "grade-school",
|
|
675
675
|
"uuid": "69cbdc2a-50f4-4e14-b9f4-c1ddee021018"
|
|
676
676
|
},
|
|
677
|
+
{
|
|
678
|
+
"core": false,
|
|
679
|
+
"difficulty": 7,
|
|
680
|
+
"slug": "palindrome-products",
|
|
681
|
+
"topics": [
|
|
682
|
+
"algorithms",
|
|
683
|
+
"control_flow_conditionals",
|
|
684
|
+
"control_flow_loops",
|
|
685
|
+
"integers",
|
|
686
|
+
"mathematics"
|
|
687
|
+
],
|
|
688
|
+
"unlocked_by": "prime-factors",
|
|
689
|
+
"uuid": "ffb0ad36-2cf5-46d4-9a5f-5bbdfb9691a7"
|
|
690
|
+
},
|
|
677
691
|
{
|
|
678
692
|
"core": false,
|
|
679
693
|
"difficulty": 8,
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# Palindrome Products
|
|
2
|
+
|
|
3
|
+
Detect palindrome products in a given range.
|
|
4
|
+
|
|
5
|
+
A palindromic number is a number that remains the same when its digits are
|
|
6
|
+
reversed. For example, `121` is a palindromic number but `112` is not.
|
|
7
|
+
|
|
8
|
+
Given a range of numbers, find the largest and smallest palindromes which
|
|
9
|
+
are products of numbers within that range.
|
|
10
|
+
|
|
11
|
+
Your solution should return the largest and smallest palindromes, along with the
|
|
12
|
+
factors of each within the range. If the largest or smallest palindrome has more
|
|
13
|
+
than one pair of factors within the range, then return all the pairs.
|
|
14
|
+
|
|
15
|
+
## Example 1
|
|
16
|
+
|
|
17
|
+
Given the range `[1, 9]` (both inclusive)...
|
|
18
|
+
|
|
19
|
+
And given the list of all possible products within this range:
|
|
20
|
+
`[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 16, 18, 15, 21, 24, 27, 20, 28, 32, 36, 25, 30, 35, 40, 45, 42, 48, 54, 49, 56, 63, 64, 72, 81]`
|
|
21
|
+
|
|
22
|
+
The palindrome products are all single digit numbers (in this case):
|
|
23
|
+
`[1, 2, 3, 4, 5, 6, 7, 8, 9]`
|
|
24
|
+
|
|
25
|
+
The smallest palindrome product is `1`. Its factors are `(1, 1)`.
|
|
26
|
+
The largest palindrome product is `9`. Its factors are `(1, 9)` and `(3, 3)`.
|
|
27
|
+
|
|
28
|
+
## Example 2
|
|
29
|
+
|
|
30
|
+
Given the range `[10, 99]` (both inclusive)...
|
|
31
|
+
|
|
32
|
+
The smallest palindrome product is `121`. Its factors are `(11, 11)`.
|
|
33
|
+
The largest palindrome product is `9009`. Its factors are `(91, 99)`.
|
|
34
|
+
|
|
35
|
+
## Setup
|
|
36
|
+
|
|
37
|
+
Go through the setup instructions for TypeScript to
|
|
38
|
+
install the necessary dependencies:
|
|
39
|
+
|
|
40
|
+
http://exercism.io/languages/typescript
|
|
41
|
+
|
|
42
|
+
## Requirements
|
|
43
|
+
|
|
44
|
+
Install assignment dependencies:
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
$ yarn install
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Making the test suite pass
|
|
51
|
+
|
|
52
|
+
Execute the tests with:
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
$ yarn test
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
## Source
|
|
61
|
+
|
|
62
|
+
Problem 4 at Project Euler [http://projecteuler.net/problem=4](http://projecteuler.net/problem=4)
|
|
63
|
+
|
|
64
|
+
## Submitting Incomplete Solutions
|
|
65
|
+
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,38 @@
|
|
|
1
|
+
const isPalindrome = (num: number) => num.toString().split('').reverse().join('') === num.toString()
|
|
2
|
+
|
|
3
|
+
const Palindromes = (params: {maxFactor: number, minFactor?: number}) => {
|
|
4
|
+
let maxFactor,
|
|
5
|
+
minFactor,
|
|
6
|
+
maxProduct,
|
|
7
|
+
minProduct,
|
|
8
|
+
data
|
|
9
|
+
maxFactor = params.maxFactor
|
|
10
|
+
minFactor = params.minFactor || 1
|
|
11
|
+
maxProduct = 1
|
|
12
|
+
minProduct = Infinity
|
|
13
|
+
data = []
|
|
14
|
+
|
|
15
|
+
for (let ii = minFactor; ii < maxFactor; ii++) {
|
|
16
|
+
for (let jj = ii; jj <= maxFactor; jj++) {
|
|
17
|
+
const product = ii * jj
|
|
18
|
+
if (isPalindrome(product)) {
|
|
19
|
+
data[product] = [ii, jj]
|
|
20
|
+
maxProduct = Math.max(maxProduct, product)
|
|
21
|
+
minProduct = Math.min(minProduct, product)
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return {
|
|
27
|
+
largest: {
|
|
28
|
+
value: maxProduct,
|
|
29
|
+
factors: data[maxProduct],
|
|
30
|
+
},
|
|
31
|
+
smallest: {
|
|
32
|
+
value: minProduct,
|
|
33
|
+
factors: data[minProduct],
|
|
34
|
+
},
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export default Palindromes
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import generate from './palindrome-products'
|
|
2
|
+
|
|
3
|
+
describe('Palindrome', () => {
|
|
4
|
+
it('largest palindrome from single digit factors', () => {
|
|
5
|
+
const palindromes = generate({ maxFactor: 9 })
|
|
6
|
+
const largest = palindromes.largest
|
|
7
|
+
|
|
8
|
+
expect(largest.value).toEqual(9)
|
|
9
|
+
const containsMatch = [[3, 3], [1, 9]].filter((el) => numericalArraysMatch(el, [3, 3])).length > 0
|
|
10
|
+
expect(containsMatch).toBe(true)
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
xit('largest palindrome from double digit factors', () => {
|
|
14
|
+
const palindromes = generate({ maxFactor: 99, minFactor: 10 })
|
|
15
|
+
const largest = palindromes.largest
|
|
16
|
+
|
|
17
|
+
expect(largest.value).toEqual(9009)
|
|
18
|
+
expect(largest.factors).toEqual([91, 99])
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
xit('smallest palindrome from double digit factors', () => {
|
|
22
|
+
const palindromes = generate({ maxFactor: 99, minFactor: 10 })
|
|
23
|
+
const smallest = palindromes.smallest
|
|
24
|
+
|
|
25
|
+
expect(smallest.value).toEqual(121)
|
|
26
|
+
expect(smallest.factors).toEqual([11, 11])
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
xit('largest palindrome from triple digit factors', () => {
|
|
30
|
+
const palindromes = generate({ maxFactor: 999, minFactor: 100 })
|
|
31
|
+
const largest = palindromes.largest
|
|
32
|
+
|
|
33
|
+
expect(largest.value).toEqual(906609)
|
|
34
|
+
expect(largest.factors).toEqual([913, 993])
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
xit('smallest palindrome from triple digit factors', () => {
|
|
38
|
+
const palindromes = generate({ maxFactor: 999, minFactor: 100 })
|
|
39
|
+
const smallest = palindromes.smallest
|
|
40
|
+
|
|
41
|
+
expect(smallest.value).toEqual(10201)
|
|
42
|
+
expect(smallest.factors).toEqual([101, 101])
|
|
43
|
+
})
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
function numericalArraysMatch(a: number[], b: number[]) {
|
|
47
|
+
if (a.length !== b.length) {
|
|
48
|
+
return false
|
|
49
|
+
}
|
|
50
|
+
const one = [...a].sort(numericalSort)
|
|
51
|
+
const two = [...b].sort(numericalSort)
|
|
52
|
+
let result = true
|
|
53
|
+
let index = 0
|
|
54
|
+
while (index < one.length) {
|
|
55
|
+
result = result && one[index] === two[index]
|
|
56
|
+
index++
|
|
57
|
+
}
|
|
58
|
+
return result
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function numericalSort(x: number, y: number) {
|
|
62
|
+
if (x < y) {
|
|
63
|
+
return -1
|
|
64
|
+
}
|
|
65
|
+
if (x > y) {
|
|
66
|
+
return 1
|
|
67
|
+
}
|
|
68
|
+
return 0
|
|
69
|
+
}
|
|
File without changes
|
|
@@ -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
|
+
}
|