trackler 2.0.8.49 → 2.0.8.50
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/tracks/elixir/.github/stale.yml +0 -0
- data/tracks/java/.github/stale.yml +8 -0
- data/tracks/java/exercises/book-store/src/example/java/Bookstore.java +36 -40
- data/tracks/java/exercises/book-store/src/test/java/BookstoreTest.java +108 -107
- data/tracks/java/exercises/palindrome-products/src/example/java/{Palindromes.java → PalindromeCalculator.java} +4 -4
- data/tracks/java/exercises/palindrome-products/src/test/java/{PalindromesTest.java → PalindromeCalculatorTest.java} +13 -6
- data/tracks/java/scripts/prune-extra-keep-files.sh +12 -0
- metadata +7 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2b20ae176f6c856990f4e8c19aba7f9a57413eb0
|
4
|
+
data.tar.gz: 9caaf6ade8db9ed4f780f70fe1f00bd7d3db67fd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 72764fd62759d31ac5d878b4018ffb622f498301c619a63a7d8969bbc01508197639bc5c2e9ee7f09118b8d254f63ad777109a7f8094f4f8c5a421c6b2ba2862
|
7
|
+
data.tar.gz: ea4f65efe06b9679130b05197cd1e0f32c09c4f764b487693321ce9d9a999a4ea461c22d3d18cd90b88186761adcd53f0c0c77836e1aa2564ef674b7c08e8650
|
data/lib/trackler/version.rb
CHANGED
File without changes
|
@@ -1,61 +1,57 @@
|
|
1
|
-
import java.awt.print.Printable;
|
2
1
|
import java.util.ArrayList;
|
3
|
-
import java.util.Arrays;
|
4
2
|
import java.util.List;
|
5
3
|
import java.util.stream.Collectors;
|
6
4
|
|
7
|
-
|
5
|
+
class Bookstore {
|
8
6
|
|
9
|
-
|
10
|
-
private List<Integer> books;
|
11
|
-
private static double[] DISCOUNT_TIERS = {0,5,10,20,25};
|
7
|
+
private static final int BOOK_PRICE = 8, MAX_GROUP_SIZE = 5;
|
12
8
|
|
13
|
-
|
14
|
-
this.books = books;
|
15
|
-
}
|
16
|
-
|
9
|
+
private static double[] DISCOUNT_TIERS = {0, 5, 10, 20, 25};
|
17
10
|
|
11
|
+
private List<Integer> books;
|
18
12
|
|
13
|
+
Bookstore(List<Integer> books) {
|
14
|
+
this.books = books;
|
15
|
+
}
|
19
16
|
|
20
|
-
|
21
|
-
|
22
|
-
|
17
|
+
double calculateTotalCost() {
|
18
|
+
return calculateTotalCost(this.books, 0);
|
19
|
+
}
|
23
20
|
|
24
|
-
|
25
|
-
|
21
|
+
private double calculateTotalCost(List<Integer> books, double priceSoFar) {
|
22
|
+
if (books.size() == 0) {
|
23
|
+
return priceSoFar;
|
24
|
+
}
|
26
25
|
|
26
|
+
List<Integer> availableBookNumbers = books.stream()
|
27
|
+
.distinct()
|
28
|
+
.collect(Collectors.toList());
|
27
29
|
|
28
|
-
|
29
|
-
return priceSoFar;
|
30
|
-
}
|
30
|
+
double minPrice = Double.MAX_VALUE;
|
31
31
|
|
32
|
-
|
32
|
+
for (int i = 0; i < availableBookNumbers.size(); i++) {
|
33
|
+
List<Integer> newGroupBooks = new ArrayList<>(availableBookNumbers.subList(0, i + 1));
|
34
|
+
List<Integer> remainingBooks = new ArrayList<>(books);
|
33
35
|
|
34
|
-
|
35
|
-
|
36
|
+
for (final Integer newGroupBook : newGroupBooks) {
|
37
|
+
//noinspection UseBulkOperation - we want to remove _one_ of each book number, not _all_ of each book number.
|
38
|
+
remainingBooks.remove(newGroupBook);
|
39
|
+
}
|
36
40
|
|
37
|
-
|
38
|
-
books.remove(groups.get(i));
|
39
|
-
}
|
40
|
-
|
41
|
-
try {
|
42
|
-
price = calculateTotalCost(books,priceSoFar + costPerGroup(groups.size()));
|
43
|
-
} catch (Exception e) {
|
44
|
-
e.printStackTrace();
|
45
|
-
}
|
46
|
-
|
47
|
-
minPrice = Math.min(minPrice, price);
|
48
|
-
return minPrice;
|
41
|
+
double price = calculateTotalCost(remainingBooks, priceSoFar + costOfGroupSize(newGroupBooks.size()));
|
49
42
|
|
43
|
+
minPrice = Math.min(minPrice, price);
|
44
|
+
}
|
50
45
|
|
51
|
-
|
46
|
+
return minPrice;
|
47
|
+
}
|
52
48
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
return BOOK_PRICE * groupSize * (100 - DISCOUNT_TIERS[groupSize-1])/100;
|
58
|
-
}
|
49
|
+
private double costOfGroupSize(int groupSize) {
|
50
|
+
if (groupSize < 1 || groupSize > MAX_GROUP_SIZE) {
|
51
|
+
throw new IllegalStateException("Invalid group size : " + groupSize);
|
52
|
+
}
|
59
53
|
|
54
|
+
return BOOK_PRICE * groupSize * (100 - DISCOUNT_TIERS[groupSize - 1]) / 100;
|
55
|
+
}
|
60
56
|
|
61
57
|
}
|
@@ -1,5 +1,6 @@
|
|
1
1
|
import static org.junit.Assert.assertEquals;
|
2
2
|
|
3
|
+
import java.util.Collections;
|
3
4
|
import java.util.List;
|
4
5
|
import java.util.ArrayList;
|
5
6
|
import java.util.Arrays;
|
@@ -7,112 +8,112 @@ import java.util.Arrays;
|
|
7
8
|
import org.junit.Ignore;
|
8
9
|
import org.junit.Test;
|
9
10
|
|
10
|
-
public class BookstoreTest{
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
11
|
+
public class BookstoreTest {
|
12
|
+
|
13
|
+
// This is sufficient accuracy since we're handling currency values, which should be equal to within 2 decimal places.
|
14
|
+
private static final double EQUALITY_TOLERANCE = 0.001;
|
15
|
+
|
16
|
+
@Test
|
17
|
+
public void onlyASingleBook() {
|
18
|
+
List<Integer> books = new ArrayList<>(Collections.singletonList(1));
|
19
|
+
Bookstore bookstore = new Bookstore(books);
|
20
|
+
assertEquals(8, bookstore.calculateTotalCost(), EQUALITY_TOLERANCE);
|
21
|
+
}
|
22
|
+
|
23
|
+
@Ignore
|
24
|
+
@Test
|
25
|
+
public void twoOfSameBook() {
|
26
|
+
List<Integer> books = new ArrayList<>(Arrays.asList(1, 1));
|
27
|
+
Bookstore bookstore = new Bookstore(books);
|
28
|
+
assertEquals(16, bookstore.calculateTotalCost(), EQUALITY_TOLERANCE);
|
29
|
+
}
|
30
|
+
|
31
|
+
@Ignore
|
32
|
+
@Test
|
33
|
+
public void emptyBasket() {
|
34
|
+
List<Integer> books = new ArrayList<>();
|
35
|
+
Bookstore bookstore = new Bookstore(books);
|
36
|
+
assertEquals(0, bookstore.calculateTotalCost(), EQUALITY_TOLERANCE);
|
37
|
+
}
|
38
|
+
|
39
|
+
@Ignore
|
40
|
+
@Test
|
41
|
+
public void twoDifferentBooks() {
|
42
|
+
List<Integer> books = new ArrayList<>(Arrays.asList(1, 2));
|
43
|
+
Bookstore bookstore = new Bookstore(books);
|
44
|
+
assertEquals(15.20, bookstore.calculateTotalCost(), EQUALITY_TOLERANCE);
|
45
|
+
}
|
46
|
+
|
47
|
+
@Ignore
|
48
|
+
@Test
|
49
|
+
public void threeDifferentBooks() {
|
50
|
+
List<Integer> books = new ArrayList<>(Arrays.asList(1, 2, 3));
|
51
|
+
Bookstore bookstore = new Bookstore(books);
|
52
|
+
assertEquals(21.6, bookstore.calculateTotalCost(), EQUALITY_TOLERANCE);
|
53
|
+
}
|
54
|
+
|
55
|
+
@Ignore
|
56
|
+
@Test
|
57
|
+
public void fourDifferentBooks() {
|
58
|
+
List<Integer> books = new ArrayList<>(Arrays.asList(1, 2, 3, 4));
|
59
|
+
Bookstore bookstore = new Bookstore(books);
|
60
|
+
assertEquals(25.6, bookstore.calculateTotalCost(), EQUALITY_TOLERANCE);
|
61
|
+
}
|
62
|
+
|
63
|
+
@Ignore
|
64
|
+
@Test
|
65
|
+
public void fiveDifferentBooks() {
|
66
|
+
List<Integer> books = new ArrayList<>(Arrays.asList(1, 2, 3, 4, 5));
|
67
|
+
Bookstore bookstore = new Bookstore(books);
|
68
|
+
assertEquals(30, bookstore.calculateTotalCost(), EQUALITY_TOLERANCE);
|
69
|
+
}
|
70
|
+
|
71
|
+
@Ignore
|
72
|
+
@Test
|
73
|
+
public void twoGroupsOfFourIsCheaperThanGroupOfFivePlusGroupOfThree() {
|
74
|
+
List<Integer> books = new ArrayList<>(Arrays.asList(1, 1, 2, 2, 3, 3, 4, 5));
|
75
|
+
Bookstore bookstore = new Bookstore(books);
|
76
|
+
assertEquals(51.20, bookstore.calculateTotalCost(), EQUALITY_TOLERANCE);
|
77
|
+
}
|
78
|
+
|
79
|
+
@Ignore
|
80
|
+
@Test
|
81
|
+
public void groupOfFourPlusGroupOfTwoIsCheaperThanTwoGroupsOfThree() {
|
82
|
+
List<Integer> books = new ArrayList<>(Arrays.asList(1, 1, 2, 2, 3, 4));
|
83
|
+
Bookstore bookstore = new Bookstore(books);
|
84
|
+
assertEquals(40.8, bookstore.calculateTotalCost(), EQUALITY_TOLERANCE);
|
85
|
+
}
|
86
|
+
|
87
|
+
@Ignore
|
88
|
+
@Test
|
89
|
+
public void twoEachOfFirst4BooksAnd1CopyEachOfRest() {
|
90
|
+
List<Integer> books = new ArrayList<>(Arrays.asList(1, 1, 2, 2, 3, 3, 4, 4, 5));
|
91
|
+
Bookstore bookstore = new Bookstore(books);
|
92
|
+
assertEquals(55.60, bookstore.calculateTotalCost(), EQUALITY_TOLERANCE);
|
93
|
+
}
|
94
|
+
|
95
|
+
@Ignore
|
96
|
+
@Test
|
97
|
+
public void twoCopiesOfEachBook() {
|
98
|
+
List<Integer> books = new ArrayList<>(Arrays.asList(1, 1, 2, 2, 3, 3, 4, 4, 5, 5));
|
99
|
+
Bookstore bookstore = new Bookstore(books);
|
100
|
+
assertEquals(60.00, bookstore.calculateTotalCost(), EQUALITY_TOLERANCE);
|
101
|
+
}
|
102
|
+
|
103
|
+
@Ignore
|
104
|
+
@Test
|
105
|
+
public void threeCopiesOfFirstBookAnd2EachOfRemaining() {
|
106
|
+
List<Integer> books = new ArrayList<>(Arrays.asList(1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 1));
|
107
|
+
Bookstore bookstore = new Bookstore(books);
|
108
|
+
assertEquals(68.00, bookstore.calculateTotalCost(), EQUALITY_TOLERANCE);
|
109
|
+
}
|
110
|
+
|
111
|
+
@Ignore
|
112
|
+
@Test
|
113
|
+
public void threeEachOFirst2BooksAnd2EachOfRemainingBooks() {
|
114
|
+
List<Integer> books = new ArrayList<>(Arrays.asList(1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 1, 2));
|
115
|
+
Bookstore bookstore = new Bookstore(books);
|
116
|
+
assertEquals(75.20, bookstore.calculateTotalCost(), EQUALITY_TOLERANCE);
|
117
|
+
}
|
116
118
|
|
117
119
|
}
|
118
|
-
|
@@ -1,8 +1,8 @@
|
|
1
1
|
import java.util.*;
|
2
2
|
|
3
|
-
public class
|
3
|
+
public class PalindromeCalculator {
|
4
4
|
|
5
|
-
public
|
5
|
+
public SortedMap<Long, List<List<Integer>>> getPalindromeProductsWithFactors(int minFactor, int maxFactor) {
|
6
6
|
SortedMap<Long, List<List<Integer>>> palindromeSortedList = new TreeMap<>();
|
7
7
|
long num;
|
8
8
|
List<List<Integer>> factors;
|
@@ -23,7 +23,7 @@ public class Palindromes {
|
|
23
23
|
}
|
24
24
|
|
25
25
|
// http://stackoverflow.com/questions/23984654/how-to-print-all-palindromes-upto-1000-without-using-any-string-stringbuilder
|
26
|
-
private
|
26
|
+
private long reverseNumber(long number) {
|
27
27
|
if (number < 10l) {
|
28
28
|
return number;
|
29
29
|
}
|
@@ -37,7 +37,7 @@ public class Palindromes {
|
|
37
37
|
return result;
|
38
38
|
}
|
39
39
|
|
40
|
-
private
|
40
|
+
private boolean isPalindrome(long number) {
|
41
41
|
return number == reverseNumber(number);
|
42
42
|
}
|
43
43
|
}
|
@@ -1,3 +1,4 @@
|
|
1
|
+
import org.junit.Before;
|
1
2
|
import org.junit.Ignore;
|
2
3
|
import org.junit.Test;
|
3
4
|
|
@@ -9,7 +10,13 @@ import java.util.stream.Collectors;
|
|
9
10
|
|
10
11
|
import static junit.framework.TestCase.*;
|
11
12
|
|
12
|
-
public class
|
13
|
+
public class PalindromeCalculatorTest {
|
14
|
+
private PalindromeCalculator palindromeCalculator;
|
15
|
+
|
16
|
+
@Before
|
17
|
+
public void setup() {
|
18
|
+
palindromeCalculator = new PalindromeCalculator();
|
19
|
+
}
|
13
20
|
|
14
21
|
@Test
|
15
22
|
public void largestPalindromeFromSingleDigitFactors() {
|
@@ -21,7 +28,7 @@ public class PalindromesTest {
|
|
21
28
|
);
|
22
29
|
final long expectedValue = 9l;
|
23
30
|
|
24
|
-
final SortedMap<Long, List<List<Integer>>> palindromes =
|
31
|
+
final SortedMap<Long, List<List<Integer>>> palindromes = palindromeCalculator.getPalindromeProductsWithFactors(1, 9);
|
25
32
|
|
26
33
|
checkPalindromeWithFactorsMatchesExpected(expected, expectedValue, palindromes, palindromes.lastKey());
|
27
34
|
}
|
@@ -36,7 +43,7 @@ public class PalindromesTest {
|
|
36
43
|
);
|
37
44
|
final long expectedValue = 9009l;
|
38
45
|
|
39
|
-
final SortedMap<Long, List<List<Integer>>> palindromes =
|
46
|
+
final SortedMap<Long, List<List<Integer>>> palindromes = palindromeCalculator.getPalindromeProductsWithFactors(10, 99);
|
40
47
|
|
41
48
|
checkPalindromeWithFactorsMatchesExpected(expected, expectedValue, palindromes, palindromes.lastKey());
|
42
49
|
}
|
@@ -51,7 +58,7 @@ public class PalindromesTest {
|
|
51
58
|
);
|
52
59
|
final long expectedValue = 121l;
|
53
60
|
|
54
|
-
final SortedMap<Long, List<List<Integer>>> palindromes =
|
61
|
+
final SortedMap<Long, List<List<Integer>>> palindromes = palindromeCalculator.getPalindromeProductsWithFactors(10, 99);
|
55
62
|
|
56
63
|
checkPalindromeWithFactorsMatchesExpected(expected, expectedValue, palindromes, palindromes.firstKey());
|
57
64
|
}
|
@@ -66,7 +73,7 @@ public class PalindromesTest {
|
|
66
73
|
);
|
67
74
|
final long expectedValue = 906609l;
|
68
75
|
|
69
|
-
final SortedMap<Long, List<List<Integer>>> palindromes =
|
76
|
+
final SortedMap<Long, List<List<Integer>>> palindromes = palindromeCalculator.getPalindromeProductsWithFactors(100, 999);
|
70
77
|
|
71
78
|
checkPalindromeWithFactorsMatchesExpected(expected, expectedValue, palindromes, palindromes.lastKey());
|
72
79
|
}
|
@@ -81,7 +88,7 @@ public class PalindromesTest {
|
|
81
88
|
);
|
82
89
|
final long expectedValue = 10201l;
|
83
90
|
|
84
|
-
final SortedMap<Long, List<List<Integer>>> palindromes =
|
91
|
+
final SortedMap<Long, List<List<Integer>>> palindromes = palindromeCalculator.getPalindromeProductsWithFactors(100, 999);
|
85
92
|
|
86
93
|
checkPalindromeWithFactorsMatchesExpected(expected, expectedValue, palindromes, palindromes.firstKey());
|
87
94
|
}
|
@@ -0,0 +1,12 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
|
3
|
+
for EXERCISE_DIRECTORY in $(find exercises -mindepth 2 -maxdepth 2 -type d -name "src"); do
|
4
|
+
STARTER_DIRECTORY="${EXERCISE_DIRECTORY}/main/java"
|
5
|
+
STARTER_FILE_COUNT=$(find "${STARTER_DIRECTORY}" -mindepth 1 -maxdepth 1 -type f -name "*.java" | wc -l)
|
6
|
+
KEEP_FILE_LOCATION="${STARTER_DIRECTORY}/.keep"
|
7
|
+
|
8
|
+
if (( ${STARTER_FILE_COUNT} > 0 )) && [[ -f "${KEEP_FILE_LOCATION}" ]]; then
|
9
|
+
echo "Removing unnecessary keep file ${KEEP_FILE_LOCATION}..."
|
10
|
+
rm "${KEEP_FILE_LOCATION}"
|
11
|
+
fi
|
12
|
+
done
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: trackler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.8.
|
4
|
+
version: 2.0.8.50
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Katrina Owen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-04-
|
11
|
+
date: 2017-04-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubyzip
|
@@ -2433,6 +2433,7 @@ files:
|
|
2433
2433
|
- tracks/elisp/exercises/word-count/word-count.el
|
2434
2434
|
- tracks/elisp/img/icon.png
|
2435
2435
|
- tracks/elixir/.git
|
2436
|
+
- tracks/elixir/.github/stale.yml
|
2436
2437
|
- tracks/elixir/.gitignore
|
2437
2438
|
- tracks/elixir/.travis.yml
|
2438
2439
|
- tracks/elixir/LICENSE
|
@@ -4275,6 +4276,7 @@ files:
|
|
4275
4276
|
- tracks/idris/img/icon.png
|
4276
4277
|
- tracks/java/.Rhistory
|
4277
4278
|
- tracks/java/.git
|
4279
|
+
- tracks/java/.github/stale.yml
|
4278
4280
|
- tracks/java/.gitignore
|
4279
4281
|
- tracks/java/.keep
|
4280
4282
|
- tracks/java/.travis.yml
|
@@ -4463,9 +4465,9 @@ files:
|
|
4463
4465
|
- tracks/java/exercises/octal/src/main/java/.keep
|
4464
4466
|
- tracks/java/exercises/octal/src/test/java/OctalTest.java
|
4465
4467
|
- tracks/java/exercises/palindrome-products/build.gradle
|
4466
|
-
- tracks/java/exercises/palindrome-products/src/example/java/
|
4468
|
+
- tracks/java/exercises/palindrome-products/src/example/java/PalindromeCalculator.java
|
4467
4469
|
- tracks/java/exercises/palindrome-products/src/main/java/.keep
|
4468
|
-
- tracks/java/exercises/palindrome-products/src/test/java/
|
4470
|
+
- tracks/java/exercises/palindrome-products/src/test/java/PalindromeCalculatorTest.java
|
4469
4471
|
- tracks/java/exercises/pangram/build.gradle
|
4470
4472
|
- tracks/java/exercises/pangram/src/example/java/PangramChecker.java
|
4471
4473
|
- tracks/java/exercises/pangram/src/main/java/PangramChecker.java
|
@@ -4604,6 +4606,7 @@ files:
|
|
4604
4606
|
- tracks/java/img/icon.png
|
4605
4607
|
- tracks/java/scripts/increase-test-logging.sh
|
4606
4608
|
- tracks/java/scripts/insert-ignores.sh
|
4609
|
+
- tracks/java/scripts/prune-extra-keep-files.sh
|
4607
4610
|
- tracks/javascript/.editorconfig
|
4608
4611
|
- tracks/javascript/.git
|
4609
4612
|
- tracks/javascript/.gitignore
|