trackler 1.0.1.1 → 1.0.1.2

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.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/.gitmodules +3 -0
  3. data/README.md +11 -1
  4. data/bin/setup +2 -0
  5. data/lib/trackler/version.rb +1 -1
  6. data/tracks/prolog/.git +1 -0
  7. data/tracks/prolog/.gitignore +4 -0
  8. data/tracks/prolog/.travis.yml +12 -0
  9. data/tracks/prolog/LICENSE +21 -0
  10. data/tracks/prolog/README.md +12 -0
  11. data/tracks/prolog/SETUP.md +0 -0
  12. data/tracks/prolog/bin/build.sh +25 -0
  13. data/tracks/prolog/bin/fetch-configlet +32 -0
  14. data/tracks/prolog/config.json +74 -0
  15. data/tracks/prolog/docs/ABOUT.md +0 -0
  16. data/tracks/prolog/docs/INSTALLATION.md +0 -0
  17. data/tracks/prolog/docs/LEARNING.md +0 -0
  18. data/tracks/prolog/docs/RESOURCES.md +0 -0
  19. data/tracks/prolog/docs/TESTS.md +0 -0
  20. data/tracks/prolog/exercises/.keep +0 -0
  21. data/tracks/prolog/exercises/anagram/anagram.example +24 -0
  22. data/tracks/prolog/exercises/anagram/anagram.pl +1 -0
  23. data/tracks/prolog/exercises/anagram/anagram_tests.plt +57 -0
  24. data/tracks/prolog/exercises/binary/binary.example +11 -0
  25. data/tracks/prolog/exercises/binary/binary.pl +1 -0
  26. data/tracks/prolog/exercises/binary/binary_tests.plt +51 -0
  27. data/tracks/prolog/exercises/grains/grains.example +17 -0
  28. data/tracks/prolog/exercises/grains/grains.pl +3 -0
  29. data/tracks/prolog/exercises/grains/grains_tests.plt +39 -0
  30. data/tracks/prolog/exercises/hamming/hamming.example +15 -0
  31. data/tracks/prolog/exercises/hamming/hamming.pl +1 -0
  32. data/tracks/prolog/exercises/hamming/hamming_tests.plt +48 -0
  33. data/tracks/prolog/exercises/hello-world/hello_world.example +5 -0
  34. data/tracks/prolog/exercises/hello-world/hello_world.pl +0 -0
  35. data/tracks/prolog/exercises/hello-world/hello_world_tests.plt +11 -0
  36. data/tracks/prolog/exercises/leap/leap.example +3 -0
  37. data/tracks/prolog/exercises/leap/leap.pl +1 -0
  38. data/tracks/prolog/exercises/leap/leap_tests.plt +24 -0
  39. data/tracks/prolog/exercises/nucleotide-count/nucleotide_count.example +15 -0
  40. data/tracks/prolog/exercises/nucleotide-count/nucleotide_count.pl +0 -0
  41. data/tracks/prolog/exercises/nucleotide-count/nucleotide_count_tests.plt +22 -0
  42. data/tracks/prolog/exercises/rna-transcription/rna_transcription.example +18 -0
  43. data/tracks/prolog/exercises/rna-transcription/rna_transcription.pl +1 -0
  44. data/tracks/prolog/exercises/rna-transcription/rna_transcription_tests.plt +27 -0
  45. data/tracks/prolog/exercises/space-age/space_age.example +16 -0
  46. data/tracks/prolog/exercises/space-age/space_age.pl +1 -0
  47. data/tracks/prolog/exercises/space-age/space_age_tests.plt +38 -0
  48. data/tracks/prolog/exercises/sum-of-multiples/sum_of_multiples.example +14 -0
  49. data/tracks/prolog/exercises/sum-of-multiples/sum_of_multiples.pl +1 -0
  50. data/tracks/prolog/exercises/sum-of-multiples/sum_of_multiples_tests.plt +39 -0
  51. data/tracks/prolog/exercises/triangle/triangle.example +26 -0
  52. data/tracks/prolog/exercises/triangle/triangle.pl +1 -0
  53. data/tracks/prolog/exercises/triangle/triangle_tests.plt +45 -0
  54. data/tracks/prolog/img/.keep +0 -0
  55. metadata +51 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9afe3a2389f45df29805ba631f6e4c4afc5c66ef
4
- data.tar.gz: bebab04f762c5ee338b0e5a4d645985db6b5034b
3
+ metadata.gz: 46eba216917195005f43b257524ef79a75d0fcce
4
+ data.tar.gz: bf6317aaf2b8742bd480e33ea4e06bcbce0081f8
5
5
  SHA512:
6
- metadata.gz: 744116cb977fbed40d585e95a734cedf12e60c2277a703826e39e74e4525881333fed0ca7e4cc3d3add5432df76b6a681bf2c12c3ae7f2223c0bb83313cfd6fd
7
- data.tar.gz: 3932ddf8a13ac14ab7e0c0c4baaccb9cf15f7e0b4278d3411c34c07523dae0d07ff397d474a2c0e2904c71b6add9887d8c4f30d6882b6839dd1824f007c91688
6
+ metadata.gz: 323e53e441f4c400f84a4d0d0123d57e1c20ecee05c684c2df0788c678dc15cab9f6e32fb661e9bf4908fa3033051350e08eda69063add138f6077c927ca36ff
7
+ data.tar.gz: d7f42fc7e36ea22693526fcb80f2507492e59646361786e662e7ed1c02f7cc6cf19b7c3740469cae392e6a5c3ecb285de3edd3ec8e764b104764a9c48ba71217
data/.gitmodules CHANGED
@@ -160,3 +160,6 @@
160
160
  [submodule "tracks/pascal"]
