trackler 2.2.1.62 → 2.2.1.63
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/exercises/all-your-base/canonical-data.json +20 -29
- data/problem-specifications/exercises/forth/canonical-data.json +52 -5
- data/problem-specifications/exercises/isbn-verifier/canonical-data.json +15 -15
- data/problem-specifications/exercises/protein-translation/canonical-data.json +153 -0
- data/problem-specifications/exercises/reverse-string/canonical-data.json +39 -0
- data/problem-specifications/exercises/reverse-string/description.md +5 -0
- data/problem-specifications/exercises/reverse-string/metadata.yml +5 -0
- data/tracks/c/config.json +42 -41
- data/tracks/csharp/config.json +13 -0
- data/tracks/csharp/exercises/Exercises.sln +6 -0
- data/tracks/csharp/exercises/isbn-verifier/Example.cs +27 -0
- data/tracks/csharp/exercises/isbn-verifier/IsbnVerifier.cs +9 -0
- data/tracks/csharp/exercises/isbn-verifier/IsbnVerifier.csproj +19 -0
- data/tracks/csharp/exercises/isbn-verifier/IsbnVerifierTest.cs +84 -0
- data/tracks/csharp/exercises/isbn-verifier/README.md +40 -0
- data/tracks/csharp/generators/Exercises/IsbnVerifier.cs +15 -0
- data/tracks/delphi/config.json +28 -28
- data/tracks/erlang/config.json +10 -0
- data/tracks/erlang/exercises/accumulate/rebar.config +1 -1
- data/tracks/erlang/exercises/accumulate/test/accumulate_tests.erl +9 -7
- data/tracks/erlang/exercises/all-your-base/rebar.config +1 -1
- data/tracks/erlang/exercises/all-your-base/test/all_your_base_tests.erl +26 -24
- data/tracks/erlang/exercises/allergies/rebar.config +1 -1
- data/tracks/erlang/exercises/allergies/test/allergies_tests.erl +19 -17
- data/tracks/erlang/exercises/anagram/rebar.config +1 -3
- data/tracks/erlang/exercises/anagram/test/anagram_tests.erl +14 -12
- data/tracks/erlang/exercises/atbash-cipher/rebar.config +1 -1
- data/tracks/erlang/exercises/atbash-cipher/test/atbash_cipher_tests.erl +7 -5
- data/tracks/erlang/exercises/bank-account/rebar.config +1 -1
- data/tracks/erlang/exercises/bank-account/test/bank_account_tests.erl +52 -51
- data/tracks/erlang/exercises/beer-song/rebar.config +30 -0
- data/tracks/erlang/exercises/beer-song/test/beer_song_tests.erl +11 -10
- data/tracks/erlang/exercises/bob/rebar.config +1 -1
- data/tracks/erlang/exercises/bob/test/bob_tests.erl +33 -35
- data/tracks/erlang/exercises/circular-buffer/rebar.config +1 -1
- data/tracks/erlang/exercises/circular-buffer/test/circular_buffer_tests.erl +33 -32
- data/tracks/erlang/exercises/clock/rebar.config +1 -1
- data/tracks/erlang/exercises/clock/test/clock_tests.erl +57 -50
- data/tracks/erlang/exercises/collatz-conjecture/rebar.config +1 -1
- data/tracks/erlang/exercises/collatz-conjecture/test/collatz_conjecture_tests.erl +11 -9
- data/tracks/erlang/exercises/complex-numbers/rebar.config +1 -1
- data/tracks/erlang/exercises/complex-numbers/test/complex_numbers_tests.erl +102 -76
- data/tracks/erlang/exercises/custom-set/rebar.config +1 -1
- data/tracks/erlang/exercises/custom-set/test/custom_set_tests.erl +100 -109
- data/tracks/erlang/exercises/difference-of-squares/rebar.config +1 -1
- data/tracks/erlang/exercises/difference-of-squares/test/difference_of_squares_tests.erl +8 -7
- data/tracks/erlang/exercises/etl/rebar.config +1 -1
- data/tracks/erlang/exercises/etl/test/etl_tests.erl +6 -5
- data/tracks/erlang/exercises/gigasecond/rebar.config +1 -1
- data/tracks/erlang/exercises/gigasecond/test/gigasecond_tests.erl +9 -8
- data/tracks/erlang/exercises/grade-school/rebar.config +1 -1
- data/tracks/erlang/exercises/grade-school/test/grade_school_tests.erl +27 -23
- data/tracks/erlang/exercises/grains/rebar.config +1 -1
- data/tracks/erlang/exercises/grains/test/grains_tests.erl +7 -6
- data/tracks/erlang/exercises/hamming/rebar.config +1 -1
- data/tracks/erlang/exercises/hamming/test/hamming_tests.erl +20 -23
- data/tracks/erlang/exercises/hello-world/rebar.config +1 -1
- data/tracks/erlang/exercises/hello-world/test/hello_world_tests.erl +6 -4
- data/tracks/erlang/exercises/isogram/rebar.config +1 -1
- data/tracks/erlang/exercises/isogram/test/isogram_tests.erl +14 -12
- data/tracks/erlang/exercises/largest-series-product/rebar.config +1 -1
- data/tracks/erlang/exercises/largest-series-product/test/largest_series_product_tests.erl +22 -21
- data/tracks/erlang/exercises/leap/rebar.config +1 -1
- data/tracks/erlang/exercises/leap/test/leap_tests.erl +8 -7
- data/tracks/erlang/exercises/luhn/rebar.config +1 -1
- data/tracks/erlang/exercises/luhn/test/luhn_tests.erl +18 -16
- data/tracks/erlang/exercises/meetup/rebar.config +1 -1
- data/tracks/erlang/exercises/meetup/test/meetup_tests.erl +96 -95
- data/tracks/erlang/exercises/nucleotide-count/rebar.config +1 -1
- data/tracks/erlang/exercises/nucleotide-count/test/nucleotide_count_tests.erl +12 -11
- data/tracks/erlang/exercises/pangram/README.md +60 -0
- data/tracks/erlang/exercises/{accumulate → pangram}/include/exercism.hrl +0 -0
- data/tracks/erlang/exercises/{beer-song/rebar.conf → pangram/rebar.config} +0 -0
- data/tracks/erlang/exercises/pangram/src/example.erl +11 -0
- data/tracks/erlang/exercises/pangram/src/pangram.app.src +9 -0
- data/tracks/erlang/exercises/pangram/src/pangram.erl +8 -0
- data/tracks/erlang/exercises/pangram/test/pangram_tests.erl +38 -0
- data/tracks/erlang/exercises/parallel-letter-frequency/rebar.config +1 -1
- data/tracks/erlang/exercises/parallel-letter-frequency/test/parallel_letter_frequency_tests.erl +7 -6
- data/tracks/erlang/exercises/phone-number/rebar.config +1 -1
- data/tracks/erlang/exercises/phone-number/test/phone_number_tests.erl +13 -12
- data/tracks/erlang/exercises/rna-transcription/rebar.config +1 -1
- data/tracks/erlang/exercises/rna-transcription/test/rna_transcription_tests.erl +13 -11
- data/tracks/erlang/exercises/robot-simulator/rebar.config +1 -1
- data/tracks/erlang/exercises/robot-simulator/test/robot_simulator_tests.erl +70 -69
- data/tracks/erlang/exercises/roman-numerals/rebar.config +1 -1
- data/tracks/erlang/exercises/roman-numerals/test/roman_numerals_tests.erl +6 -5
- data/tracks/erlang/exercises/rotational-cipher/rebar.config +1 -8
- data/tracks/erlang/exercises/rotational-cipher/test/rotational_cipher_tests.erl +29 -27
- data/tracks/erlang/exercises/scrabble-score/rebar.config +1 -1
- data/tracks/erlang/exercises/scrabble-score/test/scrabble_score_tests.erl +6 -5
- data/tracks/erlang/exercises/series/rebar.config +1 -1
- data/tracks/erlang/exercises/series/test/series_tests.erl +6 -5
- data/tracks/erlang/exercises/sieve/rebar.config +1 -1
- data/tracks/erlang/exercises/sieve/test/sieve_tests.erl +10 -8
- data/tracks/erlang/exercises/space-age/rebar.config +1 -1
- data/tracks/erlang/exercises/space-age/test/space_age_tests.erl +20 -19
- data/tracks/erlang/exercises/spiral-matrix/rebar.config +1 -1
- data/tracks/erlang/exercises/spiral-matrix/test/spiral_matrix_tests.erl +12 -10
- data/tracks/erlang/exercises/strain/rebar.config +1 -1
- data/tracks/erlang/exercises/strain/test/strain_tests.erl +17 -16
- data/tracks/erlang/exercises/sum-of-multiples/rebar.config +1 -1
- data/tracks/erlang/exercises/sum-of-multiples/test/sum_of_multiples_tests.erl +16 -15
- data/tracks/erlang/exercises/triangle/rebar.config +1 -1
- data/tracks/erlang/exercises/triangle/test/triangle_tests.erl +20 -19
- data/tracks/erlang/exercises/two-fer/rebar.config +1 -1
- data/tracks/erlang/exercises/two-fer/test/two_fer_tests.erl +8 -7
- data/tracks/erlang/exercises/word-count/rebar.config +1 -1
- data/tracks/erlang/exercises/word-count/test/word_count_tests.erl +6 -5
- data/tracks/erlang/exercises/zipper/rebar.config +1 -1
- data/tracks/erlang/exercises/zipper/test/zipper_tests.erl +47 -46
- data/tracks/erlang/testgen/src/tgen.erl +8 -6
- data/tracks/erlang/testgen/src/tgen_bob.erl +1 -1
- data/tracks/erlang/testgen/src/tgen_collatz-conjecture.erl +2 -2
- data/tracks/erlang/testgen/src/tgen_complex-numbers.erl +11 -11
- data/tracks/erlang/testgen/src/tgen_custom-set.erl +14 -14
- data/tracks/erlang/testgen/src/tgen_hamming.erl +2 -2
- data/tracks/erlang/testgen/src/tgen_hello-world.erl +1 -1
- data/tracks/erlang/testgen/src/tgen_leap.erl +1 -1
- data/tracks/erlang/testgen/src/tgen_rna-transcription.erl +2 -2
- data/tracks/erlang/testgen/src/tgs.erl +6 -0
- data/tracks/fsharp/exercises/beer-song/BeerSong.fs +1 -5
- data/tracks/fsharp/exercises/beer-song/BeerSongTest.fs +342 -20
- data/tracks/fsharp/exercises/beer-song/Example.fs +16 -10
- data/tracks/fsharp/exercises/food-chain/Example.fs +1 -1
- data/tracks/fsharp/exercises/food-chain/FoodChain.fs +1 -3
- data/tracks/fsharp/exercises/food-chain/FoodChainTest.fs +11 -11
- data/tracks/fsharp/exercises/house/Example.fs +1 -1
- data/tracks/fsharp/exercises/house/House.fs +1 -3
- data/tracks/fsharp/exercises/house/HouseTest.fs +202 -202
- data/tracks/fsharp/exercises/proverb/Example.fs +9 -9
- data/tracks/fsharp/exercises/proverb/Proverb.fs +1 -3
- data/tracks/fsharp/exercises/proverb/ProverbTest.fs +50 -21
- data/tracks/fsharp/exercises/twelve-days/Example.fs +4 -4
- data/tracks/fsharp/exercises/twelve-days/TwelveDays.fs +2 -6
- data/tracks/fsharp/exercises/twelve-days/TwelveDaysTest.fs +81 -57
- data/tracks/fsharp/generators/Generators.fs +39 -15
- data/tracks/go/bin/run-generators +5 -1
- data/tracks/go/config.json +14 -2
- data/tracks/go/exercises/accumulate/example.go +2 -1
- data/tracks/go/exercises/zebra-puzzle/.meta/hints.md +24 -0
- data/tracks/go/exercises/zebra-puzzle/README.md +76 -0
- data/tracks/go/exercises/zebra-puzzle/example.go +256 -0
- data/tracks/go/exercises/zebra-puzzle/zebra_puzzle_test.go +18 -0
- data/tracks/haskell/exercises/forth/package.yaml +1 -1
- data/tracks/haskell/exercises/forth/test/Tests.hs +1 -4
- data/tracks/haskell/exercises/pascals-triangle/package.yaml +1 -1
- data/tracks/haskell/exercises/pascals-triangle/test/Tests.hs +22 -1
- data/tracks/java/POLICIES.md +3 -3
- data/tracks/java/config.json +21 -2
- data/tracks/java/exercises/atbash-cipher/.meta/src/reference/java/Atbash.java +12 -12
- data/tracks/java/exercises/protein-translation/.meta/src/reference/java/ProteinTranslator.java +47 -0
- data/tracks/java/exercises/protein-translation/.meta/version +1 -0
- data/tracks/java/exercises/protein-translation/README.md +58 -0
- data/tracks/java/exercises/protein-translation/build.gradle +18 -0
- data/tracks/java/exercises/protein-translation/src/main/java/ProteinTranslator.java +8 -0
- data/tracks/java/exercises/protein-translation/src/test/java/ProteinTranslatorTest.java +179 -0
- data/tracks/java/exercises/settings.gradle +1 -0
- data/tracks/javascript/.eslintignore +2 -2
- data/tracks/javascript/exercises/accumulate/example.js +1 -2
- data/tracks/javascript/exercises/grains/example.js +6 -3
- data/tracks/kotlin/exercises/beer-song/.meta/src/reference/kotlin/BeerSong.kt +3 -3
- data/tracks/kotlin/exercises/beer-song/.meta/version +1 -1
- data/tracks/kotlin/exercises/beer-song/README.md +1 -1
- data/tracks/kotlin/exercises/beer-song/src/test/kotlin/BeerSongTest.kt +6 -6
- data/tracks/kotlin/exercises/forth/.meta/version +1 -1
- data/tracks/kotlin/exercises/forth/src/test/kotlin/ForthEvaluatorTest.kt +0 -7
- data/tracks/kotlin/exercises/meetup/README.md +16 -12
- data/tracks/kotlin/exercises/nth-prime/.meta/src/reference/kotlin/Prime.kt +7 -2
- data/tracks/kotlin/exercises/nth-prime/.meta/version +1 -1
- data/tracks/kotlin/exercises/nth-prime/src/test/kotlin/PrimeTest.kt +10 -1
- data/tracks/kotlin/exercises/nucleotide-count/README.md +2 -2
- data/tracks/kotlin/exercises/pascals-triangle/.meta/src/reference/kotlin/PascalsTriangle.kt +1 -1
- data/tracks/kotlin/exercises/pascals-triangle/.meta/version +1 -1
- data/tracks/kotlin/exercises/pascals-triangle/src/test/kotlin/PascalsTriangleTest.kt +58 -1
- data/tracks/kotlin/exercises/sum-of-multiples/README.md +3 -3
- data/tracks/ocaml/exercises/forth/test.ml +1 -3
- data/tracks/ocaml/exercises/rectangles/example.ml +11 -11
- data/tracks/php/exercises/bob/example.php +2 -2
- data/tracks/purescript/config.json +3 -3
- data/tracks/python/config.json +34 -22
- data/tracks/python/exercises/alphametics/example.py +90 -34
- data/tracks/python/exercises/ocr-numbers/example.py +18 -21
- data/tracks/python/exercises/ocr-numbers/ocr_numbers.py +1 -5
- data/tracks/python/exercises/ocr-numbers/ocr_numbers_test.py +124 -106
- data/tracks/python/exercises/simple-linked-list/README.md +49 -0
- data/tracks/python/exercises/simple-linked-list/example.py +67 -0
- data/tracks/python/exercises/simple-linked-list/hints.md +10 -0
- data/tracks/python/exercises/simple-linked-list/simple_linked_list.py +33 -0
- data/tracks/python/exercises/simple-linked-list/simple_linked_list_test.py +112 -0
- data/tracks/rust/README.md +2 -0
- data/tracks/rust/bin/init_exercise.py +586 -0
- data/tracks/rust/config.json +20 -10
- data/tracks/rust/exercises/book-store/.gitignore +3 -0
- data/tracks/rust/exercises/book-store/Cargo-example.toml +7 -0
- data/tracks/rust/exercises/book-store/Cargo.toml +6 -0
- data/tracks/rust/exercises/book-store/README.md +107 -0
- data/tracks/rust/exercises/book-store/example.rs +187 -0
- data/tracks/rust/exercises/book-store/src/lib.rs +3 -0
- data/tracks/rust/exercises/book-store/tests/book-store.rs +130 -0
- data/tracks/sml/config.json +8 -8
- data/tracks/typescript/config.json +6 -6
- metadata +43 -46
- data/tracks/erlang/exercises/all-your-base/include/exercism.hrl +0 -11
- data/tracks/erlang/exercises/allergies/include/exercism.hrl +0 -11
- data/tracks/erlang/exercises/anagram/include/exercism.hrl +0 -11
- data/tracks/erlang/exercises/atbash-cipher/include/exercism.hrl +0 -11
- data/tracks/erlang/exercises/bank-account/include/exercism.hrl +0 -11
- data/tracks/erlang/exercises/beer-song/include/exercism.hrl +0 -11
- data/tracks/erlang/exercises/bob/include/exercism.hrl +0 -11
- data/tracks/erlang/exercises/circular-buffer/include/exercism.hrl +0 -11
- data/tracks/erlang/exercises/clock/include/exercism.hrl +0 -11
- data/tracks/erlang/exercises/collatz-conjecture/include/exercism.hrl +0 -11
- data/tracks/erlang/exercises/complex-numbers/include/exercism.hrl +0 -11
- data/tracks/erlang/exercises/custom-set/include/exercism.hrl +0 -11
- data/tracks/erlang/exercises/difference-of-squares/include/exercism.hrl +0 -11
- data/tracks/erlang/exercises/etl/include/exercism.hrl +0 -11
- data/tracks/erlang/exercises/gigasecond/include/exercism.hrl +0 -11
- data/tracks/erlang/exercises/grade-school/include/exercism.hrl +0 -11
- data/tracks/erlang/exercises/grains/include/exercism.hrl +0 -11
- data/tracks/erlang/exercises/hamming/include/exercism.hrl +0 -11
- data/tracks/erlang/exercises/hello-world/include/exercism.hrl +0 -11
- data/tracks/erlang/exercises/isogram/include/exercism.hrl +0 -11
- data/tracks/erlang/exercises/largest-series-product/include/exercism.hrl +0 -11
- data/tracks/erlang/exercises/leap/include/exercism.hrl +0 -11
- data/tracks/erlang/exercises/luhn/include/exercism.hrl +0 -11
- data/tracks/erlang/exercises/meetup/include/exercism.hrl +0 -11
- data/tracks/erlang/exercises/nucleotide-count/include/exercism.hrl +0 -11
- data/tracks/erlang/exercises/parallel-letter-frequency/include/exercism.hrl +0 -11
- data/tracks/erlang/exercises/phone-number/include/exercism.hrl +0 -11
- data/tracks/erlang/exercises/rna-transcription/include/exercism.hrl +0 -11
- data/tracks/erlang/exercises/robot-simulator/include/exercism.hrl +0 -11
- data/tracks/erlang/exercises/roman-numerals/include/exercism.hrl +0 -11
- data/tracks/erlang/exercises/rotational-cipher/include/exercism.hrl +0 -11
- data/tracks/erlang/exercises/scrabble-score/include/exercism.hrl +0 -11
- data/tracks/erlang/exercises/series/include/exercism.hrl +0 -11
- data/tracks/erlang/exercises/sieve/include/exercism.hrl +0 -11
- data/tracks/erlang/exercises/space-age/include/exercism.hrl +0 -11
- data/tracks/erlang/exercises/spiral-matrix/include/exercism.hrl +0 -11
- data/tracks/erlang/exercises/strain/include/exercism.hrl +0 -11
- data/tracks/erlang/exercises/sum-of-multiples/include/exercism.hrl +0 -11
- data/tracks/erlang/exercises/triangle/include/exercism.hrl +0 -11
- data/tracks/erlang/exercises/two-fer/include/exercism.hrl +0 -11
- data/tracks/erlang/exercises/word-count/include/exercism.hrl +0 -11
- data/tracks/erlang/exercises/zipper/include/exercism.hrl +0 -11
@@ -0,0 +1,256 @@
|
|
1
|
+
package zebra
|
2
|
+
|
3
|
+
import "fmt"
|
4
|
+
|
5
|
+
/* The Zebra Puzzle facts given:
|
6
|
+
|
7
|
+
1. There are five houses.
|
8
|
+
2. The Englishman lives in the red house.
|
9
|
+
3. The Spaniard owns the dog.
|
10
|
+
4. Coffee is drunk in the green house.
|
11
|
+
5. The Ukrainian drinks tea.
|
12
|
+
6. The green house is immediately to the right of the ivory house.
|
13
|
+
7. The Old Gold smoker owns snails.
|
14
|
+
8. Kools are smoked in the yellow house.
|
15
|
+
9. Milk is drunk in the middle house.
|
16
|
+
10. The Norwegian lives in the first house.
|
17
|
+
11. The man who smokes Chesterfields lives in the house next to the man with the fox.
|
18
|
+
12. Kools are smoked in the house next to the house where the horse is kept.
|
19
|
+
13. The Lucky Strike smoker drinks orange juice.
|
20
|
+
14. The Japanese smokes Parliaments.
|
21
|
+
15. The Norwegian lives next to the blue house.
|
22
|
+
|
23
|
+
*/
|
24
|
+
|
25
|
+
type Solution struct {
|
26
|
+
DrinksWater string
|
27
|
+
OwnsZebra string
|
28
|
+
}
|
29
|
+
|
30
|
+
// SolvePuzzle returns a solution answering the two questions for the zebra puzzle,
|
31
|
+
// which are "Who drinks water?", and "Who owns the zebra?"
|
32
|
+
func SolvePuzzle() (solution Solution) {
|
33
|
+
|
34
|
+
// 1. There are five houses.
|
35
|
+
const (
|
36
|
+
firstHouse = iota // name/identity of each house
|
37
|
+
secondHouse
|
38
|
+
middleHouse
|
39
|
+
fourthHouse
|
40
|
+
fifthHouse
|
41
|
+
numHouses
|
42
|
+
)
|
43
|
+
houses := []int{firstHouse, secondHouse, middleHouse, fourthHouse, fifthHouse}
|
44
|
+
|
45
|
+
// Generate the permutations of all the house identities.
|
46
|
+
houseIdentityPermutations := permutations(houses, numHouses)
|
47
|
+
|
48
|
+
// Note: Below, the pattern of var naming of "iXyz" is notation for "potential house (i)dentity of Xyz"
|
49
|
+
// So for example, when comparing pEnglishman == pRed, the test is determining whether the permutation
|
50
|
+
// of placements for both the Englishman and the red house agree to meet the given fact #2.
|
51
|
+
|
52
|
+
for _, houseColors := range houseIdentityPermutations {
|
53
|
+
|
54
|
+
iRed, iGreen, iIvory, iYellow, iBlue := assign(houseColors)
|
55
|
+
|
56
|
+
// 6. The green house is immediately to the right of the ivory house.
|
57
|
+
if !justRightOf(iGreen, iIvory) {
|
58
|
+
continue
|
59
|
+
}
|
60
|
+
|
61
|
+
for _, residents := range houseIdentityPermutations {
|
62
|
+
|
63
|
+
iEnglishman, iSpaniard, iUkrainian, iNorwegian, iJapanese := assign(residents)
|
64
|
+
|
65
|
+
// 2. The Englishman lives in the red house.
|
66
|
+
// 10. The Norwegian lives in the first house.
|
67
|
+
// 15. The Norwegian lives next to the blue house.
|
68
|
+
if iEnglishman != iRed || iNorwegian != firstHouse || !nextTo(iNorwegian, iBlue) {
|
69
|
+
continue
|
70
|
+
}
|
71
|
+
|
72
|
+
for _, beverages := range houseIdentityPermutations {
|
73
|
+
|
74
|
+
iCoffee, iTea, iMilk, iOrangeJuice, iWater := assign(beverages)
|
75
|
+
|
76
|
+
// 4. Coffee is drunk in the green house.
|
77
|
+
// 5. The Ukrainian drinks tea.
|
78
|
+
// 9. Milk is drunk in the middle house.
|
79
|
+
if iCoffee != iGreen || iUkrainian != iTea || iMilk != middleHouse {
|
80
|
+
continue
|
81
|
+
}
|
82
|
+
|
83
|
+
for _, smokeBrands := range houseIdentityPermutations {
|
84
|
+
|
85
|
+
iOldGold, iKools, iChesterfields, iLuckyStrike, iParliaments := assign(smokeBrands)
|
86
|
+
|
87
|
+
// 8. Kools are smoked in the yellow house.
|
88
|
+
// 13. The Lucky Strike smoker drinks orange juice.
|
89
|
+
// 14. The Japanese smokes Parliaments.
|
90
|
+
if iKools != iYellow || iLuckyStrike != iOrangeJuice || iJapanese != iParliaments {
|
91
|
+
continue
|
92
|
+
}
|
93
|
+
|
94
|
+
for _, pets := range houseIdentityPermutations {
|
95
|
+
|
96
|
+
iDog, iSnails, iFox, iHorse, iZebra := assign(pets)
|
97
|
+
|
98
|
+
// 3. The Spaniard owns the dog.
|
99
|
+
// 7. The Old Gold smoker owns snails.
|
100
|
+
// 11. The man who smokes Chesterfields lives in the house next to the man with the fox.
|
101
|
+
// 12. Kools are smoked in the house next to the house where the horse is kept.
|
102
|
+
if iSpaniard != iDog || iOldGold != iSnails ||
|
103
|
+
!nextTo(iChesterfields, iFox) || !nextTo(iKools, iHorse) {
|
104
|
+
continue
|
105
|
+
}
|
106
|
+
|
107
|
+
// At this point all criteria are met, so we arrived at the solution,
|
108
|
+
// and can fill in an array h of house facts (actually we only need the residents).
|
109
|
+
|
110
|
+
var h [numHouses]struct {
|
111
|
+
resident string
|
112
|
+
color string
|
113
|
+
pet string
|
114
|
+
beverage string
|
115
|
+
smokeBrand string
|
116
|
+
}
|
117
|
+
|
118
|
+
h[iEnglishman].resident = "Englishman"
|
119
|
+
h[iSpaniard].resident = "Spaniard"
|
120
|
+
h[iUkrainian].resident = "Ukrainian"
|
121
|
+
h[iJapanese].resident = "Japanese"
|
122
|
+
h[iNorwegian].resident = "Norwegian"
|
123
|
+
|
124
|
+
solution = Solution{
|
125
|
+
DrinksWater: h[iWater].resident,
|
126
|
+
OwnsZebra: h[iZebra].resident}
|
127
|
+
|
128
|
+
if !showHouseFacts {
|
129
|
+
return
|
130
|
+
}
|
131
|
+
h[iRed].color = "red"
|
132
|
+
h[iGreen].color = "green"
|
133
|
+
h[iIvory].color = "ivory"
|
134
|
+
h[iYellow].color = "yellow"
|
135
|
+
h[iBlue].color = "blue"
|
136
|
+
h[iDog].pet = "dog"
|
137
|
+
h[iSnails].pet = "snails"
|
138
|
+
h[iFox].pet = "fox"
|
139
|
+
h[iHorse].pet = "horse"
|
140
|
+
h[iZebra].pet = "zebra"
|
141
|
+
h[iCoffee].beverage = "coffee"
|
142
|
+
h[iTea].beverage = "tea"
|
143
|
+
h[iMilk].beverage = "milk"
|
144
|
+
h[iOrangeJuice].beverage = "orange juice"
|
145
|
+
h[iWater].beverage = "water"
|
146
|
+
h[iOldGold].smokeBrand = "OldGold"
|
147
|
+
h[iKools].smokeBrand = "Kools"
|
148
|
+
h[iChesterfields].smokeBrand = "Chesterfields"
|
149
|
+
h[iLuckyStrike].smokeBrand = "LuckyStrike"
|
150
|
+
h[iParliaments].smokeBrand = "Parliaments"
|
151
|
+
var houseNames = [5]string{"first", "second", "middle", "fourth", "fifth"}
|
152
|
+
|
153
|
+
for p := firstHouse; p <= fifthHouse; p++ {
|
154
|
+
var separator string
|
155
|
+
if h[p].pet[len(h[p].pet)-1] != 's' {
|
156
|
+
separator = "a "
|
157
|
+
}
|
158
|
+
fmt.Printf("The %-10s lives in the %-6s house which is %-7s owns %-8s drinks %-13s and smokes %-13s\n",
|
159
|
+
h[p].resident,
|
160
|
+
houseNames[p],
|
161
|
+
h[p].color+",",
|
162
|
+
separator+h[p].pet+",",
|
163
|
+
h[p].beverage+",",
|
164
|
+
h[p].smokeBrand+".")
|
165
|
+
}
|
166
|
+
|
167
|
+
return
|
168
|
+
}
|
169
|
+
}
|
170
|
+
}
|
171
|
+
}
|
172
|
+
}
|
173
|
+
return
|
174
|
+
}
|
175
|
+
|
176
|
+
const showHouseFacts = false // when true, print all house facts for fun.
|
177
|
+
|
178
|
+
// assign is notational helper function which returns the successive members
|
179
|
+
// of a permutation slice as five distinct values.
|
180
|
+
func assign(p []int) (a, b, c, d, e int) {
|
181
|
+
return p[0], p[1], p[2], p[3], p[4]
|
182
|
+
}
|
183
|
+
|
184
|
+
// justRightOf returns true if positionally x is just to the right of y.
|
185
|
+
func justRightOf(x, y int) bool {
|
186
|
+
return (x - y) == 1
|
187
|
+
}
|
188
|
+
|
189
|
+
// nextTo returns true if positionally, x is next to y, differing only by 1.
|
190
|
+
func nextTo(x, y int) bool {
|
191
|
+
return (x-y) == 1 || (y-x) == 1
|
192
|
+
}
|
193
|
+
|
194
|
+
// permutations returns a slice containing the r length permutations of the elements in iterable.
|
195
|
+
// The implementation is modeled after the Python intertools.permutations().
|
196
|
+
func permutations(iterable []int, r int) (perms [][]int) {
|
197
|
+
pool := iterable
|
198
|
+
n := len(pool)
|
199
|
+
|
200
|
+
if r > n {
|
201
|
+
return
|
202
|
+
}
|
203
|
+
|
204
|
+
indices := make([]int, n)
|
205
|
+
for i := range indices {
|
206
|
+
indices[i] = i
|
207
|
+
}
|
208
|
+
|
209
|
+
cycles := make([]int, r)
|
210
|
+
for i := range cycles {
|
211
|
+
cycles[i] = n - i
|
212
|
+
}
|
213
|
+
|
214
|
+
result := make([]int, r)
|
215
|
+
for i, el := range indices[:r] {
|
216
|
+
result[i] = pool[el]
|
217
|
+
}
|
218
|
+
|
219
|
+
p := make([]int, len(result))
|
220
|
+
copy(p, result)
|
221
|
+
perms = append(perms, p)
|
222
|
+
|
223
|
+
for n > 0 {
|
224
|
+
i := r - 1
|
225
|
+
for ; i >= 0; i-- {
|
226
|
+
cycles[i]--
|
227
|
+
if cycles[i] == 0 {
|
228
|
+
index := indices[i]
|
229
|
+
for j := i; j < n-1; j++ {
|
230
|
+
indices[j] = indices[j+1]
|
231
|
+
}
|
232
|
+
indices[n-1] = index
|
233
|
+
cycles[i] = n - i
|
234
|
+
} else {
|
235
|
+
j := cycles[i]
|
236
|
+
indices[i], indices[n-j] = indices[n-j], indices[i]
|
237
|
+
|
238
|
+
for k := i; k < r; k++ {
|
239
|
+
result[k] = pool[indices[k]]
|
240
|
+
}
|
241
|
+
|
242
|
+
p = make([]int, len(result))
|
243
|
+
copy(p, result)
|
244
|
+
perms = append(perms, p)
|
245
|
+
|
246
|
+
break
|
247
|
+
}
|
248
|
+
}
|
249
|
+
|
250
|
+
if i < 0 {
|
251
|
+
return
|
252
|
+
}
|
253
|
+
|
254
|
+
}
|
255
|
+
return
|
256
|
+
}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
package zebra
|
2
|
+
|
3
|
+
import "testing"
|
4
|
+
|
5
|
+
func TestSolvePuzzle(t *testing.T) {
|
6
|
+
expected := Solution{DrinksWater: "Norwegian", OwnsZebra: "Japanese"}
|
7
|
+
actual := SolvePuzzle()
|
8
|
+
if expected != actual {
|
9
|
+
t.Fatalf("FAILED:\nExpected: %#v\nActual: %#v",
|
10
|
+
expected, actual)
|
11
|
+
}
|
12
|
+
}
|
13
|
+
|
14
|
+
func BenchmarkScore(b *testing.B) {
|
15
|
+
for i := 0; i < b.N; i++ {
|
16
|
+
SolvePuzzle()
|
17
|
+
}
|
18
|
+
}
|
@@ -14,10 +14,7 @@ specs = do
|
|
14
14
|
|
15
15
|
let runTexts = fmap toList . foldM (flip evalText) empty
|
16
16
|
|
17
|
-
describe "parsing and numbers" $
|
18
|
-
it "empty input results in empty stack" $
|
19
|
-
toList empty `shouldBe` []
|
20
|
-
|
17
|
+
describe "parsing and numbers" $
|
21
18
|
it "numbers just get pushed onto the stack" $
|
22
19
|
runTexts ["1 2 3 4 5"] `shouldBe` Right [1, 2, 3, 4, 5]
|
23
20
|
|
@@ -22,4 +22,25 @@ specs = describe "rows" $ for_ rowsCases rowsTest
|
|
22
22
|
, ("two rows" , 2, [[1], [1, 1] ])
|
23
23
|
, ("three rows" , 3, [[1], [1, 1], [1, 2, 1] ])
|
24
24
|
, ("four rows" , 4, [[1], [1, 1], [1, 2, 1], [1, 3, 3, 1]])
|
25
|
-
, ("
|
25
|
+
, ("five rows" , 5, [[1],
|
26
|
+
[1, 1],
|
27
|
+
[1, 2, 1],
|
28
|
+
[1, 3, 3, 1],
|
29
|
+
[1, 4, 6, 4, 1]])
|
30
|
+
, ("six rows" , 6, [[1],
|
31
|
+
[1, 1],
|
32
|
+
[1, 2, 1],
|
33
|
+
[1, 3, 3, 1],
|
34
|
+
[1, 4, 6, 4, 1],
|
35
|
+
[1, 5, 10, 10, 5, 1]])
|
36
|
+
, ("ten rows" ,10, [[1],
|
37
|
+
[1, 1],
|
38
|
+
[1, 2, 1],
|
39
|
+
[1, 3, 3, 1],
|
40
|
+
[1, 4, 6, 4, 1],
|
41
|
+
[1, 5, 10, 10, 5, 1],
|
42
|
+
[1, 6, 15, 20, 15, 6, 1],
|
43
|
+
[1, 7, 21, 35, 35, 21, 7, 1],
|
44
|
+
[1, 8, 28, 56, 70, 56, 28, 8, 1],
|
45
|
+
[1, 9, 36, 84, 126, 126, 84, 36, 9, 1]])
|
46
|
+
, ("negative rows",-1, []) ]
|
data/tracks/java/POLICIES.md
CHANGED
@@ -33,11 +33,11 @@ References: [[1](https://github.com/exercism/java/issues/177#issuecomment-261291
|
|
33
33
|
|
34
34
|
### Starter implementations
|
35
35
|
|
36
|
-
> - Exercises
|
36
|
+
> - Exercises of difficulty 4 or lower: provide stubs for all required constructors and methods. Stubs should include the following body:
|
37
37
|
`throw new UnsupportedOperationException("Delete this statement and write your own implementation.");`
|
38
|
-
> - Exercises
|
38
|
+
> - Exercises of difficulty 5 or higher: provide no stubs by default, but either (1) add hints to the hints.md file (which gets merged into the README.md for the exercise) or (2) provide stubs as above for exercises that demand complicated method signatures.
|
39
39
|
|
40
|
-
References: [[1](https://github.com/exercism/java/issues/178)], [[2](https://github.com/exercism/java/pull/683#discussion_r125506930)]
|
40
|
+
References: [[1](https://github.com/exercism/java/issues/178)], [[2](https://github.com/exercism/java/pull/683#discussion_r125506930)], [[3](https://github.com/exercism/java/issues/977)]
|
41
41
|
|
42
42
|
### Avoid using final
|
43
43
|
|
data/tracks/java/config.json
CHANGED
@@ -166,6 +166,19 @@
|
|
166
166
|
"unlocked_by": "difference-of-squares",
|
167
167
|
"uuid": "d0dcc898-ec38-4822-9e3c-1a1829c9b2d9"
|
168
168
|
},
|
169
|
+
{
|
170
|
+
"core": false,
|
171
|
+
"difficulty": 3,
|
172
|
+
"slug": "protein-translation",
|
173
|
+
"topics": [
|
174
|
+
"arrays",
|
175
|
+
"conditionals",
|
176
|
+
"loops",
|
177
|
+
"strings"
|
178
|
+
],
|
179
|
+
"unlocked_by": "rna-transcription",
|
180
|
+
"uuid": "331073b3-bd1a-4868-b767-a64ce9fd9d97"
|
181
|
+
},
|
169
182
|
{
|
170
183
|
"core": false,
|
171
184
|
"difficulty": 4,
|
@@ -763,7 +776,13 @@
|
|
763
776
|
"core": false,
|
764
777
|
"difficulty": 6,
|
765
778
|
"slug": "bowling",
|
766
|
-
"topics":
|
779
|
+
"topics": [
|
780
|
+
"conditionals",
|
781
|
+
"exception_handling",
|
782
|
+
"games",
|
783
|
+
"integers",
|
784
|
+
"mathematics"
|
785
|
+
],
|
767
786
|
"unlocked_by": "scrabble-score",
|
768
787
|
"uuid": "4b3f7771-c642-4278-a3d9-2fb958f26361"
|
769
788
|
},
|
@@ -791,7 +810,7 @@
|
|
791
810
|
"text_formatting"
|
792
811
|
],
|
793
812
|
"unlocked_by": "matrix",
|
794
|
-
"uuid": "
|
813
|
+
"uuid": "486d342e-c834-40fc-b691-a4dab3f790da"
|
795
814
|
},
|
796
815
|
{
|
797
816
|
"core": false,
|
@@ -1,44 +1,44 @@
|
|
1
1
|
import java.util.ArrayList;
|
2
2
|
import java.util.List;
|
3
3
|
|
4
|
-
|
4
|
+
class Atbash {
|
5
5
|
|
6
6
|
private static final int GROUP_SIZE = 5;
|
7
7
|
private static final String PLAIN = "abcdefghijklmnopqrstuvwxyz";
|
8
8
|
private static final String CIPHER = "zyxwvutsrqponmlkjihgfedcba";
|
9
9
|
|
10
|
-
|
10
|
+
String encode(String input) {
|
11
11
|
String encoded = stripInvalidCharacters(input).toLowerCase();
|
12
|
-
|
12
|
+
StringBuilder cyphered = new StringBuilder(input.length());
|
13
13
|
|
14
14
|
for (char c : encoded.toCharArray()) {
|
15
|
-
cyphered
|
15
|
+
cyphered.append(applyCipher(c));
|
16
16
|
}
|
17
17
|
|
18
|
-
return splitIntoFiveLetterWords(cyphered);
|
18
|
+
return splitIntoFiveLetterWords(cyphered.toString());
|
19
19
|
}
|
20
20
|
|
21
|
-
|
21
|
+
String decode(String input) {
|
22
22
|
String encoded = stripInvalidCharacters(input).toLowerCase();
|
23
|
-
|
23
|
+
StringBuilder deciphered = new StringBuilder(input.length());
|
24
24
|
|
25
25
|
for (char c : encoded.toCharArray()) {
|
26
|
-
deciphered
|
26
|
+
deciphered.append(applyCipher(c));
|
27
27
|
}
|
28
28
|
|
29
|
-
return deciphered;
|
29
|
+
return deciphered.toString();
|
30
30
|
}
|
31
31
|
|
32
32
|
private String stripInvalidCharacters(String input) {
|
33
|
-
|
33
|
+
StringBuilder filteredValue = new StringBuilder(input.length());
|
34
34
|
|
35
35
|
for (char c : input.toCharArray()) {
|
36
36
|
if (Character.isLetterOrDigit(c)) {
|
37
|
-
filteredValue
|
37
|
+
filteredValue.append(c);
|
38
38
|
}
|
39
39
|
}
|
40
40
|
|
41
|
-
return filteredValue;
|
41
|
+
return filteredValue.toString();
|
42
42
|
}
|
43
43
|
|
44
44
|
private char applyCipher(char input) {
|
data/tracks/java/exercises/protein-translation/.meta/src/reference/java/ProteinTranslator.java
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
import java.util.ArrayList;
|
2
|
+
import java.util.Arrays;
|
3
|
+
import java.util.List;
|
4
|
+
|
5
|
+
class ProteinTranslator {
|
6
|
+
|
7
|
+
private static final String[] METHIONINE = {"AUG"};
|
8
|
+
private static final String[] PHENYLALANINE = {"UUU", "UUC"};
|
9
|
+
private static final String[] LEUCINE = {"UUA", "UUG"};
|
10
|
+
private static final String[] SERINE = {"UCU", "UCC", "UCA", "UCG"};
|
11
|
+
private static final String[] TYROSINE = {"UAU", "UAC"};
|
12
|
+
private static final String[] CYSTEINE = {"UGU", "UGC"};
|
13
|
+
private static final String[] TRYPTOPHAN = {"UGG"};
|
14
|
+
private static final String[] STOP = {"UAA", "UAG", "UGA"};
|
15
|
+
|
16
|
+
List<String> translate(String rnaSequence) {
|
17
|
+
|
18
|
+
List<String> proteinList = new ArrayList<String>();
|
19
|
+
|
20
|
+
for (int i = 0; i < rnaSequence.length(); i += 3) {
|
21
|
+
String codon = rnaSequence.substring(i, i+3);
|
22
|
+
|
23
|
+
if (Arrays.asList(METHIONINE).contains(codon)) {
|
24
|
+
proteinList.add("Methionine");
|
25
|
+
} else if (Arrays.asList(PHENYLALANINE).contains(codon)) {
|
26
|
+
proteinList.add("Phenylalanine");
|
27
|
+
} else if (Arrays.asList(LEUCINE).contains(codon)) {
|
28
|
+
proteinList.add("Leucine");
|
29
|
+
} else if (Arrays.asList(SERINE).contains(codon)) {
|
30
|
+
proteinList.add("Serine");
|
31
|
+
} else if (Arrays.asList(TYROSINE).contains(codon)) {
|
32
|
+
proteinList.add("Tyrosine");
|
33
|
+
} else if (Arrays.asList(CYSTEINE).contains(codon)) {
|
34
|
+
proteinList.add("Cysteine");
|
35
|
+
} else if (Arrays.asList(TRYPTOPHAN).contains(codon)) {
|
36
|
+
proteinList.add("Tryptophan");
|
37
|
+
} else if (Arrays.asList(STOP).contains(codon)) {
|
38
|
+
break;
|
39
|
+
} else {
|
40
|
+
throw new IllegalArgumentException("Invalid input");
|
41
|
+
}
|
42
|
+
|
43
|
+
}
|
44
|
+
|
45
|
+
return proteinList;
|
46
|
+
}
|
47
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
1.0.0
|
@@ -0,0 +1,58 @@
|
|
1
|
+
#Translate RNA sequences into proteins.
|
2
|
+
|
3
|
+
RNA can be broken into three nucleotide sequences called codons, and then translated to a polypeptide like so:
|
4
|
+
|
5
|
+
RNA: `"AUGUUUUCU"` => translates to
|
6
|
+
|
7
|
+
Codons: `"AUG", "UUU", "UCU"`
|
8
|
+
=> which become a polypeptide with the following sequence =>
|
9
|
+
|
10
|
+
Protein: `"Methionine", "Phenylalanine", "Serine"`
|
11
|
+
|
12
|
+
There are 64 codons which in turn correspond to 20 amino acids; however, all of the codon sequences and resulting amino acids are not important in this exercise. If it works for one codon, the program should work for all of them.
|
13
|
+
However, feel free to expand the list in the test suite to include them all.
|
14
|
+
|
15
|
+
There are also three terminating codons (also known as 'STOP' codons); if any of these codons are encountered (by the ribosome), all translation ends and the protein is terminated.
|
16
|
+
|
17
|
+
All subsequent codons after are ignored, like this:
|
18
|
+
|
19
|
+
RNA: `"AUGUUUUCUUAAAUG"` =>
|
20
|
+
|
21
|
+
Codons: `"AUG", "UUU", "UCU", "UAG", "AUG"` =>
|
22
|
+
|
23
|
+
Protein: `"Methionine", "Phenylalanine", "Serine"`
|
24
|
+
|
25
|
+
Note the stop codon terminates the translation and the final methionine is not translated into the protein sequence.
|
26
|
+
|
27
|
+
Below are the codons and resulting Amino Acids needed for the exercise.
|
28
|
+
|
29
|
+
Codon | Protein
|
30
|
+
:--- | :---
|
31
|
+
AUG | Methionine
|
32
|
+
UUU, UUC | Phenylalanine
|
33
|
+
UUA, UUG | Leucine
|
34
|
+
UCU, UCC, UCA, UCG | Serine
|
35
|
+
UAU, UAC | Tyrosine
|
36
|
+
UGU, UGC | Cysteine
|
37
|
+
UGG | Tryptophan
|
38
|
+
UAA, UAG, UGA | STOP
|
39
|
+
|
40
|
+
Learn more about [protein translation on Wikipedia](http://en.wikipedia.org/wiki/Translation_(biology))
|
41
|
+
|
42
|
+
# Running the tests
|
43
|
+
|
44
|
+
You can run all the tests for an exercise by entering
|
45
|
+
|
46
|
+
```sh
|
47
|
+
$ gradle test
|
48
|
+
```
|
49
|
+
|
50
|
+
in your terminal.
|
51
|
+
|
52
|
+
## Source
|
53
|
+
|
54
|
+
Tyler Long
|
55
|
+
|
56
|
+
## Submitting Incomplete Solutions
|
57
|
+
|
58
|
+
It's possible to submit an incomplete solution so you can see how others have completed the exercise.
|
@@ -0,0 +1,18 @@
|
|
1
|
+
apply plugin: "java"
|
2
|
+
apply plugin: "eclipse"
|
3
|
+
apply plugin: "idea"
|
4
|
+
|
5
|
+
repositories {
|
6
|
+
mavenCentral()
|
7
|
+
}
|
8
|
+
|
9
|
+
dependencies {
|
10
|
+
testCompile "junit:junit:4.12"
|
11
|
+
}
|
12
|
+
|
13
|
+
test {
|
14
|
+
testLogging {
|
15
|
+
exceptionFormat = 'full'
|
16
|
+
events = ["passed", "failed", "skipped"]
|
17
|
+
}
|
18
|
+
}
|