Initial upload

This commit is contained in:
2022-08-24 14:28:45 +02:00
parent c67653ddee
commit 57bc7b0289
370 changed files with 18479 additions and 0 deletions

View File

@@ -0,0 +1,31 @@
{
"blurb": "Implement run-length encoding and decoding.",
"authors": [
"MatForsberg"
],
"contributors": [
"bitfield",
"ekingery",
"ferhatelmas",
"hilary",
"ilmanzo",
"leenipper",
"sebito91"
],
"files": {
"solution": [
"run_length_encoding.go"
],
"test": [
"run_length_encoding_test.go"
],
"example": [
".meta/example.go"
],
"editor": [
"cases_test.go"
]
},
"source": "Wikipedia",
"source_url": "https://en.wikipedia.org/wiki/Run-length_encoding"
}

View File

@@ -0,0 +1 @@
{"track":"go","exercise":"run-length-encoding","id":"c65b116f8aba4eaf9baa3b129a348992","url":"https://exercism.org/tracks/go/exercises/run-length-encoding","handle":"halfdan","is_requester":true,"auto_approve":false}

View File

@@ -0,0 +1,40 @@
# Help
## Running the tests
To run the tests run the command `go test` from within the exercise directory.
If the test suite contains benchmarks, you can run these with the `--bench` and `--benchmem`
flags:
go test -v --bench . --benchmem
Keep in mind that each reviewer will run benchmarks on a different machine, with
different specs, so the results from these benchmark tests may vary.
## Submitting your solution
You can submit your solution using the `exercism submit run_length_encoding.go` command.
This command will upload your solution to the Exercism website and print the solution page's URL.
It's possible to submit an incomplete solution which allows you to:
- See how others have completed the exercise
- Request help from a mentor
## Need to get help?
If you'd like help solving the exercise, check the following pages:
- The [Go track's documentation](https://exercism.org/docs/tracks/go)
- [Exercism's support channel on gitter](https://gitter.im/exercism/support)
- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs)
Should those resources not suffice, you could submit your (incomplete) solution to request mentoring.
To get help if you're having trouble, you can use one of the following resources:
- [How to Write Go Code](https://golang.org/doc/code.html)
- [Effective Go](https://golang.org/doc/effective_go.html)
- [Go Resources](http://golang.org/help)
- [StackOverflow](http://stackoverflow.com/questions/tagged/go)

View File

@@ -0,0 +1,49 @@
# Run Length Encoding
Welcome to Run Length Encoding on Exercism's Go Track.
If you need help running the tests or submitting your code, check out `HELP.md`.
## Instructions
Implement run-length encoding and decoding.
Run-length encoding (RLE) is a simple form of data compression, where runs
(consecutive data elements) are replaced by just one data value and count.
For example we can represent the original 53 characters with only 13.
```text
"WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWB" -> "12WB12W3B24WB"
```
RLE allows the original data to be perfectly reconstructed from
the compressed data, which makes it a lossless data compression.
```text
"AABCCCDEEEE" -> "2AB3CD4E" -> "AABCCCDEEEE"
```
For simplicity, you can assume that the unencoded string will only contain
the letters A through Z (either lower or upper case) and whitespace. This way
data to be encoded will never contain any numbers and numbers inside data to
be decoded always represent the count for the following character.
## Source
### Created by
- @MatForsberg
### Contributed to by
- @bitfield
- @ekingery
- @ferhatelmas
- @hilary
- @ilmanzo
- @leenipper
- @sebito91
### Based on
Wikipedia - https://en.wikipedia.org/wiki/Run-length_encoding

View File

@@ -0,0 +1,42 @@
package encode
// Source: exercism/problem-specifications
// Commit: 1b7900e run-length-encoding: apply "input" policy
// Problem Specifications Version: 1.1.0
// run-length encode a string
var encodeTests = []struct {
input string
expected string
description string
}{
{"", "", "empty string"},
{"XYZ", "XYZ", "single characters only are encoded without count"},
{"AABBBCCCC", "2A3B4C", "string with no single characters"},
{"WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWB", "12WB12W3B24WB", "single characters mixed with repeated characters"},
{" hsqq qww ", "2 hs2q q2w2 ", "multiple whitespace mixed in string"},
{"aabbbcccc", "2a3b4c", "lowercase characters"},
}
// run-length decode a string
var decodeTests = []struct {
input string
expected string
description string
}{
{"", "", "empty string"},
{"XYZ", "XYZ", "single characters only"},
{"2A3B4C", "AABBBCCCC", "string with no single characters"},
{"12WB12W3B24WB", "WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWB", "single characters with repeated characters"},
{"2 hs2q q2w2 ", " hsqq qww ", "multiple whitespace mixed in string"},
{"2a3b4c", "aabbbcccc", "lower case string"},
}
// encode and then decode
var encodeDecodeTests = []struct {
input string
expected string
description string
}{
{"zzz ZZ zZ", "zzz ZZ zZ", "encode followed by decode gives original string"},
}

View File

@@ -0,0 +1,3 @@
module encode
go 1.13

View File

@@ -0,0 +1,9 @@
package encode
func RunLengthEncode(input string) string {
panic("Please implement the RunLengthEncode function")
}
func RunLengthDecode(input string) string {
panic("Please implement the RunLengthDecode function")
}

View File

@@ -0,0 +1,31 @@
package encode
import "testing"
func TestRunLengthEncode(t *testing.T) {
for _, test := range encodeTests {
if actual := RunLengthEncode(test.input); actual != test.expected {
t.Errorf("FAIL %s - RunLengthEncode(%s) = %q, expected %q.",
test.description, test.input, actual, test.expected)
}
t.Logf("PASS RunLengthEncode - %s", test.description)
}
}
func TestRunLengthDecode(t *testing.T) {
for _, test := range decodeTests {
if actual := RunLengthDecode(test.input); actual != test.expected {
t.Errorf("FAIL %s - RunLengthDecode(%s) = %q, expected %q.",
test.description, test.input, actual, test.expected)
}
t.Logf("PASS RunLengthDecode - %s", test.description)
}
}
func TestRunLengthEncodeDecode(t *testing.T) {
for _, test := range encodeDecodeTests {
if actual := RunLengthDecode(RunLengthEncode(test.input)); actual != test.expected {
t.Errorf("FAIL %s - RunLengthDecode(RunLengthEncode(%s)) = %q, expected %q.",
test.description, test.input, actual, test.expected)
}
t.Logf("PASS %s", test.description)
}
}