161
161
  path = tracks/pascal
162
162
  url = https://github.com/exercism/xpascal.git
163
+ [submodule "tracks/prolog"]
164
+ path = tracks/prolog
165
+ url = https://github.com/exercism/xprolog
data/README.md CHANGED
@@ -64,7 +64,17 @@ end
64
64
 
65
65
  After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
66
66
 
67
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
67
+ To install this gem onto your local machine, run `bundle exec rake install`.
68
+
69
+ To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
70
+
71
+ ## Adding a new language track
72
+
73
+ Language tracks are included as submodules. To add a new one, run the following command, defining the track id as an environment variable. Shown here with `prolog` as an example.
74
+
75
+ ```
76
+ $ TRACK_ID=prolog; git submodule add https://github.com/exercism/x$TRACK_ID tracks/$TRACK_ID
77
+ ```
68
78
 
69
79
  ## Contributing
70
80
 
data/bin/setup CHANGED
@@ -4,5 +4,7 @@ IFS=$'\n\t'
4
4
  set -vx
5
5
 
6
6
  bundle install
7
+ git submodule init
8
+ git submodule update
7
9
 
8
10
  # Do any other automated setup that you need to do here
@@ -1,3 +1,3 @@
1
1
  module Trackler
2
- VERSION = "1.0.1.1"
2
+ VERSION = "1.0.1.2"
3
3
  end
