Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add two-fer exercise #114

Merged
merged 5 commits into from
Feb 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@
"text_formatting"
]
},
{
"slug": "two-fer",
"uuid": "34f6e27c-9f14-4311-bc71-1f24958795a2",
"core": true,
"unlocked_by": null,
"difficulty": 1,
"topics": [
"strings"
]
},
{
"slug": "leap",
"uuid": "4be11d9f-db6a-4edd-af35-7d33d2dc9c0f",
Expand Down Expand Up @@ -368,8 +378,8 @@
"unlocked_by": null,
"difficulty": 1,
"topics": [
"strings",
"filtering"
"filtering",
"strings"
]
}
]
Expand Down
2 changes: 1 addition & 1 deletion exercises/acronym/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Help generate some jargon by writing a program that converts a long name
like Portable Network Graphics to its acronym (PNG).

## Installation
See [this guide](https://github.com/exercism/xr/blob/master/docs/INSTALLATION.md) for instructions on how to setup your local R environment.
See [this guide](https://exercism.io/tracks/r/installation) for instructions on how to setup your local R environment.

## How to implement your solution
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.
Expand Down
2 changes: 0 additions & 2 deletions exercises/bob/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ anything.

He answers 'Whatever.' to anything else.

Bob's conversational partner is a purist when it comes to written communication and always follows normal rules regarding sentence punctuation in English.

## Installation
See [this guide](https://exercism.io/tracks/r/installation) for instructions on how to setup your local R environment.

Expand Down
51 changes: 24 additions & 27 deletions exercises/crypto-square/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,11 @@ regarded as forming a rectangle when printed with intervening newlines.

For example, the sentence

```text
"If man was meant to stay on the ground, god would have given us roots."
```
> If man was meant to stay on the ground, god would have given us roots.

is normalized to:

```text
"ifmanwasmeanttostayonthegroundgodwouldhavegivenusroots"
```
> ifmanwasmeanttostayonthegroundgodwouldhavegivenusroots

The plaintext should be organized in to a rectangle. The size of the
rectangle (`r x c`) should be decided by the length of the message,
Expand All @@ -31,13 +27,13 @@ Our normalized text is 54 characters long, dictating a rectangle with
`c = 8` and `r = 7`:

```text
"ifmanwas"
"meanttos"
"tayonthe"
"groundgo"
"dwouldha"
"vegivenu"
"sroots "
ifmanwas
meanttos
tayonthe
groundgo
dwouldha
vegivenu
sroots
```

The coded message is obtained by reading down the columns going left to
Expand All @@ -46,30 +42,31 @@ right.
The message above is coded as:

```text
"imtgdvsfearwermayoogoanouuiontnnlvtwttddesaohghnsseoau"
imtgdvsfearwermayoogoanouuiontnnlvtwttddesaohghnsseoau
```

Output the encoded text in chunks that fill perfect rectangles `(r X c)`,
with `c` chunks of `r` length, separated by spaces. For phrases that are
`n` characters short of the perfect rectangle, pad each of the last `n`
chunks with a single trailing space.
Output the encoded text in chunks. Phrases that fill perfect rectangles
`(r X c)` should be output `c` chunks of `r` length, separated by spaces.
Phrases that do not fill perfect rectangles will have `n` empty spaces.
Those spaces should be distributed evenly, added to the end of the last
`n` chunks.

```text
"imtgdvs fearwer mayoogo anouuio ntnnlvt wttddes aohghn sseoau "
imtgdvs fearwer mayoogo anouuio ntnnlvt wttddes aohghn sseoau
```

Notice that were we to stack these, we could visually decode the
cyphertext back in to the original message:

```text
"imtgdvs"
"fearwer"
"mayoogo"
"anouuio"
"ntnnlvt"
"wttddes"
"aohghn "
"sseoau "
imtgdvs
fearwer
mayoogo
anouuio
ntnnlvt
wttddes
aohghn
sseoau
```

## Installation
Expand Down
7 changes: 3 additions & 4 deletions exercises/hamming/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,9 @@ The Hamming distance between these two DNA strands is 7.

# Implementation notes

The Hamming distance is only defined for sequences of equal length, so
an attempt to calculate it between sequences of different lengths should
not work. The general handling of this situation (e.g., raising an
exception vs returning a special value) may differ between languages.
The Hamming distance is only defined for sequences of equal length. This means
that based on the definition, each language could deal with getting sequences
of equal length differently.

## Installation
See [this guide](https://exercism.io/tracks/r/installation) for instructions on how to setup your local R environment.
Expand Down
8 changes: 3 additions & 5 deletions exercises/sieve/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ number.

The Sieve of Eratosthenes is a simple, ancient algorithm for finding all
prime numbers up to any given limit. It does so by iteratively marking as
composite (i.e. not prime) the multiples of each prime, starting with the
multiples of 2. It does not use any division or remainder operation.
composite (i.e. not prime) the multiples of each prime,
starting with the multiples of 2.

Create your range, starting at two and continuing up to and including the given limit. (i.e. [2, limit])

Expand All @@ -25,9 +25,7 @@ https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes

Notice that this is a very specific algorithm, and the tests don't check
that you've implemented the algorithm, only that you've come up with the
correct list of primes. A good first test is to check that you do not use
division or remainder operations (div, /, mod or % depending on the
language).
correct list of primes.

## Installation
See [this guide](https://exercism.io/tracks/r/installation) for instructions on how to setup your local R environment.
Expand Down
29 changes: 29 additions & 0 deletions exercises/two-fer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Two Fer

`Two-fer` or `2-fer` is short for two for one. One for you and one for me.

```text
"One for X, one for me."
```

When X is a name or "you".

If the given name is "Alice", the result should be "One for Alice, one for me."
If no name is given, the result should be "One for you, one for me."


## Installation
See [this guide](https://exercism.io/tracks/r/installation) for instructions on how to setup your local R environment.

## How to implement your solution
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.

## How to run tests
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`.

## Source

[https://en.wikipedia.org/wiki/Two-fer](https://en.wikipedia.org/wiki/Two-fer)

## Submitting Incomplete Solutions
It's possible to submit an incomplete solution so you can see how others have completed the exercise.
3 changes: 3 additions & 0 deletions exercises/two-fer/example.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
two_fer <- function(input = "you") {
sprintf("One for %s, one for me.", input)
}
18 changes: 18 additions & 0 deletions exercises/two-fer/test_two-fer.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
source("./two-fer.R")
library(testthat)

context("two-fer")

test_that("Abbreviate a phrase", {
expect_equal(two_fer(), "One for you, one for me.")
})

test_that("Abbreviate a phrase", {
expect_equal(two_fer("Alice"), "One for Alice, one for me.")
})

test_that("Abbreviate a phrase", {
expect_equal(two_fer("Bob"), "One for Bob, one for me.")
})

message("All tests passed for exercise: two-fer")
3 changes: 3 additions & 0 deletions exercises/two-fer/two-fer.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
two_fer <- function(input) {

}