trackler 2.2.1.6 → 2.2.1.7
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/tracks/c/README.md +27 -0
- data/tracks/coffeescript/config.json +1 -0
- data/tracks/coldfusion/config.json +1 -1
- data/tracks/crystal/README.md +27 -7
- data/tracks/crystal/config/maintainers.json +25 -0
- data/tracks/crystal/generator/spec/remote_data_file_spec.cr +1 -1
- data/tracks/crystal/generator/src/exercise_generator.cr +1 -1
- data/tracks/crystal/generator/src/remote_data_file.cr +2 -2
- data/tracks/csharp/config.json +1 -2
- data/tracks/csharp/config/maintainers.json +55 -0
- data/tracks/csharp/docs/EXERCISE_README_INSERT.md +1 -1
- data/tracks/csharp/exercises/accumulate/README.md +1 -1
- data/tracks/csharp/exercises/acronym/README.md +1 -1
- data/tracks/csharp/exercises/all-your-base/README.md +1 -1
- data/tracks/csharp/exercises/allergies/README.md +1 -1
- data/tracks/csharp/exercises/alphametics/README.md +1 -1
- data/tracks/csharp/exercises/anagram/README.md +1 -1
- data/tracks/csharp/exercises/atbash-cipher/README.md +1 -1
- data/tracks/csharp/exercises/bank-account/README.md +1 -1
- data/tracks/csharp/exercises/beer-song/README.md +1 -1
- data/tracks/csharp/exercises/binary-search-tree/README.md +1 -1
- data/tracks/csharp/exercises/binary-search/README.md +1 -1
- data/tracks/csharp/exercises/bob/README.md +1 -1
- data/tracks/csharp/exercises/book-store/README.md +1 -1
- data/tracks/csharp/exercises/bowling/README.md +1 -1
- data/tracks/csharp/exercises/bracket-push/README.md +1 -1
- data/tracks/csharp/exercises/change/README.md +1 -1
- data/tracks/csharp/exercises/circular-buffer/README.md +1 -1
- data/tracks/csharp/exercises/clock/README.md +1 -1
- data/tracks/csharp/exercises/connect/README.md +1 -1
- data/tracks/csharp/exercises/crypto-square/README.md +1 -1
- data/tracks/csharp/exercises/custom-set/README.md +1 -1
- data/tracks/csharp/exercises/diamond/README.md +1 -1
- data/tracks/csharp/exercises/difference-of-squares/README.md +1 -1
- data/tracks/csharp/exercises/diffie-hellman/README.md +1 -1
- data/tracks/csharp/exercises/dominoes/README.md +1 -1
- data/tracks/csharp/exercises/dot-dsl/README.md +1 -1
- data/tracks/csharp/exercises/error-handling/README.md +1 -1
- data/tracks/csharp/exercises/etl/README.md +1 -1
- data/tracks/csharp/exercises/flatten-array/README.md +1 -1
- data/tracks/csharp/exercises/food-chain/README.md +1 -1
- data/tracks/csharp/exercises/forth/README.md +1 -1
- data/tracks/csharp/exercises/gigasecond/README.md +1 -1
- data/tracks/csharp/exercises/go-counting/README.md +1 -1
- data/tracks/csharp/exercises/grade-school/README.md +1 -1
- data/tracks/csharp/exercises/grains/README.md +1 -1
- data/tracks/csharp/exercises/grep/README.md +1 -1
- data/tracks/csharp/exercises/hamming/README.md +1 -1
- data/tracks/csharp/exercises/hangman/README.md +1 -1
- data/tracks/csharp/exercises/hello-world/README.md +1 -1
- data/tracks/csharp/exercises/house/README.md +1 -1
- data/tracks/csharp/exercises/isogram/README.md +1 -1
- data/tracks/csharp/exercises/kindergarten-garden/README.md +1 -1
- data/tracks/csharp/exercises/largest-series-product/README.md +1 -1
- data/tracks/csharp/exercises/leap/README.md +1 -1
- data/tracks/csharp/exercises/ledger/README.md +1 -1
- data/tracks/csharp/exercises/linked-list/README.md +1 -1
- data/tracks/csharp/exercises/list-ops/README.md +1 -1
- data/tracks/csharp/exercises/luhn/README.md +1 -1
- data/tracks/csharp/exercises/markdown/README.md +1 -1
- data/tracks/csharp/exercises/matrix/README.md +1 -1
- data/tracks/csharp/exercises/meetup/README.md +1 -1
- data/tracks/csharp/exercises/minesweeper/README.md +1 -1
- data/tracks/csharp/exercises/nth-prime/README.md +1 -1
- data/tracks/csharp/exercises/nucleotide-count/README.md +1 -1
- data/tracks/csharp/exercises/ocr-numbers/README.md +1 -1
- data/tracks/csharp/exercises/palindrome-products/README.md +1 -1
- data/tracks/csharp/exercises/pangram/README.md +1 -1
- data/tracks/csharp/exercises/parallel-letter-frequency/README.md +1 -1
- data/tracks/csharp/exercises/pascals-triangle/README.md +1 -1
- data/tracks/csharp/exercises/perfect-numbers/README.md +1 -1
- data/tracks/csharp/exercises/phone-number/README.md +1 -1
- data/tracks/csharp/exercises/pig-latin/README.md +1 -1
- data/tracks/csharp/exercises/poker/README.md +1 -1
- data/tracks/csharp/exercises/pov/README.md +1 -1
- data/tracks/csharp/exercises/prime-factors/README.md +1 -1
- data/tracks/csharp/exercises/protein-translation/README.md +1 -1
- data/tracks/csharp/exercises/proverb/README.md +1 -1
- data/tracks/csharp/exercises/pythagorean-triplet/README.md +1 -1
- data/tracks/csharp/exercises/queen-attack/README.md +1 -1
- data/tracks/csharp/exercises/rail-fence-cipher/README.md +1 -1
- data/tracks/csharp/exercises/raindrops/README.md +1 -1
- data/tracks/csharp/exercises/react/README.md +1 -1
- data/tracks/csharp/exercises/rectangles/README.md +1 -1
- data/tracks/csharp/exercises/rna-transcription/README.md +1 -1
- data/tracks/csharp/exercises/robot-name/README.md +1 -1
- data/tracks/csharp/exercises/robot-simulator/README.md +1 -1
- data/tracks/csharp/exercises/roman-numerals/README.md +1 -1
- data/tracks/csharp/exercises/rotational-cipher/README.md +1 -1
- data/tracks/csharp/exercises/run-length-encoding/README.md +1 -1
- data/tracks/csharp/exercises/saddle-points/README.md +1 -1
- data/tracks/csharp/exercises/say/README.md +1 -1
- data/tracks/csharp/exercises/scale-generator/README.md +1 -1
- data/tracks/csharp/exercises/scrabble-score/README.md +1 -1
- data/tracks/csharp/exercises/secret-handshake/README.md +1 -1
- data/tracks/csharp/exercises/series/README.md +1 -1
- data/tracks/csharp/exercises/sgf-parsing/README.md +1 -1
- data/tracks/csharp/exercises/sieve/README.md +1 -1
- data/tracks/csharp/exercises/simple-cipher/README.md +1 -1
- data/tracks/csharp/exercises/simple-linked-list/README.md +1 -1
- data/tracks/csharp/exercises/space-age/README.md +1 -1
- data/tracks/csharp/exercises/strain/README.md +1 -1
- data/tracks/csharp/exercises/sublist/README.md +1 -1
- data/tracks/csharp/exercises/sum-of-multiples/README.md +1 -1
- data/tracks/csharp/exercises/tournament/README.md +1 -1
- data/tracks/csharp/exercises/transpose/README.md +1 -1
- data/tracks/csharp/exercises/tree-building/README.md +1 -1
- data/tracks/csharp/exercises/triangle/README.md +1 -1
- data/tracks/csharp/exercises/twelve-days/README.md +1 -1
- data/tracks/csharp/exercises/two-bucket/README.md +1 -1
- data/tracks/csharp/exercises/variable-length-quantity/README.md +1 -1
- data/tracks/csharp/exercises/word-count/README.md +1 -1
- data/tracks/csharp/exercises/word-search/README.md +1 -1
- data/tracks/csharp/exercises/wordy/README.md +1 -1
- data/tracks/csharp/exercises/zebra-puzzle/README.md +1 -1
- data/tracks/csharp/exercises/zipper/README.md +1 -1
- data/tracks/d/config.json +1 -0
- data/tracks/dart/config/maintainers.json +15 -0
- data/tracks/ecmascript/config.json +76 -193
- data/tracks/ecmascript/exercises/twelve-days/README.md +66 -0
- data/tracks/ecmascript/exercises/twelve-days/example.js +53 -0
- data/tracks/ecmascript/exercises/twelve-days/package.json +68 -0
- data/tracks/ecmascript/exercises/twelve-days/twelve-days.spec.js +106 -0
- data/tracks/factor/config.json +1 -1
- data/tracks/fsharp/config/maintainers.json +35 -0
- data/tracks/go/config.json +82 -38
- data/tracks/go/config/maintainers.json +13 -22
- data/tracks/go/exercises/bowling/cases_test.go +11 -11
- data/tracks/go/exercises/forth/cases_test.go +7 -7
- data/tracks/go/exercises/forth/example.go +1 -1
- data/tracks/go/exercises/forth/forth_test.go +1 -1
- data/tracks/go/exercises/hamming/cases_test.go +7 -7
- data/tracks/go/exercises/hamming/hamming.go +1 -1
- data/tracks/go/exercises/phone-number/cases_test.go +2 -7
- data/tracks/go/exercises/phone-number/example.go +1 -1
- data/tracks/go/exercises/phone-number/phone_number_test.go +1 -1
- data/tracks/go/exercises/rna-transcription/cases_test.go +7 -7
- data/tracks/go/exercises/secret-handshake/cases_test.go +1 -1
- data/tracks/groovy/config.json +1 -0
- data/tracks/haxe/config.json +1 -1
- data/tracks/java/.travis.yml +1 -1
- data/tracks/java/config/maintainers.json +20 -0
- data/tracks/java/exercises/custom-set/src/test/java/CustomSetTest.java +1 -1
- data/tracks/java/exercises/word-count/src/test/java/WordCountTest.java +1 -1
- data/tracks/javascript/config.json +229 -247
- data/tracks/kotlin/config/maintainers.json +35 -0
- data/tracks/lfe/config/maintainers.json +15 -0
- data/tracks/lisp/config/maintainers.json +55 -0
- data/tracks/ocaml/config.json +0 -5
- data/tracks/ocaml/config/maintainers.json +25 -0
- data/tracks/perl5/config/maintainers.json +25 -0
- data/tracks/perl6/config/maintainers.json +25 -0
- data/tracks/pony/config/maintainers.json +15 -0
- data/tracks/pony/exercises/atbash-cipher/example.pony +2 -2
- data/tracks/pony/exercises/beer-song/example.pony +1 -1
- data/tracks/pony/exercises/bob/example.pony +1 -1
- data/tracks/pony/exercises/difference-of-squares/example.pony +1 -1
- data/tracks/pony/exercises/hamming/test.pony +12 -12
- data/tracks/pony/exercises/pascals-triangle/example.pony +1 -1
- data/tracks/pony/exercises/pascals-triangle/test.pony +6 -6
- data/tracks/pony/exercises/rna-transcription/test.pony +3 -3
- data/tracks/pony/exercises/roman-numerals/test.pony +3 -3
- data/tracks/purescript/config/maintainers.json +35 -0
- data/tracks/r/config.json +140 -81
- data/tracks/r/exercises/collatz-conjecture/README.md +43 -0
- data/tracks/r/exercises/collatz-conjecture/collatz-conjecture.R +3 -0
- data/tracks/r/exercises/collatz-conjecture/example.R +13 -0
- data/tracks/r/exercises/collatz-conjecture/test_collatz-conjecture.R +28 -0
- data/tracks/r/exercises/nucleotide-count/README.md +43 -0
- data/tracks/r/exercises/nucleotide-count/example.R +17 -0
- data/tracks/r/exercises/nucleotide-count/nucleotide-count.R +3 -0
- data/tracks/r/exercises/nucleotide-count/test_nucleotide-count.R +51 -0
- data/tracks/r/exercises/pangram/README.md +25 -0
- data/tracks/r/exercises/pangram/example.R +14 -0
- data/tracks/r/exercises/pangram/pangram.R +3 -0
- data/tracks/r/exercises/pangram/test_pangram.R +42 -0
- data/tracks/r/exercises/triangle/.meta/hints.md +4 -0
- data/tracks/r/exercises/triangle/README.md +41 -0
- data/tracks/r/exercises/triangle/example.R +23 -0
- data/tracks/r/exercises/triangle/test_triangle.R +72 -0
- data/tracks/r/exercises/triangle/triangle.R +3 -0
- data/tracks/rust/config.json +32 -1
- data/tracks/rust/config/maintainers.json +1 -6
- data/tracks/rust/exercises/acronym/tests/acronym.rs +1 -1
- data/tracks/rust/exercises/beer-song/example.rs +1 -1
- data/tracks/rust/exercises/circular-buffer/example.rs +8 -10
- data/tracks/rust/exercises/circular-buffer/tests/circular-buffer.rs +2 -2
- data/tracks/rust/exercises/clock/.meta/hints.md +10 -0
- data/tracks/rust/exercises/clock/Cargo.lock +4 -0
- data/tracks/rust/exercises/clock/Cargo.toml +6 -0
- data/tracks/rust/exercises/clock/README.md +57 -0
- data/tracks/rust/exercises/clock/example.rs +32 -0
- data/tracks/{ocaml/exercises/point-mutations/example.ml → rust/exercises/clock/src/lib.rs} +0 -0
- data/tracks/rust/exercises/clock/tests/clock.rs +331 -0
- data/tracks/rust/exercises/custom-set/tests/custom-set.rs +3 -3
- data/tracks/rust/exercises/dominoes/example.rs +1 -1
- data/tracks/rust/exercises/grade-school/example.rs +1 -1
- data/tracks/rust/exercises/hamming/example.rs +1 -1
- data/tracks/rust/exercises/nth-prime/Cargo.lock +4 -0
- data/tracks/rust/exercises/nth-prime/Cargo.toml +6 -0
- data/tracks/rust/exercises/nth-prime/README.md +47 -0
- data/tracks/rust/exercises/nth-prime/example.rs +28 -0
- data/tracks/rust/exercises/nth-prime/src/lib.rs +0 -0
- data/tracks/rust/exercises/nth-prime/tests/nth-prime.rs +30 -0
- data/tracks/rust/exercises/parallel-letter-frequency/example.rs +1 -1
- data/tracks/rust/exercises/phone-number/example.rs +1 -1
- data/tracks/rust/exercises/pythagorean-triplet/Cargo.lock +4 -0
- data/tracks/rust/exercises/pythagorean-triplet/Cargo.toml +6 -0
- data/tracks/rust/exercises/pythagorean-triplet/README.md +56 -0
- data/tracks/rust/exercises/pythagorean-triplet/example.rs +11 -0
- data/tracks/rust/exercises/pythagorean-triplet/src/lib.rs +0 -0
- data/tracks/rust/exercises/pythagorean-triplet/tests/pythagorean-triplet.rs +6 -0
- data/tracks/rust/exercises/rna-transcription/tests/rna-transcription.rs +1 -1
- data/tracks/rust/exercises/robot-name/tests/robot-name.rs +2 -2
- data/tracks/rust/exercises/say/example.rs +4 -4
- data/tracks/rust/exercises/say/tests/say.rs +4 -4
- data/tracks/rust/exercises/tournament/example.rs +2 -2
- data/tracks/scala/config/maintainers.json +10 -6
- data/tracks/scala/exercises/bracket-push/example.scala +2 -2
- data/tracks/scala/exercises/bracket-push/src/test/scala/BracketPushTest.scala +74 -0
- data/tracks/scala/exercises/crypto-square/example.scala +9 -9
- data/tracks/scala/exercises/crypto-square/src/test/scala/CryptoSquareTest.scala +33 -41
- data/tracks/scala/testgen/src/main/scala/BracketPushTestGenerator.scala +9 -38
- data/tracks/scala/testgen/src/main/scala/CryptoSquareTestGenerator.scala +17 -0
- data/tracks/sml/config.json +1 -1
- data/tracks/swift/config/maintainers.json +35 -0
- data/tracks/swift/docs/ABOUT.md +15 -5
- data/tracks/vimscript/config/maintainers.json +35 -0
- metadata +58 -8
- data/tracks/ocaml/exercises/point-mutations/Makefile +0 -8
- data/tracks/ocaml/exercises/point-mutations/README.md +0 -81
- data/tracks/ocaml/exercises/point-mutations/dna.mli +0 -6
- data/tracks/scala/exercises/bracket-push/src/test/scala/BracketsTest.scala +0 -68
- data/tracks/scala/exercises/crypto-square/src/main/scala/CryptoSquare.scala +0 -11
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# Collatz Conjecture
|
|
2
|
+
|
|
3
|
+
The Collatz Conjecture or 3x+1 problem can be summarized as follows:
|
|
4
|
+
|
|
5
|
+
Take any positive integer n. If n is even, divide n by 2 to get n / 2. If n is
|
|
6
|
+
odd, multiply n by 3 and add 1 to get 3n + 1. Repeat the process indefinitely.
|
|
7
|
+
The conjecture states that no matter which number you start with, you will
|
|
8
|
+
always reach 1 eventually.
|
|
9
|
+
|
|
10
|
+
Given a number n, return the number of steps required to reach 1.
|
|
11
|
+
|
|
12
|
+
## Examples
|
|
13
|
+
Starting with n = 12, the steps would be as follows:
|
|
14
|
+
|
|
15
|
+
0. 12
|
|
16
|
+
1. 6
|
|
17
|
+
2. 3
|
|
18
|
+
3. 10
|
|
19
|
+
4. 5
|
|
20
|
+
5. 16
|
|
21
|
+
6. 8
|
|
22
|
+
7. 4
|
|
23
|
+
8. 2
|
|
24
|
+
9. 1
|
|
25
|
+
|
|
26
|
+
Resulting in 9 steps. So for input n = 12, the return value would be 9.
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
## Installation
|
|
30
|
+
See [this guide](https://github.com/exercism/xr/blob/master/docs/INSTALLATION.md) for instructions on how to setup your local R environment.
|
|
31
|
+
|
|
32
|
+
## How to implement your solution
|
|
33
|
+
In each problem folder, there is a file named `<exercise_name>.R` containing a function that returns a `NULL` value. Place your implementation inside the body of the function.
|
|
34
|
+
|
|
35
|
+
## How to run tests
|
|
36
|
+
Inside of RStudio, simply execute the `test_<exercise_name>.R` script. This can be conveniently done with [testthat's `auto_test` function](https://www.rdocumentation.org/packages/testthat/topics/auto_test). Because exercism code and tests are in the same folder, use this same path for both `code_path` and `test_path` parameters. On the command-line, you can also run `Rscript test_<exercise_name>.R`.
|
|
37
|
+
|
|
38
|
+
## Source
|
|
39
|
+
|
|
40
|
+
An unsolved problem in mathematics named after mathematician Lothar Collatz [https://en.wikipedia.org/wiki/3x_%2B_1_problem](https://en.wikipedia.org/wiki/3x_%2B_1_problem)
|
|
41
|
+
|
|
42
|
+
## Submitting Incomplete Solutions
|
|
43
|
+
It's possible to submit an incomplete solution so you can see how others have completed the exercise.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
collatz_step_counter <- function(num) {
|
|
2
|
+
|
|
3
|
+
if (num <= 0) {
|
|
4
|
+
stop("Only positive numbers are allowed")
|
|
5
|
+
} else if (num == 1) {
|
|
6
|
+
return(0)
|
|
7
|
+
} else if (num %% 2 == 0) {
|
|
8
|
+
return(1 + collatz_step_counter(num/2))
|
|
9
|
+
} else {
|
|
10
|
+
return(1 + collatz_step_counter(3*num + 1))
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
source("./collatz-conjecture.R")
|
|
2
|
+
library(testthat)
|
|
3
|
+
|
|
4
|
+
test_that("Input of 1 results in 0 steps", {
|
|
5
|
+
expect_equal(collatz_step_counter(1), 0)
|
|
6
|
+
})
|
|
7
|
+
|
|
8
|
+
test_that("Even input with repeated even steps", {
|
|
9
|
+
expect_equal(collatz_step_counter(16), 4)
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
test_that("Input which results in small number of even and odd steps", {
|
|
13
|
+
expect_equal(collatz_step_counter(12), 9)
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
test_that("Input which results in large number of even and odd steps", {
|
|
17
|
+
expect_equal(collatz_step_counter(1000000), 152)
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
test_that("Input of 0 results in an error", {
|
|
21
|
+
expect_error(collatz_step_counter(0))
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
test_that("Negative input results in an error", {
|
|
25
|
+
expect_error(collatz_step_counter(-15))
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
message("All tests passed for exercise: collatz-conjecture")
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# Nucleotide Count
|
|
2
|
+
|
|
3
|
+
Given a DNA string, compute how many times each nucleotide occurs in the string.
|
|
4
|
+
|
|
5
|
+
DNA is represented by an alphabet of the following symbols: 'A', 'C',
|
|
6
|
+
'G', and 'T'.
|
|
7
|
+
|
|
8
|
+
Each symbol represents a nucleotide, which is a fancy name for the
|
|
9
|
+
particular molecules that happen to make up a large part of DNA.
|
|
10
|
+
|
|
11
|
+
Shortest intro to biochemistry EVAR:
|
|
12
|
+
|
|
13
|
+
- twigs are to birds nests as
|
|
14
|
+
- nucleotides are to DNA and RNA as
|
|
15
|
+
- amino acids are to proteins as
|
|
16
|
+
- sugar is to starch as
|
|
17
|
+
- oh crap lipids
|
|
18
|
+
|
|
19
|
+
I'm not going to talk about lipids because they're crazy complex.
|
|
20
|
+
|
|
21
|
+
So back to nucleotides.
|
|
22
|
+
|
|
23
|
+
DNA contains four types of them: adenine (`A`), cytosine (`C`), guanine
|
|
24
|
+
(`G`), and thymine (`T`).
|
|
25
|
+
|
|
26
|
+
RNA contains a slightly different set of nucleotides, but we don't care
|
|
27
|
+
about that for now.
|
|
28
|
+
|
|
29
|
+
## Installation
|
|
30
|
+
See [this guide](https://github.com/exercism/xr/blob/master/docs/INSTALLATION.md) for instructions on how to setup your local R environment.
|
|
31
|
+
|
|
32
|
+
## How to implement your solution
|
|
33
|
+
In each problem folder, there is a file named `<exercise_name>.R` containing a function that returns a `NULL` value. Place your implementation inside the body of the function.
|
|
34
|
+
|
|
35
|
+
## How to run tests
|
|
36
|
+
Inside of RStudio, simply execute the `test_<exercise_name>.R` script. This can be conveniently done with [testthat's `auto_test` function](https://www.rdocumentation.org/packages/testthat/topics/auto_test). Because exercism code and tests are in the same folder, use this same path for both `code_path` and `test_path` parameters. On the command-line, you can also run `Rscript test_<exercise_name>.R`.
|
|
37
|
+
|
|
38
|
+
## Source
|
|
39
|
+
|
|
40
|
+
The Calculating DNA Nucleotides_problem at Rosalind [http://rosalind.info/problems/dna/](http://rosalind.info/problems/dna/)
|
|
41
|
+
|
|
42
|
+
## Submitting Incomplete Solutions
|
|
43
|
+
It's possible to submit an incomplete solution so you can see how others have completed the exercise.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
library(magrittr)
|
|
2
|
+
|
|
3
|
+
nucleotide_count <- function(input) {
|
|
4
|
+
|
|
5
|
+
strand_chr <- strsplit(input, "")[[1]]
|
|
6
|
+
|
|
7
|
+
nucleotides <- c("A", "C", "G", "T")
|
|
8
|
+
|
|
9
|
+
if (length(strand_chr) > 0 && !all(strand_chr %in% nucleotides)) {
|
|
10
|
+
stop("Invalid nucleotide in strand")
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
nucleotides %>%
|
|
14
|
+
sapply(function(x) {sum(x == strand_chr)}) %>%
|
|
15
|
+
as.list()
|
|
16
|
+
|
|
17
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
source("./nucleotide-count.R")
|
|
2
|
+
library(testthat)
|
|
3
|
+
|
|
4
|
+
# When comparing lists, all.equal expects the objects to be in the same order
|
|
5
|
+
# This expectation instead checks that a) the set of names are the same and
|
|
6
|
+
# b) each named object is equal
|
|
7
|
+
expect_equal_pairs <- function(object, expected) {
|
|
8
|
+
expect_equal(sort(names(object)),
|
|
9
|
+
sort(names(expected)),
|
|
10
|
+
info = "names in lists differ")
|
|
11
|
+
for (name in names(expected)) {
|
|
12
|
+
expect_equal(object[name], expected[name], info = "list element missing")
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
test_that("all zeros for empty strand", {
|
|
17
|
+
expect_equal_pairs(nucleotide_count(""),
|
|
18
|
+
list(
|
|
19
|
+
A = 0,
|
|
20
|
+
C = 0,
|
|
21
|
+
G = 0,
|
|
22
|
+
T = 0
|
|
23
|
+
))
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
test_that("3 zeros & 1 count for strand with a single repeated nucleotide", {
|
|
27
|
+
expect_equal_pairs(nucleotide_count("GGGGGGG"),
|
|
28
|
+
list(
|
|
29
|
+
A = 0,
|
|
30
|
+
C = 0,
|
|
31
|
+
G = 7,
|
|
32
|
+
T = 0
|
|
33
|
+
))
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
test_that("correct counts for strand with multiple nucleotides", {
|
|
37
|
+
expect_equal_pairs(nucleotide_count(
|
|
38
|
+
"AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC"),
|
|
39
|
+
list(
|
|
40
|
+
A = 20,
|
|
41
|
+
C = 12,
|
|
42
|
+
G = 17,
|
|
43
|
+
T = 21
|
|
44
|
+
))
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
test_that("error for strand with invalid nucleotides", {
|
|
48
|
+
expect_error(nucleotide_count("AGXXACT"))
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
message("All tests passed for exercise: nucleotide-count")
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Pangram
|
|
2
|
+
|
|
3
|
+
Determine if a sentence is a pangram. A pangram (Greek: παν γράμμα, pan gramma,
|
|
4
|
+
"every letter") is a sentence using every letter of the alphabet at least once.
|
|
5
|
+
The best known English pangram is:
|
|
6
|
+
> The quick brown fox jumps over the lazy dog.
|
|
7
|
+
|
|
8
|
+
The alphabet used consists of ASCII letters `a` to `z`, inclusive, and is case
|
|
9
|
+
insensitive. Input will not contain non-ASCII symbols.
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
See [this guide](https://github.com/exercism/xr/blob/master/docs/INSTALLATION.md) for instructions on how to setup your local R environment.
|
|
13
|
+
|
|
14
|
+
## How to implement your solution
|
|
15
|
+
In each problem folder, there is a file named `<exercise_name>.R` containing a function that returns a `NULL` value. Place your implementation inside the body of the function.
|
|
16
|
+
|
|
17
|
+
## How to run tests
|
|
18
|
+
Inside of RStudio, simply execute the `test_<exercise_name>.R` script. This can be conveniently done with [testthat's `auto_test` function](https://www.rdocumentation.org/packages/testthat/topics/auto_test). Because exercism code and tests are in the same folder, use this same path for both `code_path` and `test_path` parameters. On the command-line, you can also run `Rscript test_<exercise_name>.R`.
|
|
19
|
+
|
|
20
|
+
## Source
|
|
21
|
+
|
|
22
|
+
Wikipedia [https://en.wikipedia.org/wiki/Pangram](https://en.wikipedia.org/wiki/Pangram)
|
|
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,42 @@
|
|
|
1
|
+
source("./pangram.R")
|
|
2
|
+
library(testthat)
|
|
3
|
+
|
|
4
|
+
test_that("sentence empty", {
|
|
5
|
+
expect_false(is_pangram(""))
|
|
6
|
+
})
|
|
7
|
+
|
|
8
|
+
test_that("pangram with only lower case", {
|
|
9
|
+
expect_true(is_pangram("the quick brown fox jumps over the lazy dog"))
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
test_that("missing character 'x'", {
|
|
13
|
+
expect_false(
|
|
14
|
+
is_pangram("a quick movement of the enemy will jeopardize five gunboats"))
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
test_that("another missing character 'x'", {
|
|
18
|
+
expect_false(is_pangram("the quick brown fish jumps over the lazy dog"))
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
test_that("pangram with underscores", {
|
|
22
|
+
expect_true(is_pangram("the_quick_brown_fox_jumps_over_the_lazy_dog"))
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
test_that("pangram with numbers", {
|
|
26
|
+
expect_true(is_pangram("the 1 quick brown fox jumps over the 2 lazy dogs"))
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
test_that("missing letters replaced by numbers", {
|
|
30
|
+
expect_false(is_pangram("7h3 qu1ck brown fox jumps ov3r 7h3 lazy dog"))
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
test_that("pangram with mixed case and punctuation", {
|
|
34
|
+
expect_true(is_pangram("\"Five quacking Zephyrs jolt my wax bed.\""))
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
test_that("upper and lower case versions of the same character should not be
|
|
38
|
+
counted separately", {
|
|
39
|
+
expect_false(is_pangram("the quick brown fox jumped over the lazy FOX"))
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
message("All tests passed for exercise: pangram")
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# Triangle
|
|
2
|
+
|
|
3
|
+
Determine if a triangle is equilateral, isosceles, or scalene.
|
|
4
|
+
|
|
5
|
+
An _equilateral_ triangle has all three sides the same length.<br/>
|
|
6
|
+
An _isosceles_ triangle has at least two sides the same length. (It is sometimes
|
|
7
|
+
specified as having exactly two sides the same length, but for the purposes of
|
|
8
|
+
this exercise we'll say at least two.)<br/>
|
|
9
|
+
A _scalene_ triangle has all sides of different lengths.
|
|
10
|
+
|
|
11
|
+
## Note
|
|
12
|
+
|
|
13
|
+
For a shape to be a triangle at all, all sides have to be of length > 0, and
|
|
14
|
+
the sum of the lengths of any two sides must be greater than or equal to the
|
|
15
|
+
length of the third side. See [Triangle Inequality](https://en.wikipedia.org/wiki/Triangle_inequality).
|
|
16
|
+
|
|
17
|
+
## Dig Deeper
|
|
18
|
+
|
|
19
|
+
The case where the sum of the lengths of two sides _equals_ that of the
|
|
20
|
+
third is known as a _degenerate_ triangle - it has zero area and looks like
|
|
21
|
+
a single line. Feel free to add your own code/tests to check for degenerate triangles.
|
|
22
|
+
|
|
23
|
+
## Hint
|
|
24
|
+
|
|
25
|
+
For this exercise you will need to implement a simple S3 class. If you are not familiar with S3, a great starting point is the [chapter on S3](http://adv-r.hadley.nz/s3.html) in Hadley Wickham's book Advanced R.
|
|
26
|
+
|
|
27
|
+
## Installation
|
|
28
|
+
See [this guide](https://github.com/exercism/xr/blob/master/docs/INSTALLATION.md) for instructions on how to setup your local R environment.
|
|
29
|
+
|
|
30
|
+
## How to implement your solution
|
|
31
|
+
In each problem folder, there is a file named `<exercise_name>.R` containing a function that returns a `NULL` value. Place your implementation inside the body of the function.
|
|
32
|
+
|
|
33
|
+
## How to run tests
|
|
34
|
+
Inside of RStudio, simply execute the `test_<exercise_name>.R` script. This can be conveniently done with [testthat's `auto_test` function](https://www.rdocumentation.org/packages/testthat/topics/auto_test). Because exercism code and tests are in the same folder, use this same path for both `code_path` and `test_path` parameters. On the command-line, you can also run `Rscript test_<exercise_name>.R`.
|
|
35
|
+
|
|
36
|
+
## Source
|
|
37
|
+
|
|
38
|
+
The Ruby Koans triangle project, parts 1 & 2 [http://rubykoans.com](http://rubykoans.com)
|
|
39
|
+
|
|
40
|
+
## Submitting Incomplete Solutions
|
|
41
|
+
It's possible to submit an incomplete solution so you can see how others have completed the exercise.
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
triangle <- function(x, y, z) {
|
|
2
|
+
|
|
3
|
+
checks <- c(x + y < z,
|
|
4
|
+
x + z < y,
|
|
5
|
+
y + z < x,
|
|
6
|
+
x == 0,
|
|
7
|
+
y == 0,
|
|
8
|
+
z == 0)
|
|
9
|
+
|
|
10
|
+
if (any(checks)) {
|
|
11
|
+
stop("Invalid sides for triangle")
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
unique_sides <- length(unique(c(x, y, z)))
|
|
15
|
+
|
|
16
|
+
triangle_class <- switch(unique_sides,
|
|
17
|
+
c("equilateral", "isosceles"),
|
|
18
|
+
"isosceles",
|
|
19
|
+
"scalene")
|
|
20
|
+
|
|
21
|
+
structure(list(x = x, y = y, z = z), class = triangle_class)
|
|
22
|
+
|
|
23
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
source("./triangle.R")
|
|
2
|
+
library(testthat)
|
|
3
|
+
|
|
4
|
+
test_that("true if all sides are equal", {
|
|
5
|
+
expect_is(triangle(2, 2, 2), "equilateral")
|
|
6
|
+
})
|
|
7
|
+
|
|
8
|
+
test_that("false if any side is unequal", {
|
|
9
|
+
expect_false(any("equilateral" %in% class(triangle(2, 3, 2))))
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
test_that("false if no sides are equal", {
|
|
13
|
+
expect_false(any("equilateral" %in% class(triangle(5, 4, 6))))
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
test_that("not equilateral if sides are zero", {
|
|
17
|
+
expect_error(triangle(0, 0, 0))
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
test_that("sides may be floats", {
|
|
21
|
+
expect_is(triangle(0.5, 0.5, 0.5), "equilateral")
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
test_that("isosceles if last two sides are equal", {
|
|
25
|
+
expect_is(triangle(3, 4, 4), "isosceles")
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
test_that("isosceles if first two sides are equal", {
|
|
29
|
+
expect_is(triangle(4, 4, 3), "isosceles")
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
test_that("isosceles if first and last sides are equal", {
|
|
33
|
+
expect_is(triangle(4, 3, 4), "isosceles")
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
test_that("equilateral triangles are also isosceles", {
|
|
37
|
+
expect_is(triangle(4, 4, 4), "isosceles")
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
test_that("not isosceles if no sides are equal", {
|
|
41
|
+
expect_false(any("isosceles" %in% class(triangle(2, 3, 4))))
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
test_that("not isosceles if triangle inequality is violated", {
|
|
45
|
+
expect_error(triangle(1, 1, 3))
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
test_that("sides may be floats", {
|
|
49
|
+
expect_is(triangle(0.5, 0.4, 0.5), "isosceles")
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
test_that("scalene if no sides are equal", {
|
|
53
|
+
expect_is(triangle(5, 4, 6), "scalene")
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
test_that("not scalene if all sides are equal", {
|
|
57
|
+
expect_false(any("scalene" %in% class(triangle(4, 4, 4))))
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
test_that("not scalene if two sides are equal", {
|
|
61
|
+
expect_false(any("scalene" %in% class(triangle(4, 4, 3))))
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
test_that("not scalene if triangle inequality is violated", {
|
|
65
|
+
expect_error(triangle(7, 3, 2))
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
test_that("sides may be floats", {
|
|
69
|
+
expect_is(triangle(0.5, 0.4, 0.6), "scalene")
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
message("All tests passed for exercise: triangle")
|