@@ -0,0 +1 @@
1
+ gitdir: ../../.git/modules/tracks/prolog
@@ -0,0 +1,4 @@
1
+ *.swp
2
+ .DS_Store
3
+ bin/configlet
4
+ bin/configlet.exe
@@ -0,0 +1,12 @@
1
+ language: bash
2
+
3
+ install:
4
+ before_script:
5
+ - sudo apt-add-repository ppa:swi-prolog/devel -y
6
+ - sudo apt-get update -q
7
+ - sudo apt-get install swi-prolog-nox
8
+
9
+ script:
10
+ - bin/fetch-configlet
11
+ - bin/configlet .
12
+ - bin/build.sh
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Katrina Owen, _@kytrinyx.com
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,12 @@
1
+ # Exercism prolog Track
2
+ ![build status](https://travis-ci.org/exercism/xprolog.svg?branch=master)
3
+
4
+ Exercism exercises in prolog.
5
+
6
+ ## TODO
7
+
8
+ _Document how to contribute to the prolog track._
9
+
10
+ ## Contributing Guide
11
+
12
+ Please see the [contributing guide](https://github.com/exercism/x-common/blob/master/CONTRIBUTING.md).
File without changes
@@ -0,0 +1,25 @@
1
+ declare -i TEST_RESULT=0
2
+ FAILED_EXERCISES=''
3
+
4
+ for example_file in exercises/**/*.example
5
+ do
6
+ exercise_dir=$(dirname $example_file)
7
+ exercise=$(basename $example_file .example)
8
+ mv "$exercise_dir/$exercise.pl" "$exercise_dir/$exercise.impl"
9
+ mv "$exercise_dir/$exercise.example" "$exercise_dir/$exercise.pl"
10
+ echo '-------------------------------------------------------'
11
+ echo "Testing $exercise"
12
+ swipl -f "$exercise_dir/$exercise.pl" -s "$exercise_dir/${exercise}_tests.plt" -g run_tests,halt -t 'halt(1)'
13
+ if [ $? -ne 0 ]; then
14
+ TEST_RESULT=1
15
+ FAILED_EXERCISES+="$exercise\n"
16
+ fi
17
+ mv "$exercise_dir/$exercise.pl" "$exercise_dir/$exercise.example"
18
+ mv "$exercise_dir/$exercise.impl" "$exercise_dir/$exercise.pl"
19
+ done
20
+
21
+ if [ $TEST_RESULT -ne 0 ]; then
22
+ echo "The following exercises failed"
23
+ printf $FAILED_EXERCISES
24
+ exit $TEST_RESULT
25
+ fi
@@ -0,0 +1,32 @@
1
+ #!/bin/bash
2
+
3
+ LATEST=https://github.com/exercism/configlet/releases/latest
4
+
5
+ OS=$(
6
+ case $(uname) in
7
+ (Darwin*)
8
+ echo "mac";;
9
+ (Linux*)
10
+ echo "linux";;
11
+ (Windows*)
12
+ echo "windows";;
13
+ (*)
14
+ echo "linux";;
15
+ esac)
16
+
17
+ ARCH=$(
18
+ case $(uname -m) in
19
+ (*64*)
20
+ echo 64bit;;
21
+ (*686*)
22
+ echo 32bit;;
23
+ (*386*)
24
+ echo 32bit;;
25
+ (*)
26
+ echo 64bit;;
27
+ esac)
28
+
29
+ VERSION="$(curl --head --silent $LATEST | awk -v FS=/ '/Location:/{print $NF}' | tr -d '\r')"
30
+ URL=https://github.com/exercism/configlet/releases/download/$VERSION/configlet-$OS-${ARCH}.tgz
31
+
32
+ curl -s --location $URL | tar xz -C bin/
@@ -0,0 +1,74 @@
1
+ {
2
+ "slug": "prolog",
3
+ "language": "prolog",
4
+ "repository": "https://github.com/exercism/xprolog",
5
+ "active": false,
6
+ "exercises": [
7
+ {
8
+ "slug": "hello-world" ,
9
+ "difficulty": 1,
10
+ "topics": []
11
+ },
12
+ {
13
+ "slug": "sum-of-multiples",
14
+ "difficulty": 1,
15
+ "topics": []
16
+ },
17
+ {
18
+ "slug": "binary",
19
+ "difficulty": 1,
20
+ "topics": []
21
+ },
22
+ {
23
+ "slug": "leap",
24
+ "difficulty": 1,
25
+ "topics": []
26
+ },
27
+ {
28
+ "slug": "triangle",
29
+ "difficulty": 1,
30
+ "topics": []
31
+ },
32
+ {
33
+ "slug": "space-age",
34
+ "difficulty": 1,
35
+ "topics": []
36
+ },
37
+ {
38
+ "slug": "grains",
39
+ "difficulty": 1,
40
+ "topics": []
41
+ },
42
+ {
43
+ "slug": "nucleotide-count" ,
44
+ "difficulty": 1,
45
+ "topics": []
46
+ },
47
+ {
48
+ "slug": "hamming",
49
+ "difficulty": 1,
50
+ "topics": []
51
+ },
52
+ {
53
+ "slug": "anagram",
54
+ "difficulty": 1,
55
+ "topics": []
56
+ },
57
+ {
58
+ "slug": "rna-transcription",
59
+ "difficulty": 1,
60
+ "topics": []
61
+ }
62
+ ],
63
+ "deprecated": [
64
+
65
+ ],
66
+ "ignored": [
67
+ "bin",
68
+ "img",
69
+ "docs"
70
+ ],
71
+ "foregone": [
72
+
73
+ ]
74
+ }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,24 @@
1
+ % turns a string into a sorted list of characters
2
+ format_word(Word, Formatted) :-
3
+ string_lower(Word, LowercaseWord),
4
+ string_chars(LowercaseWord, CharList),
5
+ sort(CharList, Formatted).
6
+
7
+ anagram(Word, Options, Matching) :-
8
+ format_word(Word, FormattedWord),
9
+ anagram(Word, Options, Matching, FormattedWord).
10
+
11
+ anagram(_, [], [], _) :- !.
12
+ anagram(Word, [Option|Options], Matching, CharList) :-
13
+ Word \== Option,
14
+ format_word(Option, FormattedOption),
15
+ equal_lists(CharList, FormattedOption),
16
+ anagram(Word, Options, NextMatching, CharList),
17
+ Matching = [Option | NextMatching],
18
+ !.
19
+ anagram(Word, [_ | Options], Matching, CharList) :-
20
+ anagram(Word, Options, Matching, CharList).
21
+
22
+ equal_lists([], []).
23
+ equal_lists([H|T1], [H|T2]) :-
24
+ equal_lists(T1, T2).
@@ -0,0 +1 @@
1
+ anagram(Word, Options, Matching).
@@ -0,0 +1,57 @@
1
+ :- begin_tests(anagram).
2
+
3
+ test(no_matches) :-
4
+ anagram("diaper", [ "hello", "world", "zombies", "pants"], []).
5
+
6
+ test(detects_simple_anagram) :-
7
+ anagram("ant", ["tan", "stand", "at"], ["tan"]).
8
+
9
+ test(does_not_detect_false_positives) :-
10
+ anagram("galea", ["eagle"], []).
11
+
12
+ test(detects_multiple_anagrams) :-
13
+ anagram("master", ["stream", "pigeon", "maters"], ["stream", "maters"]).
14
+
15
+ test(does_not_detect_anagram_subsets) :-
16
+ anagram("good", ["dog", "goody"], []).
17
+
18
+ test(detects_anagram) :-
19
+ anagram("listen", ["enlists", "google", "inlets", "banana"], ["inlets"]).
20
+
21
+ test(detects_multiple_anagrams) :-
22
+ anagram("allergy", ["gallery", "ballerina", "regally", "clergy", "largely", "leading"], ["gallery", "regally", "largely"]).
23
+
24
+ test(does_not_detect_identical_words) :-
25
+ anagram("corn", ["corn", "dark", "Corn", "rank", "CORN", "cron", "park"], ["cron"]).
26
+
27
+ test(does_not_detect_nonanagrams_with_identical_checksum) :-
28
+ anagram("mass", ["last"], []).
29
+
30
+ test(detects_anagrams_case_insensitively) :-
31
+ anagram("Orchestra", ["cashregister", "Carthorse", "radishes"], ["Carthorse"]).
32
+
33
+ test(detects_anagrams_using_case_insensitive_subject) :-
34
+ anagram("Orchestra", ["cashregister", "carthorse", "radishes"], ["carthorse"]).
35
+
36
+ test(detects_anagrams_using_case_insensitive_possible_matches) :-
37
+ anagram("orchestra", ["cashregister", "Carthorse", "radishes"], ["Carthorse"]).
38
+
39
+ test(does_not_detect_a_word_as_its_own_anagram) :-
40
+ anagram("banana", ["Banana"], []).
41
+
42
+ test(does_not_detect_a_anagram_if_the_original_word_is_repeated) :-
43
+ anagram("go", ["go Go GO"], []).
44
+
45
+ test(anagrams_must_use_all_letters_exactly_once) :-
46
+ anagram("tapper", ["patter"], []).
47
+
48
+ test(detects_unicode_anagrams) :-
49
+ anagram("ΑΒΓ", ["ΒΓΑ", "ΒΓΔ", "γβα"], ["ΒΓΑ", "γβα"]).
50
+
51
+ test(eliminates_misleading_unicode_anagrams) :-
52
+ anagram("ΑΒΓ", ["ABΓ"], []).
53
+
54
+ test(capital_word_is_not_own_anagram) :-
55
+ anagram("BANANA", ["Banana"], []).
56
+
57
+ :- end_tests(anagram).
@@ -0,0 +1,11 @@
1
+ binary(Str, Dec) :-
2
+ string_chars(Str, RevLst),
3
+ reverse(RevLst, Lst),
4
+ convert(Lst, Dec).
5
+
6
+ convert([], 0).
7
+ convert([Head|List], Dec) :-
8
+ atom_number(Head, Val),
9
+ (Val is 0, !; Val is 1),
10
+ convert(List, NextDec),
11
+ Dec is NextDec*2 + Val.
@@ -0,0 +1 @@
1
+ binary(Str, Dec).
@@ -0,0 +1,51 @@
1
+ :- begin_tests(binary).
2
+
3
+ test(binary_0_is_decimal_0) :-
4
+ binary("0", 0).
5
+
6
+ test(binary_0_is_decimal_0) :-
7
+ binary("0", 0).
8
+
9
+ test(binary_1_is_decimal_1) :-
10
+ binary("1", 1).
11
+
12
+ test(binary_10_is_decimal_2) :-
13
+ binary("10", 2).
14
+
15
+ test(binary_11_is_decimal_3) :-
16
+ binary("11", 3).
17
+
18
+ test(binary_100_is_decimal_4) :-
19
+ binary("100", 4).
20
+
21
+ test(binary_1001_is_decimal_9) :-
22
+ binary("1001", 9).
23
+
24
+ test(binary_11010_is_decimal_26) :-
25
+ binary("11010", 26).
26
+
27
+ test(binary_10001101000_is_decimal_1128) :-
28
+ binary("10001101000", 1128).
29
+
30
+ test(binary_ignores_leading_zeros) :-
31
+ binary("000011111", 31).
32
+
33
+ test(two_is_not_a_valid_binary_digit, [fail]) :-
34
+ binary("2", _).
35
+
36
+ test(nonbinary_digit_is_invalid, [fail]) :-
37
+ binary("01201", _).
38
+
39
+ test(trailing_nonbinary_characters_is_invalid, [fail]) :-
40
+ binary("10nope", _).
41
+
42
+ test(nonbinary_characters_is_invalid, [fail]) :-
43
+ binary("nope10", _).
44
+
45
+ test(internal_nonbinary_characters_is_invalid, [fail]) :-
46
+ binary("10nope10", _).
47
+
48
+ test(whitespace_separated_is_invalid, [fail]) :-
49
+ binary("001 nope", _).
50
+
51
+ :- end_tests(binary).
@@ -0,0 +1,17 @@
1
+ square(1, 1) :- !.
2
+ square(SquareNumber, Value) :-
3
+ SquareNumber > 1, not(SquareNumber > 64),
4
+ NextSquare is SquareNumber - 1,
5
+ square(NextSquare, NewValue),
6
+ Value is 2 * NewValue,
7
+ !.
8
+
9
+ total(Total) :- total(Total, 64).
10
+
11
+ total(0, 0) :- !.
12
+ total(Total, Square) :-
13
+ NextSquare is Square - 1,
14
+ total(NextTotal, NextSquare),
15
+ square(Square, SquareValue),
16
+ Total is NextTotal + SquareValue.
17
+
@@ -0,0 +1,3 @@
1
+ square(SquareNumber, Value).
2
+
3
+ total(Value).
@@ -0,0 +1,39 @@
1
+ :- begin_tests(grains).
2
+
3
+ test(first) :-
4
+ square(1, 1).
5
+
6
+ test(second) :-
7
+ square(2, 2).
8
+
9
+ test(third) :-
10
+ square(3, 4).
11
+
12
+ test(sixteen) :-
13
+ square(16, 32768).
14
+
15
+ test(twenty_three) :-
16
+ square(23, 4194304).
17
+
18
+ test(thirty_two) :-
19
+ square(32, 2147483648).
20
+
21
+ test(fifty_five) :-
22
+ square(55, 18014398509481984).
23
+
24
+ test(sixty_four) :-
25
+ square(64, 9223372036854775808).
26
+
27
+ test(total) :-
28
+ total(18446744073709551615).
29
+
30
+ test(zero, [fail]) :-
31
+ square(0, _).
32
+
33
+ test(negative, [fail]) :-
34
+ square(-1, _).
35
+
36
+ test(off_board, [fail]) :-
37
+ square(65, _).
38
+
39
+ :- end_tests(grains).
@@ -0,0 +1,15 @@
1
+ hamming_distance(Str1, Str2, Distance) :-
2
+ string_length(Str1, Length),
3
+ string_length(Str2, Length),
4
+ string_chars(Str1, List1),
5
+ string_chars(Str2, List2),
6
+ hamming_distance_cmp(List1, List2, Distance).
7
+
8
+ hamming_distance_cmp([], [], 0) :- !.
9
+ hamming_distance_cmp([Char1|Chars1], [Char2|Chars2], Distance) :-
10
+ hamming_distance_cmp(Chars1, Chars2, NextDistance),
11
+ (Char1 == Char2 ->
12
+ Distance is NextDistance
13
+ ;
14
+ Distance is NextDistance + 1
15
+ ).
@@ -0,0 +1 @@
1
+ hamming_distance(Str1, Str2, Dist).
@@ -0,0 +1,48 @@
1
+ :- begin_tests(hamming).
2
+
3
+ test(identical_strands) :-
4
+ hamming_distance("A", "A", 0).
5
+
6
+ test(long_identical_strands) :-
7
+ hamming_distance("GGACTGA", "GGACTGA", 0).
8
+
9
+ test(complete_distance_in_single_nucleotide_strands) :-
10
+ hamming_distance("A", "G", 1).
11
+
12
+ test(complete_distance_in_small_strands) :-
13
+ hamming_distance("AG", "CT", 2).
14
+
15
+ test(small_distance_in_small_strands) :-
16
+ hamming_distance("AT", "CT", 1).
17
+
18
+ test(small_distance) :-
19
+ hamming_distance("GGACG", "GGTCG", 1).
20
+
21
+ test(small_distance_in_long_strands) :-
22
+ hamming_distance("ACCAGGG", "ACTATGG", 2).
23
+
24
+ test(nonunique_character_in_first_strand) :-
25
+ hamming_distance("AGA", "AGG", 1).
26
+
27
+ test(nonunique_character_in_second_strand) :-
28
+ hamming_distance("AGG", "AGA", 1).
29
+
30
+ test(same_nucleotides_in_different_positions) :-
31
+ hamming_distance("TAG", "GAT", 2).
32
+
33
+ test(large_distance) :-
34
+ hamming_distance("GATACA", "GCATAA", 4).
35
+
36
+ test(large_distance_in_offbyone_strand) :-
37
+ hamming_distance("GGACGGATTCTG", "AGGACGGATTCT", 9).
38
+
39
+ test(empty_strands) :-
40
+ hamming_distance("", "", 0).
41
+
42
+ test(disallow_first_strand_longer, [fail]) :-
43
+ hamming_distance("AATG", "AAA", _).
44
+
45
+ test(disallow_second_strand_longer, [fail]) :-
46
+ hamming_distance("ATA", "AGTG", _).
47
+
48
+ :- end_tests(hamming).
@@ -0,0 +1,5 @@
1
+ hello_world('Hello World!').
2
+
3
+ hello_world(Name, Phrase) :-
4
+ atom_concat('Hello ', Name, HelloName),
5
+ atom_concat(HelloName, '!', Phrase).
@@ -0,0 +1,11 @@
1
+ :- begin_tests(hello_word).
2
+ test(hello_world) :-
3
+ hello_world('Hello World!').
4
+
5
+ test(hello_world_fail, blocked("Pending")) :-
6
+ hello_world('Alice', 'Hello Alice!').
7
+
8
+ test(hello_world_fail, blocked("Pending")) :-
9
+ hello_world('Bob', 'Hello Bob!').
10
+
11
+ :- end_tests(hello_word).
@@ -0,0 +1,3 @@
1
+ leap(Year) :-
2
+ 0 is mod(Year, 4), not(0 is mod(Year, 100)), !;
3
+ 0 is mod(Year, 400).
@@ -0,0 +1 @@
1
+ leap(Year).
@@ -0,0 +1,24 @@
1
+ :- begin_tests(leap_tests).
2
+
3
+ test(leap_year) :-
4
+ leap(1996).
5
+
6
+ test(standard_and_odd_year) :-
7
+ not(leap(1997)).
8
+
9
+ test(standard_even_year) :-
10
+ not(leap(1998)).
11
+
12
+ test(standard_nineteeth_century) :-
13
+ not(leap(1900)).
14
+
15
+ test(standard_eighteenth_century) :-
16
+ not(leap(1800)).
17
+
18
+ test(leap_twenty_fourth_century) :-
19
+ leap(2400).
20
+
21
+ test(leap_y2k) :-
22
+ leap(2000).
23
+
24
+ :- end_tests(leap_tests).
@@ -0,0 +1,15 @@
1
+ nucleotide_count(Strand, Counts) :-
2
+ atom_chars(Strand, Nucleotides),
3
+ count_nucleotides(Nucleotides, [('A', 0), ('C', 0), ('G', 0), ('T', 0)], Counts).
4
+
5
+ count_nucleotides([], Counts, Counts).
6
+ count_nucleotides([Nucleotide | Rest], Running, Counts) :-
7
+ count_single_nucleotide(Nucleotide, Running, NewCounts),
8
+ count_nucleotides(Rest, NewCounts, Counts).
9
+
10
+ count_single_nucleotide(Nucleotide, [(OtherNucleotide, OtherCount) | Rest], NewCounts) :-
11
+ count_single_nucleotide(Nucleotide, Rest, RestCounts),
12
+ append([(OtherNucleotide, OtherCount)], RestCounts, NewCounts).
13
+ count_single_nucleotide(Nucleotide, [(Nucleotide, Count) | Rest], NewCounts) :-
14
+ NewCount is Count + 1,
15
+ append([(Nucleotide, NewCount)], Rest, NewCounts).
@@ -0,0 +1,22 @@
1
+ :- begin_tests(nucleotide_counting).
2
+
3
+ test(empty_dna_strand_has_no_adenosine) :-
4
+ nucleotide_count('', [('A', 0) | _ ]), !.
5
+
6
+ test(repetitive_cytidine_gets_counted) :-
7
+ nucleotide_count('CCCCC', Counts),
8
+ member(('C', 5), Counts), !.
9
+
10
+ test(counts_only_thymidine) :-
11
+ nucleotide_count('GGGGGTAACCCGG', Counts),
12
+ member(('T', 1), Counts), !.
13
+
14
+ test(counts_only_thymidine) :-
15
+ nucleotide_count(
16
+ 'AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC',
17
+ [ ('A' ,20), ('C' , 12), ('G' , 17), ('T', 21) ]), !.
18
+
19
+ test(fails_when_not_dns, [fail]) :-
20
+ nucleotide_count('JOHNNYAPPLESEED', _), !.
21
+
22
+ :- end_tests(nucleotide_counting).
@@ -0,0 +1,18 @@
1
+ rna_transcription(Rna, Dna) :-
2
+ string_chars(Rna, RnaList),
3
+ rna_transcription_list(RnaList, DnaList),
4
+ string_chars(Dna, DnaList).
5
+
6
+ rna_transcription_list([], []) :- !.
7
+ rna_transcription_list([RnaBase | Rna], [DnaBase | Dna]) :-
8
+ (RnaBase = 'C' ->
9
+ DnaBase = 'G';
10
+ RnaBase = 'G' ->
11
+ DnaBase = 'C';
12
+ RnaBase = 'T' ->
13
+ DnaBase = 'A';
14
+ RnaBase = 'A' ->
15
+ DnaBase = 'U'
16
+ ),
17
+ rna_transcription_list(Rna, Dna).
18
+
@@ -0,0 +1 @@
1
+ rna_transcription(Rna, Dna).
@@ -0,0 +1,27 @@
1
+ :- begin_tests(rna_transcription).
2
+
3
+ test(rna_complement_of_cytosine_is_guanine) :-
4
+ rna_transcription("C", "G").
5
+
6
+ test(rna_complement_of_guanine_is_cytosine) :-
7
+ rna_transcription("G", "C").
8
+
9
+ test(rna_complement_of_thymine_is_adenine) :-
10
+ rna_transcription("T", "A").
11
+
12
+ test(rna_complement_of_adenine_is_uracil) :-
13
+ rna_transcription("A", "U").
14
+
15
+ test(rna_complement) :-
16
+ rna_transcription("ACGTGGTCTTAA", "UGCACCAGAAUU").
17
+
18
+ test(dna_correctly_handles_invalid_input, [fail]) :-
19
+ rna_transcription("U", _).
20
+
21
+ test(dna_correctly_handles_completely_invalid_input, [fail]) :-
22
+ rna_transcription("XXX", _).
23
+
24
+ test(dna_correctly_handles_partially_invalid_input, [fail]) :-
25
+ rna_transcription("ACGTXXXCTTAA", _).
26
+
27
+ :- end_tests(rna_transcription).
@@ -0,0 +1,16 @@
1
+ period("Earth", 1).
2
+ period("Mercury", 0.2408467).
3
+ period("Venus", 0.61519726).
4
+ period("Mars", 1.8808158).
5
+ period("Jupiter", 11.862615).
6
+ period("Saturn", 29.447498).
7
+ period("Uranus", 84.016846).
8
+ period("Neptune", 164.79132).
9
+
10
+ convYearSec(Year, Sec) :-
11
+ Year is Sec / 31557600.
12
+
13
+ space_age(Planet, AgeSec, Years) :-
14
+ period(Planet, Conv),
15
+ convYearSec(AgeYear, AgeSec),
16
+ Years is AgeYear / Conv, !.
@@ -0,0 +1 @@
1
+ space_age(Planet, AgeSec, Years).
@@ -0,0 +1,38 @@
1
+ :- begin_tests(space_age).
2
+
3
+ float_eq(Real, Expected) :-
4
+ Expected is round(Real * 100).
5
+
6
+ test(earth) :-
7
+ space_age("Earth", 1000000000, Age),
8
+ float_eq(Age, 3169).
9
+
10
+ test(mercury) :-
11
+ space_age("Mercury", 2134835688, Age),
12
+ float_eq(Age, 28088).
13
+
14
+ test(venus) :-
15
+ space_age("Venus", 189839836, Age),
16
+ float_eq(Age, 978).
17
+
18
+ test(mars) :-
19
+ space_age("Mars", 2329871239, Age),
20
+ float_eq(Age, 3925).
21
+
22
+ test(jupiter) :-
23
+ space_age("Jupiter", 901876382, Age),
24
+ float_eq(Age, 241).
25
+
26
+ test(saturn) :-
27
+ space_age("Saturn", 3000000000, Age),
28
+ float_eq(Age, 323).
29
+
30
+ test(uranus) :-
31
+ space_age("Uranus", 3210123456, Age),
32
+ float_eq(Age, 121).
33
+
34
+ test(neptune) :-
35
+ space_age("Neptune", 8210123456, Age),
36
+ float_eq(Age, 158).
37
+
38
+ :- end_tests(space_age).
@@ -0,0 +1,14 @@
1
+ factored([Curr|Factors], Num) :-
2
+ 0 is mod(Num, Curr), !;
3
+ factored(Factors, Num).
4
+
5
+ sum_of_multiples(_, 0, 0) :- !.
6
+ sum_of_multiples(Factors, Limit, Sum) :-
7
+ Next is Limit - 1,
8
+ sum_of_multiples(Factors, Next, NextSum),
9
+ (
10
+ factored(Factors, Limit),
11
+ Sum is Limit + NextSum, !;
12
+ Sum is NextSum
13
+ ).
14
+
@@ -0,0 +1 @@
1
+ sum_of_multiples(Factors, Limit, Sum).
@@ -0,0 +1,39 @@
1
+ :- begin_tests(sum_of_multiples).
2
+
3
+ test(low_limit) :-
4
+ sum_of_multiples([3, 5], 1, 0).
5
+
6
+ test(just_one_multiple) :-
7
+ sum_of_multiples([3, 5], 4, 3).
8
+
9
+ test(a_few_multiples) :-
10
+ sum_of_multiples([3, 5], 10, 23).
11
+
12
+ test(sum_more_multiples) :-
13
+ sum_of_multiples([3, 5], 100, 2318).
14
+
15
+ test(even_more_multiples) :-
16
+ sum_of_multiples([3, 5], 1000, 233168).
17
+
18
+ test(new_factors) :-
19
+ sum_of_multiples([7, 13, 17], 20, 51).
20
+
21
+ test(sum_more_new_factors) :-
22
+ sum_of_multiples([4, 6], 15, 30).
23
+
24
+ test(even_more_new_factors) :-
25
+ sum_of_multiples([5, 6, 8], 150, 4419).
26
+
27
+ test(divisible_factor) :-
28
+ sum_of_multiples([5, 25], 51, 275).
29
+
30
+ test(large_factors) :-
31
+ sum_of_multiples([43, 47], 10000, 2203160).
32
+
33
+ test(every_num) :-
34
+ sum_of_multiples([1], 100, 4950).
35
+
36
+ test(no_factors) :-
37
+ sum_of_multiples([], 10000, 0).
38
+
39
+ :- end_tests(sum_of_multiples).
@@ -0,0 +1,26 @@
1
+ triangle(Side, Side, Side, "equilateral") :-
2
+ valid_triangle(Side, Side, Side), !.
3
+
4
+ triangle(SideEq, SideEq, OtherSide, "isosceles") :-
5
+ valid_triangle(SideEq, SideEq, OtherSide), !.
6
+
7
+ triangle(SideEq, OtherSide, SideEq, "isosceles") :-
8
+ valid_triangle(SideEq, SideEq, OtherSide), !.
9
+
10
+ triangle(OtherSide, SideEq, SideEq, "isosceles") :-
11
+ valid_triangle(SideEq, SideEq, OtherSide), !.
12
+
13
+ triangle(Side1, Side2, Side3, "scalene") :-
14
+ valid_triangle(Side1, Side2, Side3).
15
+
16
+
17
+ valid_triangle(Side1, Side2, Side3) :-
18
+ Add23 is Side2 + Side3,
19
+ Add12 is Side1 + Side2,
20
+ Add13 is Side1 + Side3,
21
+ not(Side1 > Add23),
22
+ not(Side2 > Add13),
23
+ not(Side3 > Add12),
24
+ Side1 \== 0,
25
+ Side2 \== 0,
26
+ Side3 \== 0.
@@ -0,0 +1 @@
1
+ triangle(Side1, Side2, Side3, Type).
@@ -0,0 +1,45 @@
1
+ :- begin_tests(triangle).
2
+
3
+ test(equilateral_triangle_has_all_sides_equal) :-
4
+ triangle(2, 2, 2, "equilateral").
5
+
6
+ test(larger_equilateral_triangle) :-
7
+ triangle(10, 10, 10, "equilateral").
8
+
9
+ test(isosceles_triangle_with_last_two_sides_equal) :-
10
+ triangle(3, 4, 4, "isosceles").
11
+
12
+ test(isosceles_triangle_with_first_two_sides_equal) :-
13
+ triangle(4, 4, 3, "isosceles").
14
+
15
+ test(isosceles_triangle_with_first_and_last_sides_equal) :-
16
+ triangle(4, 3, 4, "isosceles").
17
+
18
+ test(isosceles_triangle_with_unequal_side_larger_than_equal_sides) :-
19
+ triangle(4, 7, 4, "isosceles").
20
+
21
+ test(scalene_triangle_has_no_equal_sides) :-
22
+ triangle(3, 4, 5, "scalene").
23
+
24
+ test(a2_equals_b_plus_c_isnt_always_equilateral) :-
25
+ triangle(5, 4, 6, "scalene").
26
+
27
+ test(larger_scalene_triangle) :-
28
+ triangle(10, 11, 12, "scalene").
29
+
30
+ test(scalene_triangle_with_sides_in_descending_order) :-
31
+ triangle(5, 4, 2, "scalene").
32
+
33
+ test(small_scalene_triangle_with_floating_point_values) :-
34
+ triangle((0.4), (0.6), (0.3), "scalene").
35
+
36
+ test(a_triangle_violating_the_triangle_inequality_is_illegal, [fail]) :-
37
+ triangle(7, 3, 2, _).
38
+
39
+ test(two_sides_equal_but_violates_triangle_inequality, [fail]) :-
40
+ triangle(1, 1, 3, _).
41
+
42
+ test(triangles_with_all_sides_zero_are_illegal, [fail]) :-
43
+ triangle(0, 0, 0, _).
44
+
45
+ :- end_tests(triangle).
File without changes
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: 1.0.1.1
4
+ version: 1.0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Katrina Owen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-16 00:00:00.000000000 Z
11
+ date: 2016-10-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubyzip
@@ -4956,6 +4956,55 @@ files:
4956
4956
  - tracks/powershell/exercises/hello-world/hello-world.tests.ps1
4957
4957
  - tracks/powershell/exercises/hello-world/hello-world_example.ps1
4958
4958
  - tracks/powershell/img/icon.png
4959
+ - tracks/prolog/.git
4960
+ - tracks/prolog/.gitignore
4961
+ - tracks/prolog/.travis.yml
4962
+ - tracks/prolog/LICENSE
4963
+ - tracks/prolog/README.md
4964
+ - tracks/prolog/SETUP.md
4965
+ - tracks/prolog/bin/build.sh
4966
+ - tracks/prolog/bin/fetch-configlet
4967
+ - tracks/prolog/config.json
4968
+ - tracks/prolog/docs/ABOUT.md
4969
+ - tracks/prolog/docs/INSTALLATION.md
4970
+ - tracks/prolog/docs/LEARNING.md
4971
+ - tracks/prolog/docs/RESOURCES.md
4972
+ - tracks/prolog/docs/TESTS.md
4973
+ - tracks/prolog/exercises/.keep
4974
+ - tracks/prolog/exercises/anagram/anagram.example
4975
+ - tracks/prolog/exercises/anagram/anagram.pl
4976
+ - tracks/prolog/exercises/anagram/anagram_tests.plt
4977
+ - tracks/prolog/exercises/binary/binary.example
4978
+ - tracks/prolog/exercises/binary/binary.pl
4979
+ - tracks/prolog/exercises/binary/binary_tests.plt
4980
+ - tracks/prolog/exercises/grains/grains.example
4981
+ - tracks/prolog/exercises/grains/grains.pl
4982
+ - tracks/prolog/exercises/grains/grains_tests.plt
4983
+ - tracks/prolog/exercises/hamming/hamming.example
4984
+ - tracks/prolog/exercises/hamming/hamming.pl
4985
+ - tracks/prolog/exercises/hamming/hamming_tests.plt
4986
+ - tracks/prolog/exercises/hello-world/hello_world.example
4987
+ - tracks/prolog/exercises/hello-world/hello_world.pl
4988
+ - tracks/prolog/exercises/hello-world/hello_world_tests.plt
4989
+ - tracks/prolog/exercises/leap/leap.example
4990
+ - tracks/prolog/exercises/leap/leap.pl
4991
+ - tracks/prolog/exercises/leap/leap_tests.plt
4992
+ - tracks/prolog/exercises/nucleotide-count/nucleotide_count.example
4993
+ - tracks/prolog/exercises/nucleotide-count/nucleotide_count.pl
4994
+ - tracks/prolog/exercises/nucleotide-count/nucleotide_count_tests.plt
4995
+ - tracks/prolog/exercises/rna-transcription/rna_transcription.example
4996
+ - tracks/prolog/exercises/rna-transcription/rna_transcription.pl
4997
+ - tracks/prolog/exercises/rna-transcription/rna_transcription_tests.plt
4998
+ - tracks/prolog/exercises/space-age/space_age.example
4999
+ - tracks/prolog/exercises/space-age/space_age.pl
5000
+ - tracks/prolog/exercises/space-age/space_age_tests.plt
5001
+ - tracks/prolog/exercises/sum-of-multiples/sum_of_multiples.example
5002
+ - tracks/prolog/exercises/sum-of-multiples/sum_of_multiples.pl
5003
+ - tracks/prolog/exercises/sum-of-multiples/sum_of_multiples_tests.plt
5004
+ - tracks/prolog/exercises/triangle/triangle.example
5005
+ - tracks/prolog/exercises/triangle/triangle.pl
5006
+ - tracks/prolog/exercises/triangle/triangle_tests.plt
5007
+ - tracks/prolog/img/.keep
4959
5008
  - tracks/purescript/.git
4960
5009
  - tracks/purescript/.gitignore
4961
5010
  - tracks/purescript/.travis.yml