summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--go.mod2
-rw-r--r--go/complex-numbers/.exercism/config.json19
-rw-r--r--go/complex-numbers/.exercism/metadata.json1
-rw-r--r--go/complex-numbers/HELP.md40
-rw-r--r--go/complex-numbers/README.md44
-rw-r--r--go/complex-numbers/cases_test.go572
-rw-r--r--go/complex-numbers/complex_numbers.go72
-rw-r--r--go/complex-numbers/complex_numbers_test.go134
-rw-r--r--go/complex-numbers/go.mod3
-rw-r--r--go/lasagna/.exercism/config.json25
-rw-r--r--go/lasagna/.exercism/metadata.json1
-rw-r--r--go/lasagna/HELP.md40
-rw-r--r--go/lasagna/HINTS.md44
-rw-r--r--go/lasagna/README.md151
-rw-r--r--go/lasagna/go.mod3
-rw-r--r--go/lasagna/lasagna.go19
-rw-r--r--go/lasagna/lasagna_test.go94
-rw-r--r--go/luhn/luhn.go2
-rw-r--r--go/robot-name/robot_name.go4
-rw-r--r--go/run-length-encoding/.exercism/config.json32
-rw-r--r--go/run-length-encoding/.exercism/metadata.json1
-rw-r--r--go/run-length-encoding/HELP.md40
-rw-r--r--go/run-length-encoding/README.md50
-rw-r--r--go/run-length-encoding/cases_test.go89
-rw-r--r--go/run-length-encoding/go.mod3
-rw-r--r--go/run-length-encoding/run_length_encoding.go60
-rw-r--r--go/run-length-encoding/run_length_encoding_test.go53
-rw-r--r--rust/hello-world/src/lib.rs2
-rw-r--r--rust/lucians-luscious-lasagna/.exercism/config.json20
-rw-r--r--rust/lucians-luscious-lasagna/.exercism/metadata.json1
-rw-r--r--rust/lucians-luscious-lasagna/.gitignore8
-rw-r--r--rust/lucians-luscious-lasagna/Cargo.toml4
-rw-r--r--rust/lucians-luscious-lasagna/HELP.md85
-rw-r--r--rust/lucians-luscious-lasagna/HINTS.md31
-rw-r--r--rust/lucians-luscious-lasagna/README.md159
-rw-r--r--rust/lucians-luscious-lasagna/src/lib.rs19
-rw-r--r--rust/lucians-luscious-lasagna/tests/lucians-luscious-lasagna.rs39
37 files changed, 1961 insertions, 5 deletions
diff --git a/go.mod b/go.mod
index 3050ff5..0f0b3a5 100644
--- a/go.mod
+++ b/go.mod
@@ -1,3 +1,3 @@
module dim13.org/exercism
-go 1.13
+go 1.19
diff --git a/go/complex-numbers/.exercism/config.json b/go/complex-numbers/.exercism/config.json
new file mode 100644
index 0000000..e9c806f
--- /dev/null
+++ b/go/complex-numbers/.exercism/config.json
@@ -0,0 +1,19 @@
+{
+ "authors": [
+ "eklatzer"
+ ],
+ "files": {
+ "solution": [
+ "complex_numbers.go"
+ ],
+ "test": [
+ "complex_numbers_test.go"
+ ],
+ "example": [
+ ".meta/example.go"
+ ]
+ },
+ "blurb": "Implement complex numbers.",
+ "source": "Wikipedia",
+ "source_url": "https://en.wikipedia.org/wiki/Complex_number"
+}
diff --git a/go/complex-numbers/.exercism/metadata.json b/go/complex-numbers/.exercism/metadata.json
new file mode 100644
index 0000000..ab9e31e
--- /dev/null
+++ b/go/complex-numbers/.exercism/metadata.json
@@ -0,0 +1 @@
+{"track":"go","exercise":"complex-numbers","id":"0b6d7784e1c847d29450f740f51abaa3","url":"https://exercism.org/tracks/go/exercises/complex-numbers","handle":"dim13","is_requester":true,"auto_approve":false} \ No newline at end of file
diff --git a/go/complex-numbers/HELP.md b/go/complex-numbers/HELP.md
new file mode 100644
index 0000000..cc1f090
--- /dev/null
+++ b/go/complex-numbers/HELP.md
@@ -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 complex_numbers.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 programming category on the forum](https://forum.exercism.org/c/programming/5)
+- 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) \ No newline at end of file
diff --git a/go/complex-numbers/README.md b/go/complex-numbers/README.md
new file mode 100644
index 0000000..ea1288c
--- /dev/null
+++ b/go/complex-numbers/README.md
@@ -0,0 +1,44 @@
+# Complex Numbers
+
+Welcome to Complex Numbers on Exercism's Go Track.
+If you need help running the tests or submitting your code, check out `HELP.md`.
+
+## Instructions
+
+A complex number is a number in the form `a + b * i` where `a` and `b` are real and `i` satisfies `i^2 = -1`.
+
+`a` is called the real part and `b` is called the imaginary part of `z`.
+The conjugate of the number `a + b * i` is the number `a - b * i`.
+The absolute value of a complex number `z = a + b * i` is a real number `|z| = sqrt(a^2 + b^2)`. The square of the absolute value `|z|^2` is the result of multiplication of `z` by its complex conjugate.
+
+The sum/difference of two complex numbers involves adding/subtracting their real and imaginary parts separately:
+`(a + i * b) + (c + i * d) = (a + c) + (b + d) * i`,
+`(a + i * b) - (c + i * d) = (a - c) + (b - d) * i`.
+
+Multiplication result is by definition
+`(a + i * b) * (c + i * d) = (a * c - b * d) + (b * c + a * d) * i`.
+
+The reciprocal of a non-zero complex number is
+`1 / (a + i * b) = a/(a^2 + b^2) - b/(a^2 + b^2) * i`.
+
+Dividing a complex number `a + i * b` by another `c + i * d` gives:
+`(a + i * b) / (c + i * d) = (a * c + b * d)/(c^2 + d^2) + (b * c - a * d)/(c^2 + d^2) * i`.
+
+Raising e to a complex exponent can be expressed as `e^(a + i * b) = e^a * e^(i * b)`, the last term of which is given by Euler's formula `e^(i * b) = cos(b) + i * sin(b)`.
+
+Implement the following operations:
+
+- addition, subtraction, multiplication and division of two complex numbers,
+- conjugate, absolute value, exponent of a given complex number.
+
+Assume the programming language you are using does not have an implementation of complex numbers.
+
+## Source
+
+### Created by
+
+- @eklatzer
+
+### Based on
+
+Wikipedia - https://en.wikipedia.org/wiki/Complex_number \ No newline at end of file
diff --git a/go/complex-numbers/cases_test.go b/go/complex-numbers/cases_test.go
new file mode 100644
index 0000000..b95890a
--- /dev/null
+++ b/go/complex-numbers/cases_test.go
@@ -0,0 +1,572 @@
+package complexnumbers
+
+// Source: exercism/problem-specifications
+// Commit: 24a7bfa Add exponential resulting in a number with real and imaginary part (#2052)
+
+type complexNumber struct {
+ a float64
+ b float64
+}
+
+var realTestCases = []struct {
+ description string
+ in complexNumber
+ want float64
+}{
+ {
+ description: "Real part of a purely real number",
+ in: complexNumber{
+ a: 1.000000,
+ b: 0.000000,
+ },
+ want: 1.000000,
+ },
+ {
+ description: "Real part of a purely imaginary number",
+ in: complexNumber{
+ a: 0.000000,
+ b: 1.000000,
+ },
+ want: 0.000000,
+ },
+ {
+ description: "Real part of a number with real and imaginary part",
+ in: complexNumber{
+ a: 1.000000,
+ b: 2.000000,
+ },
+ want: 1.000000,
+ },
+}
+
+var imaginaryTestCases = []struct {
+ description string
+ in complexNumber
+ want float64
+}{
+ {
+ description: "Imaginary part of a purely real number",
+ in: complexNumber{
+ a: 1.000000,
+ b: 0.000000,
+ },
+ want: 0.000000,
+ },
+ {
+ description: "Imaginary part of a purely imaginary number",
+ in: complexNumber{
+ a: 0.000000,
+ b: 1.000000,
+ },
+ want: 1.000000,
+ },
+ {
+ description: "Imaginary part of a number with real and imaginary part",
+ in: complexNumber{
+ a: 1.000000,
+ b: 2.000000,
+ },
+ want: 2.000000,
+ },
+}
+
+var addTestCases = []struct {
+ description string
+ n1 complexNumber
+ n2 complexNumber
+ want complexNumber
+}{
+ {
+ description: "Add purely real numbers",
+ n1: complexNumber{
+ a: 1.000000,
+ b: 0.000000,
+ },
+ n2: complexNumber{
+ a: 2.000000,
+ b: 0.000000,
+ },
+ want: complexNumber{
+ a: 3.000000,
+ b: 0.000000,
+ },
+ },
+ {
+ description: "Add purely imaginary numbers",
+ n1: complexNumber{
+ a: 0.000000,
+ b: 1.000000,
+ },
+ n2: complexNumber{
+ a: 0.000000,
+ b: 2.000000,
+ },
+ want: complexNumber{
+ a: 0.000000,
+ b: 3.000000,
+ },
+ },
+ {
+ description: "Add numbers with real and imaginary part",
+ n1: complexNumber{
+ a: 1.000000,
+ b: 2.000000,
+ },
+ n2: complexNumber{
+ a: 3.000000,
+ b: 4.000000,
+ },
+ want: complexNumber{
+ a: 4.000000,
+ b: 6.000000,
+ },
+ },
+ {
+ description: "Add real number to complex number",
+ n1: complexNumber{
+ a: 1.000000,
+ b: 2.000000,
+ },
+ n2: complexNumber{
+ a: 5.000000,
+ b: 0.000000,
+ },
+ want: complexNumber{
+ a: 6.000000,
+ b: 2.000000,
+ },
+ },
+ {
+ description: "Add complex number to real number",
+ n1: complexNumber{
+ a: 5.000000,
+ b: 0.000000,
+ },
+ n2: complexNumber{
+ a: 1.000000,
+ b: 2.000000,
+ },
+ want: complexNumber{
+ a: 6.000000,
+ b: 2.000000,
+ },
+ },
+}
+
+var subtractTestCases = []struct {
+ description string
+ n1 complexNumber
+ n2 complexNumber
+ want complexNumber
+}{
+ {
+ description: "Subtract purely real numbers",
+ n1: complexNumber{
+ a: 1.000000,
+ b: 0.000000,
+ },
+ n2: complexNumber{
+ a: 2.000000,
+ b: 0.000000,
+ },
+ want: complexNumber{
+ a: -1.000000,
+ b: 0.000000,
+ },
+ },
+ {
+ description: "Subtract purely imaginary numbers",
+ n1: complexNumber{
+ a: 0.000000,
+ b: 1.000000,
+ },
+ n2: complexNumber{
+ a: 0.000000,
+ b: 2.000000,
+ },
+ want: complexNumber{
+ a: 0.000000,
+ b: -1.000000,
+ },
+ },
+ {
+ description: "Subtract numbers with real and imaginary part",
+ n1: complexNumber{
+ a: 1.000000,
+ b: 2.000000,
+ },
+ n2: complexNumber{
+ a: 3.000000,
+ b: 4.000000,
+ },
+ want: complexNumber{
+ a: -2.000000,
+ b: -2.000000,
+ },
+ },
+ {
+ description: "Subtract real number from complex number",
+ n1: complexNumber{
+ a: 5.000000,
+ b: 7.000000,
+ },
+ n2: complexNumber{
+ a: 4.000000,
+ b: 0.000000,
+ },
+ want: complexNumber{
+ a: 1.000000,
+ b: 7.000000,
+ },
+ },
+ {
+ description: "Subtract complex number from real number",
+ n1: complexNumber{
+ a: 4.000000,
+ b: 0.000000,
+ },
+ n2: complexNumber{
+ a: 5.000000,
+ b: 7.000000,
+ },
+ want: complexNumber{
+ a: -1.000000,
+ b: -7.000000,
+ },
+ },
+}
+
+var divideTestCases = []struct {
+ description string
+ n1 complexNumber
+ n2 complexNumber
+ want complexNumber
+}{
+ {
+ description: "Divide purely real numbers",
+ n1: complexNumber{
+ a: 1.000000,
+ b: 0.000000,
+ },
+ n2: complexNumber{
+ a: 2.000000,
+ b: 0.000000,
+ },
+ want: complexNumber{
+ a: 0.500000,
+ b: 0.000000,
+ },
+ },
+ {
+ description: "Divide purely imaginary numbers",
+ n1: complexNumber{
+ a: 0.000000,
+ b: 1.000000,
+ },
+ n2: complexNumber{
+ a: 0.000000,
+ b: 2.000000,
+ },
+ want: complexNumber{
+ a: 0.500000,
+ b: 0.000000,
+ },
+ },
+ {
+ description: "Divide numbers with real and imaginary part",
+ n1: complexNumber{
+ a: 1.000000,
+ b: 2.000000,
+ },
+ n2: complexNumber{
+ a: 3.000000,
+ b: 4.000000,
+ },
+ want: complexNumber{
+ a: 0.440000,
+ b: 0.080000,
+ },
+ },
+ {
+ description: "Divide complex number by real number",
+ n1: complexNumber{
+ a: 10.000000,
+ b: 100.000000,
+ },
+ n2: complexNumber{
+ a: 10.000000,
+ b: 0.000000,
+ },
+ want: complexNumber{
+ a: 1.000000,
+ b: 10.000000,
+ },
+ },
+ {
+ description: "Divide real number by complex number",
+ n1: complexNumber{
+ a: 5.000000,
+ b: 0.000000,
+ },
+ n2: complexNumber{
+ a: 1.000000,
+ b: 1.000000,
+ },
+ want: complexNumber{
+ a: 2.500000,
+ b: -2.500000,
+ },
+ },
+}
+
+var multiplyTestCases = []struct {
+ description string
+ n1 complexNumber
+ n2 *complexNumber // if n2 is nil it is a multiplication with the factor
+ factor float64
+ want complexNumber
+}{
+ {
+ description: "Imaginary unit",
+ n1: complexNumber{
+ a: 0.000000,
+ b: 1.000000,
+ },
+ n2: &complexNumber{
+ a: 0.000000,
+ b: 1.000000,
+ },
+ factor: 0.000000,
+ want: complexNumber{
+ a: -1.000000,
+ b: 0.000000,
+ },
+ },
+ {
+ description: "Multiply purely real numbers",
+ n1: complexNumber{
+ a: 1.000000,
+ b: 0.000000,
+ },
+ n2: &complexNumber{
+ a: 2.000000,
+ b: 0.000000,
+ },
+ factor: 0.000000,
+ want: complexNumber{
+ a: 2.000000,
+ b: 0.000000,
+ },
+ },
+ {
+ description: "Multiply purely imaginary numbers",
+ n1: complexNumber{
+ a: 0.000000,
+ b: 1.000000,
+ },
+ n2: &complexNumber{
+ a: 0.000000,
+ b: 2.000000,
+ },
+ factor: 0.000000,
+ want: complexNumber{
+ a: -2.000000,
+ b: 0.000000,
+ },
+ },
+ {
+ description: "Multiply numbers with real and imaginary part",
+ n1: complexNumber{
+ a: 1.000000,
+ b: 2.000000,
+ },
+ n2: &complexNumber{
+ a: 3.000000,
+ b: 4.000000,
+ },
+ factor: 0.000000,
+ want: complexNumber{
+ a: -5.000000,
+ b: 10.000000,
+ },
+ },
+ {
+ description: "Multiply complex number by real number",
+ n1: complexNumber{
+ a: 2.000000,
+ b: 5.000000,
+ },
+
+ n2: nil,
+
+ factor: 5.000000,
+ want: complexNumber{
+ a: 10.000000,
+ b: 25.000000,
+ },
+ },
+ {
+ description: "Multiply real number by complex number",
+ n1: complexNumber{
+ a: 2.000000,
+ b: 5.000000,
+ },
+
+ n2: nil,
+
+ factor: 5.000000,
+ want: complexNumber{
+ a: 10.000000,
+ b: 25.000000,
+ },
+ },
+}
+
+var conjugateTestCases = []struct {
+ description string
+ in complexNumber
+ want complexNumber
+}{
+ {
+ description: "Conjugate a purely real number",
+ in: complexNumber{
+ a: 5.000000,
+ b: 0.000000,
+ },
+ want: complexNumber{
+ a: 5.000000,
+ b: 0.000000,
+ },
+ },
+ {
+ description: "Conjugate a purely imaginary number",
+ in: complexNumber{
+ a: 0.000000,
+ b: 5.000000,
+ },
+ want: complexNumber{
+ a: 0.000000,
+ b: -5.000000,
+ },
+ },
+ {
+ description: "Conjugate a number with real and imaginary part",
+ in: complexNumber{
+ a: 1.000000,
+ b: 1.000000,
+ },
+ want: complexNumber{
+ a: 1.000000,
+ b: -1.000000,
+ },
+ },
+}
+
+var absTestCases = []struct {
+ description string
+ in complexNumber
+ want float64
+}{
+ {
+ description: "Absolute value of a positive purely real number",
+ in: complexNumber{
+ a: 5.000000,
+ b: 0.000000,
+ },
+ want: 5.000000,
+ },
+ {
+ description: "Absolute value of a negative purely real number",
+ in: complexNumber{
+ a: -5.000000,
+ b: 0.000000,
+ },
+ want: 5.000000,
+ },
+ {
+ description: "Absolute value of a purely imaginary number with positive imaginary part",
+ in: complexNumber{
+ a: 0.000000,
+ b: 5.000000,
+ },
+ want: 5.000000,
+ },
+ {
+ description: "Absolute value of a purely imaginary number with negative imaginary part",
+ in: complexNumber{
+ a: 0.000000,
+ b: -5.000000,
+ },
+ want: 5.000000,
+ },
+ {
+ description: "Absolute value of a number with real and imaginary part",
+ in: complexNumber{
+ a: 3.000000,
+ b: 4.000000,
+ },
+ want: 5.000000,
+ },
+}
+
+var expTestCases = []struct {
+ description string
+ in complexNumber
+ want complexNumber
+}{
+ {
+ description: "Euler's identity/formula",
+ in: complexNumber{
+ a: 0.000000,
+ b: 3.141593,
+ },
+ want: complexNumber{
+ a: -1.000000,
+ b: 0.000000,
+ },
+ },
+ {
+ description: "Exponential of 0",
+ in: complexNumber{
+ a: 0.000000,
+ b: 0.000000,
+ },
+ want: complexNumber{
+ a: 1.000000,
+ b: 0.000000,
+ },
+ },
+ {
+ description: "Exponential of a purely real number",
+ in: complexNumber{
+ a: 1.000000,
+ b: 0.000000,
+ },
+ want: complexNumber{
+ a: 2.718282,
+ b: 0.000000,
+ },
+ },
+ {
+ description: "Exponential of a number with real and imaginary part",
+ in: complexNumber{
+ a: 0.693147,
+ b: 3.141593,
+ },
+ want: complexNumber{
+ a: -2.000000,
+ b: 0.000000,
+ },
+ },
+ {
+ description: "Exponential resulting in a number with real and imaginary part",
+ in: complexNumber{
+ a: 0.346574,
+ b: 0.785398,
+ },
+ want: complexNumber{
+ a: 1.000000,
+ b: 1.000000,
+ },
+ },
+}
diff --git a/go/complex-numbers/complex_numbers.go b/go/complex-numbers/complex_numbers.go
new file mode 100644
index 0000000..d06bd3d
--- /dev/null
+++ b/go/complex-numbers/complex_numbers.go
@@ -0,0 +1,72 @@
+package complexnumbers
+
+import "math"
+
+// Define the Number type here.
+type Number struct {
+ Re, Im float64
+}
+
+func (n Number) Real() float64 {
+ return n.Re
+}
+
+func (n Number) Imaginary() float64 {
+ return n.Im
+}
+
+func (n1 Number) Add(n2 Number) Number {
+ return Number{
+ Re: n1.Re + n2.Re,
+ Im: n1.Im + n2.Im,
+ }
+}
+
+func (n1 Number) Subtract(n2 Number) Number {
+ return Number{
+ Re: n1.Re - n2.Re,
+ Im: n1.Im - n2.Im,
+ }
+}
+
+func (n1 Number) Multiply(n2 Number) Number {
+ return Number{
+ Re: n1.Re*n2.Re - n1.Im*n2.Im,
+ Im: n1.Im*n2.Re + n1.Re*n2.Im,
+ }
+}
+
+func (n Number) Times(factor float64) Number {
+ return Number{
+ Re: n.Re * factor,
+ Im: n.Im * factor,
+ }
+}
+
+func (n1 Number) Divide(n2 Number) Number {
+ x := n2.Re*n2.Re + n2.Im*n2.Im
+ return Number{
+ Re: (n1.Re*n2.Re + n1.Im*n2.Im) / x,
+ Im: (n1.Im*n2.Re - n1.Re*n2.Im) / x,
+ }
+}
+
+func (n Number) Conjugate() Number {
+ return Number{
+ Re: n.Re,
+ Im: -n.Im,
+ }
+}
+
+func (n Number) Abs() float64 {
+ return math.Sqrt(n.Re*n.Re + n.Im*n.Im)
+}
+
+func (n Number) Exp() Number {
+ r := math.Exp(n.Re)
+ s, c := math.Sincos(n.Im)
+ return Number{
+ Re: r * c,
+ Im: r * s,
+ }
+}
diff --git a/go/complex-numbers/complex_numbers_test.go b/go/complex-numbers/complex_numbers_test.go
new file mode 100644
index 0000000..097f75a
--- /dev/null
+++ b/go/complex-numbers/complex_numbers_test.go
@@ -0,0 +1,134 @@
+package complexnumbers
+
+import (
+ "math"
+ "testing"
+)
+
+const floatEqualityThreshold = 1e-5
+
+func floatingPointEquals(got, want float64) bool {
+ absoluteDifferenceBelowThreshold := math.Abs(got-want) <= floatEqualityThreshold
+ relativeDifferenceBelowThreshold := math.Abs(got-want)/(math.Abs(got)+math.Abs(want)) <= floatEqualityThreshold
+ return absoluteDifferenceBelowThreshold || relativeDifferenceBelowThreshold
+}
+
+func TestNumber_Real(t *testing.T) {
+ for _, tt := range realTestCases {
+ t.Run(tt.description, func(t *testing.T) {
+ n := Number{tt.in.a, tt.in.b}
+ if got := n.Real(); !floatingPointEquals(got, tt.want) {
+ t.Errorf("Number%+v.Real() = %v, want %v", tt.in, got, tt.want)
+ }
+ })
+ }
+}
+
+func TestNumber_Imaginary(t *testing.T) {
+ for _, tt := range imaginaryTestCases {
+ t.Run(tt.description, func(t *testing.T) {
+ n := Number{tt.in.a, tt.in.b}
+ if got := n.Imaginary(); !floatingPointEquals(got, tt.want) {
+ t.Errorf("Number%+v.Imaginary() = %v, want %v", tt.in, got, tt.want)
+ }
+ })
+ }
+}
+
+func TestNumber_Add(t *testing.T) {
+ for _, tt := range addTestCases {
+ t.Run(tt.description, func(t *testing.T) {
+ n1 := Number{tt.n1.a, tt.n1.b}
+ n2 := Number{tt.n2.a, tt.n2.b}
+ if got := n1.Add(n2); !floatingPointEquals(got.Real(), tt.want.a) || !floatingPointEquals(got.Imaginary(), tt.want.b) {
+ t.Errorf("Number%+v.Add%+v\n got: %+v\nwant: %+v", tt.n1, tt.n2, got, tt.want)
+ }
+ })
+ }
+}
+
+func TestNumber_Subtract(t *testing.T) {
+ for _, tt := range subtractTestCases {
+ t.Run(tt.description, func(t *testing.T) {
+ n1 := Number{tt.n1.a, tt.n1.b}
+ n2 := Number{tt.n2.a, tt.n2.b}
+ if got := n1.Subtract(n2); !floatingPointEquals(got.Real(), tt.want.a) || !floatingPointEquals(got.Imaginary(), tt.want.b) {
+ t.Errorf("Number%+v.Subtract%+v\n got: %+v\nwant: %+v", tt.n1, tt.n2, got, tt.want)
+ }
+ })
+ }
+}
+
+func TestNumber_Multiply(t *testing.T) {
+ for _, tt := range multiplyTestCases {
+ t.Run(tt.description, func(t *testing.T) {
+ if tt.n2 == nil {
+ t.Skip("skipping tests with factor used withNumber.Times()")
+ }
+ n1 := Number{tt.n1.a, tt.n1.b}
+ n2 := Number{tt.n2.a, tt.n2.b}
+ if got := n1.Multiply(n2); !floatingPointEquals(got.Real(), tt.want.a) || !floatingPointEquals(got.Imaginary(), tt.want.b) {
+ t.Errorf("Number%+v.Multiply%+v\n got: %+v\nwant: %+v", tt.n1, tt.n2, got, tt.want)
+ }
+ })
+ }
+}
+
+func TestNumber_Times(t *testing.T) {
+ for _, tt := range multiplyTestCases {
+ t.Run(tt.description, func(t *testing.T) {
+ if tt.n2 != nil {
+ t.Skip("skipping tests with complex multiplier used withNumber.Multiply()")
+ }
+ n := Number{tt.n1.a, tt.n1.b}
+ if got := n.Times(tt.factor); !floatingPointEquals(got.Real(), tt.want.a) || !floatingPointEquals(got.Imaginary(), tt.want.b) {
+ t.Errorf("Number%+v.Times(%v)\n got: %+v\nwant: %+v", tt.n1, tt.factor, got, tt.want)
+ }
+ })
+ }
+}
+
+func TestNumber_Divide(t *testing.T) {
+ for _, tt := range divideTestCases {
+ t.Run(tt.description, func(t *testing.T) {
+ n1 := Number{tt.n1.a, tt.n1.b}
+ n2 := Number{tt.n2.a, tt.n2.b}
+ if got := n1.Divide(n2); !floatingPointEquals(got.Real(), tt.want.a) || !floatingPointEquals(got.Imaginary(), tt.want.b) {
+ t.Errorf("Number%+v.Divide%+v\n got: %+v\nwant: %+v", tt.n1, tt.n2, got, tt.want)
+ }
+ })
+ }
+}
+
+func TestNumber_Abs(t *testing.T) {
+ for _, tt := range absTestCases {
+ t.Run(tt.description, func(t *testing.T) {
+ n := Number{tt.in.a, tt.in.b}
+ if got := n.Abs(); !floatingPointEquals(got, tt.want) {
+ t.Errorf("Number.Abs%+v = %v, want %v", tt.in, got, tt.want)
+ }
+ })
+ }
+}
+
+func TestNumber_Conjugate(t *testing.T) {
+ for _, tt := range conjugateTestCases {
+ t.Run(tt.description, func(t *testing.T) {
+ n := Number{tt.in.a, tt.in.b}
+ if got := n.Conjugate(); !floatingPointEquals(got.Real(), tt.want.a) || !floatingPointEquals(got.Imaginary(), tt.want.b) {
+ t.Errorf("Number%+v.Conjugate()\n got: %+v\nwant: %+v", tt.in, got, tt.want)
+ }
+ })
+ }
+}
+
+func TestNumber_Exp(t *testing.T) {
+ for _, tt := range expTestCases {
+ t.Run(tt.description, func(t *testing.T) {
+ n := Number{tt.in.a, tt.in.b}
+ if got := n.Exp(); !floatingPointEquals(got.Real(), tt.want.a) || !floatingPointEquals(got.Imaginary(), tt.want.b) {
+ t.Errorf("Number%+v.Exp()\n got: %+v\nwant: %+v", tt.in, got, tt.want)
+ }
+ })
+ }
+}
diff --git a/go/complex-numbers/go.mod b/go/complex-numbers/go.mod
new file mode 100644
index 0000000..4a89806
--- /dev/null
+++ b/go/complex-numbers/go.mod
@@ -0,0 +1,3 @@
+module complex
+
+go 1.16
diff --git a/go/lasagna/.exercism/config.json b/go/lasagna/.exercism/config.json
new file mode 100644
index 0000000..5dbbba1
--- /dev/null
+++ b/go/lasagna/.exercism/config.json
@@ -0,0 +1,25 @@
+{
+ "blurb": "Learn about packages, functions, and variables by helping Gopher cook lasagna.",
+ "authors": [
+ "tehsphinx"
+ ],
+ "contributors": [
+ "ekingery",
+ "andrerfcsantos",
+ "bobtfish"
+ ],
+ "forked_from": [
+ "csharp/lucians-luscious-lasagna"
+ ],
+ "files": {
+ "solution": [
+ "lasagna.go"
+ ],
+ "test": [
+ "lasagna_test.go"
+ ],
+ "exemplar": [
+ ".meta/exemplar.go"
+ ]
+ }
+}
diff --git a/go/lasagna/.exercism/metadata.json b/go/lasagna/.exercism/metadata.json
new file mode 100644
index 0000000..d7bf30c
--- /dev/null
+++ b/go/lasagna/.exercism/metadata.json
@@ -0,0 +1 @@
+{"track":"go","exercise":"lasagna","id":"c21bf02bc9e64260ac06cc5378c47d50","url":"https://exercism.org/tracks/go/exercises/lasagna","handle":"dim13","is_requester":true,"auto_approve":false} \ No newline at end of file
diff --git a/go/lasagna/HELP.md b/go/lasagna/HELP.md
new file mode 100644
index 0000000..7396ee9
--- /dev/null
+++ b/go/lasagna/HELP.md
@@ -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 lasagna.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 programming category on the forum](https://forum.exercism.org/c/programming/5)
+- 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) \ No newline at end of file
diff --git a/go/lasagna/HINTS.md b/go/lasagna/HINTS.md
new file mode 100644
index 0000000..be4c9b1
--- /dev/null
+++ b/go/lasagna/HINTS.md
@@ -0,0 +1,44 @@
+# Hints
+
+## General
+
+- An [integer value][integers] can be defined as one or more consecutive digits.
+- If you see a `panic:` error when running the tests, this is because you have not implemented one of the functions (it should say which one) or you have left the boilerplate in place. You need to remove the `panic(...)` line from the supplied code and replace it with a real implementation.
+
+## 1. Define the expected oven time in minutes
+
+- You need to define a [constant][constants] and assign it the expected oven time in minutes.
+- If you see an `undefined: OvenTime` error then double check that you have the constant defined.
+- If you see an `invalid operation: got != tt.expected (mismatched types float64 and int)` error then you have likely put a decimal point into the `OvenTime` causing Go to infer the type as a floating point number. Remove the decimal and the type will be inferred as an `int`.
+- If you see a `syntax error: non-declaration statement outside function body` error then it is likely that you forgot the `const` keyword.
+- If you see a `syntax error: unexpected :=, expecting =` error then you are likely trying to assign the constant using `:=` like a variable; constants are assigned using `=` not `:=`.
+
+## 2. Calculate the remaining oven time in minutes
+
+- You need to define a [function][functions] with a single parameter.
+- You have to [explicitly return an integer][return] from a function.
+- The function's parameter is an [integer][integers].
+- You can [call][calls] one of the other functions you've defined previously.
+- You can use the [mathematical operator for subtraction][operators] to subtract values.
+
+## 3. Calculate the preparation time in minutes
+
+- You need to define a [function][functions] with a single parameter.
+- You have to [explicitly return an integer][return] from a function.
+- The function's parameter is an [integer][integers].
+- You can use the [mathematical operator for multiplication][operators] to multiply values.
+
+## 4. Calculate the elapsed working time in minutes
+
+- You need to define a [function][functions] with two parameters.
+- You have to [explicitly return an integer][return] from a function.
+- The function's parameter is an [integer][integers].
+- You can [call][calls] one of the other functions you've defined previously.
+- You can use the [mathematical operator for addition][operators] to add values.
+
+[functions]: https://tour.golang.org/basics/4
+[return]: https://golang.org/ref/spec#Return_statements
+[operators]: https://golang.org/ref/spec#Operators
+[integers]: https://golang.org/ref/spec#Integer_literals
+[calls]: https://golang.org/ref/spec#Calls
+[constants]: https://tour.golang.org/basics/15 \ No newline at end of file
diff --git a/go/lasagna/README.md b/go/lasagna/README.md
new file mode 100644
index 0000000..3a4b0c4
--- /dev/null
+++ b/go/lasagna/README.md
@@ -0,0 +1,151 @@
+# Gopher's Gorgeous Lasagna
+
+Welcome to Gopher's Gorgeous Lasagna on Exercism's Go Track.
+If you need help running the tests or submitting your code, check out `HELP.md`.
+If you get stuck on the exercise, check out `HINTS.md`, but try and solve it without using those first :)
+
+## Introduction
+
+[Go](https://golang.org) is a statically typed, compiled programming language.
+This exercise introduces three major language features: Packages, Functions, and Variables.
+
+## Packages
+
+Go applications are organized in packages.
+A package is a collection of source files located in the same directory.
+All source files in a directory must share the same package name.
+When a package is imported, only entities (functions, types, variables, constants) whose names start with a capital letter can be used / accessed.
+The recommended style of naming in Go is that identifiers will be named using `camelCase`, except for those meant to be accessible across packages which should be `PascalCase`.
+
+```go
+package lasagna
+```
+
+## Variables
+
+Go is statically-typed, which means all variables [must have a defined type](https://en.wikipedia.org/wiki/Type_system) at compile-time.
+
+Variables can be defined by explicitly specifying a type:
+
+```go
+var explicit int // Explicitly typed
+```
+
+You can also use an initializer, and the compiler will assign the variable type to match the type of the initializer.
+
+```go
+implicit := 10 // Implicitly typed as an int
+```
+
+Once declared, variables can be assigned values using the `=` operator.
+Once declared, a variable's type can never change.
+
+```go
+count := 1 // Assign initial value
+count = 2 // Update to new value
+
+count = false // This throws a compiler error due to assigning a non `int` type
+```
+
+## Constants
+
+Constants hold a piece of data just like variables, but their value cannot change during the execution of the program.
+
+Constants are defined using the `const` keyword and can be numbers, characters, strings or booleans:
+
+```go
+const Age = 21 // Defines a numeric constant 'Age' with the value of 21
+```
+
+## Functions
+
+Go functions accept zero or more parameters.
+Parameters must be explicitly typed, there is no type inference.
+
+Values are returned from functions using the `return` keyword.
+
+A function is invoked by specifying the function name and passing arguments for each of the function's parameters.
+
+Note that Go supports two types of comments.
+Single line comments are preceded by `//` and multiline comments are inserted between `/*` and `*/`.
+
+```go
+package greeting
+
+// Hello is a public function.
+func Hello (name string) string {
+ return hi(name)
+}
+
+// hi is a private function.
+func hi (name string) string {
+ return "hi " + name
+}
+```
+
+## Instructions
+
+In this exercise you're going to write some code to help you cook a brilliant lasagna from your favorite cooking book.
+
+You have four tasks, all related to the time spent cooking the lasagna.
+
+## 1. Define the expected oven time in minutes
+
+Define the `OvenTime` constant with how many minutes the lasagna should be in the oven. According to the cooking book, the expected oven time in minutes is 40:
+
+```go
+OvenTime
+// => 40
+```
+
+## 2. Calculate the remaining oven time in minutes
+
+Define the `RemainingOvenTime()` function that takes the actual minutes the lasagna has been in the oven as a parameter and returns how many minutes the lasagna still has to remain in the oven, based on the expected oven time in minutes from the previous task.
+
+```go
+func RemainingOvenTime(actual int) int {
+ // TODO
+}
+
+RemainingOvenTime(30)
+// => 10
+```
+
+## 3. Calculate the preparation time in minutes
+
+Define the `PreparationTime` function that takes the number of layers you added to the lasagna as a parameter and returns how many minutes you spent preparing the lasagna, assuming each layer takes you 2 minutes to prepare.
+
+```go
+func PreparationTime(numberOfLayers int) int {
+ // TODO
+}
+
+PreparationTime(2)
+// => 4
+```
+
+## 4. Calculate the elapsed working time in minutes
+
+Define the `ElapsedTime` function that takes two parameters: the first parameter is the number of layers you added to the lasagna, and the second parameter is the number of minutes the lasagna has been in the oven.
+The function should return how many minutes in total you've worked on cooking the lasagna, which is the sum of the preparation time in minutes, and the time in minutes the lasagna has spent in the oven at the moment.
+
+```go
+func ElapsedTime(numberOfLayers, actualMinutesInOven int) int {
+ // TODO
+}
+
+ElapsedTime(3, 20)
+// => 26
+```
+
+## Source
+
+### Created by
+
+- @tehsphinx
+
+### Contributed to by
+
+- @ekingery
+- @andrerfcsantos
+- @bobtfish \ No newline at end of file
diff --git a/go/lasagna/go.mod b/go/lasagna/go.mod
new file mode 100644
index 0000000..0d1c4ed
--- /dev/null
+++ b/go/lasagna/go.mod
@@ -0,0 +1,3 @@
+module lasagna
+
+go 1.16
diff --git a/go/lasagna/lasagna.go b/go/lasagna/lasagna.go
new file mode 100644
index 0000000..5c1fbad
--- /dev/null
+++ b/go/lasagna/lasagna.go
@@ -0,0 +1,19 @@
+package lasagna
+
+// TODO: define the 'OvenTime' constant
+const OvenTime = 40
+
+// RemainingOvenTime returns the remaining minutes based on the `actual` minutes already in the oven.
+func RemainingOvenTime(actualMinutesInOven int) int {
+ return OvenTime - actualMinutesInOven
+}
+
+// PreparationTime calculates the time needed to prepare the lasagna based on the amount of layers.
+func PreparationTime(numberOfLayers int) int {
+ return numberOfLayers * 2
+}
+
+// ElapsedTime calculates the time elapsed cooking the lasagna. This time includes the preparation time and the time the lasagna is baking in the oven.
+func ElapsedTime(numberOfLayers, actualMinutesInOven int) int {
+ return PreparationTime(numberOfLayers) + actualMinutesInOven
+}
diff --git a/go/lasagna/lasagna_test.go b/go/lasagna/lasagna_test.go
new file mode 100644
index 0000000..9ed503b
--- /dev/null
+++ b/go/lasagna/lasagna_test.go
@@ -0,0 +1,94 @@
+package lasagna
+
+import "testing"
+
+type lasagnaTests struct {
+ name string
+ layers, time, expected int
+}
+
+func TestOvenTime(t *testing.T) {
+ tests := []lasagnaTests{
+ {
+ name: "Calculates how many minutes the lasagna should be in the oven",
+ layers: 0,
+ time: 40,
+ expected: 40,
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ if got := OvenTime; got != tt.expected {
+ t.Errorf("OvenTime(%d) = %d; want %d", tt.expected, got, tt.expected)
+ }
+ })
+ }
+}
+
+func TestRemainingOvenTime(t *testing.T) {
+ tests := []lasagnaTests{
+ {
+ name: "Remaining minutes in oven",
+ layers: 0,
+ time: 15,
+ expected: 25,
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ if got := RemainingOvenTime(tt.time); got != tt.expected {
+ t.Errorf("RemainingOvenTime(%d) = %d; want %d", tt.time, got, tt.expected)
+ }
+ })
+ }
+
+}
+func TestPreparationTime(t *testing.T) {
+ tests := []lasagnaTests{
+ {
+ name: "Preparation time in minutes for one layer",
+ layers: 1,
+ time: 0,
+ expected: 2,
+ },
+ {
+ name: "Preparation time in minutes for multiple layers",
+ layers: 4,
+ time: 0,
+ expected: 8,
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ if got := PreparationTime(tt.layers); got != tt.expected {
+ t.Errorf("PreparationTime(%d) = %d; want %d", tt.layers, got, tt.expected)
+ }
+ })
+
+ }
+}
+
+func TestElapsedTime(t *testing.T) {
+ tests := []lasagnaTests{
+ {
+ name: "Total time in minutes for one layer",
+ layers: 1,
+ time: 30,
+ expected: 32,
+ },
+ {
+ name: "Total time in minutes for multiple layers",
+ layers: 4,
+ time: 8,
+ expected: 16,
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ if got := ElapsedTime(tt.layers, tt.time); got != tt.expected {
+ t.Errorf("ElapsedTime(%d, %d) = %d; want %d", tt.layers, tt.time, got, tt.expected)
+ }
+ })
+
+ }
+}
diff --git a/go/luhn/luhn.go b/go/luhn/luhn.go
index c11cde3..5da01f7 100644
--- a/go/luhn/luhn.go
+++ b/go/luhn/luhn.go
@@ -38,5 +38,5 @@ func Valid(s string) bool {
func AddCheck(s string) string {
sum := chksum(normalize(s + "9"))
n := 9 - sum%10
- return s + string('0'+n)
+ return s + string('0'+rune(n))
}
diff --git a/go/robot-name/robot_name.go b/go/robot-name/robot_name.go
index 6230e1c..2cf4a60 100644
--- a/go/robot-name/robot_name.go
+++ b/go/robot-name/robot_name.go
@@ -13,8 +13,8 @@ type Robot struct {
name string
}
-func randLetter() string { return string('A' + rand.Intn(26)) }
-func randNumber() string { return string('0' + rand.Intn(10)) }
+func randLetter() string { return string('A' + rune(rand.Intn(26))) }
+func randNumber() string { return string('0' + rune(rand.Intn(10))) }
func newName() string {
return randLetter() + randLetter() +
diff --git a/go/run-length-encoding/.exercism/config.json b/go/run-length-encoding/.exercism/config.json
new file mode 100644
index 0000000..9c9538f
--- /dev/null
+++ b/go/run-length-encoding/.exercism/config.json
@@ -0,0 +1,32 @@
+{
+ "blurb": "Implement run-length encoding and decoding.",
+ "authors": [
+ "MatForsberg"
+ ],
+ "contributors": [
+ "bitfield",
+ "ekingery",
+ "ferhatelmas",
+ "hilary",
+ "ilmanzo",
+ "leenipper",
+ "sebito91",
+ "eklatzer"
+ ],
+ "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"
+}
diff --git a/go/run-length-encoding/.exercism/metadata.json b/go/run-length-encoding/.exercism/metadata.json
new file mode 100644
index 0000000..dd34cf8
--- /dev/null
+++ b/go/run-length-encoding/.exercism/metadata.json
@@ -0,0 +1 @@
+{"track":"go","exercise":"run-length-encoding","id":"36e9ecb416fc40eaa771f9d3f44c8ef1","url":"https://exercism.org/tracks/go/exercises/run-length-encoding","handle":"dim13","is_requester":true,"auto_approve":false} \ No newline at end of file
diff --git a/go/run-length-encoding/HELP.md b/go/run-length-encoding/HELP.md
new file mode 100644
index 0000000..30de1a6
--- /dev/null
+++ b/go/run-length-encoding/HELP.md
@@ -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 programming category on the forum](https://forum.exercism.org/c/programming/5)
+- 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) \ No newline at end of file
diff --git a/go/run-length-encoding/README.md b/go/run-length-encoding/README.md
new file mode 100644
index 0000000..c48d31f
--- /dev/null
+++ b/go/run-length-encoding/README.md
@@ -0,0 +1,50 @@
+# 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
+- @eklatzer
+
+### Based on
+
+Wikipedia - https://en.wikipedia.org/wiki/Run-length_encoding \ No newline at end of file
diff --git a/go/run-length-encoding/cases_test.go b/go/run-length-encoding/cases_test.go
new file mode 100644
index 0000000..38266e9
--- /dev/null
+++ b/go/run-length-encoding/cases_test.go
@@ -0,0 +1,89 @@
+package encode
+
+// This is an auto-generated file. Do not change it manually. Run the generator to update the file.
+// See https://github.com/exercism/go#synchronizing-tests-and-instructions
+// Source: exercism/problem-specifications
+// Commit: a757698 run-length-encoding: 'lower case' -> 'lowercase' (#1708)
+
+type testCase struct {
+ description string
+ input string
+ expected string
+}
+
+// run-length encode a string
+var encodeTests = []testCase{
+ {
+ description: "empty string",
+ input: "",
+ expected: "",
+ },
+ {
+ description: "single characters only are encoded without count",
+ input: "XYZ",
+ expected: "XYZ",
+ },
+ {
+ description: "string with no single characters",
+ input: "AABBBCCCC",
+ expected: "2A3B4C",
+ },
+ {
+ description: "single characters mixed with repeated characters",
+ input: "WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWB",
+ expected: "12WB12W3B24WB",
+ },
+ {
+ description: "multiple whitespace mixed in string",
+ input: " hsqq qww ",
+ expected: "2 hs2q q2w2 ",
+ },
+ {
+ description: "lowercase characters",
+ input: "aabbbcccc",
+ expected: "2a3b4c",
+ },
+}
+
+// run-length decode a string
+var decodeTests = []testCase{
+ {
+ description: "empty string",
+ input: "",
+ expected: "",
+ },
+ {
+ description: "single characters only",
+ input: "XYZ",
+ expected: "XYZ",
+ },
+ {
+ description: "string with no single characters",
+ input: "2A3B4C",
+ expected: "AABBBCCCC",
+ },
+ {
+ description: "single characters with repeated characters",
+ input: "12WB12W3B24WB",
+ expected: "WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWB",
+ },
+ {
+ description: "multiple whitespace mixed in string",
+ input: "2 hs2q q2w2 ",
+ expected: " hsqq qww ",
+ },
+ {
+ description: "lowercase string",
+ input: "2a3b4c",
+ expected: "aabbbcccc",
+ },
+}
+
+// encode and then decode
+var encodeDecodeTests = []testCase{
+ {
+ description: "encode followed by decode gives original string",
+ input: "zzz ZZ zZ",
+ expected: "zzz ZZ zZ",
+ },
+}
diff --git a/go/run-length-encoding/go.mod b/go/run-length-encoding/go.mod
new file mode 100644
index 0000000..6689746
--- /dev/null
+++ b/go/run-length-encoding/go.mod
@@ -0,0 +1,3 @@
+module encode
+
+go 1.16
diff --git a/go/run-length-encoding/run_length_encoding.go b/go/run-length-encoding/run_length_encoding.go
new file mode 100644
index 0000000..07fdcd9
--- /dev/null
+++ b/go/run-length-encoding/run_length_encoding.go
@@ -0,0 +1,60 @@
+package encode
+
+import (
+ "fmt"
+ "strings"
+)
+
+func encodeLength(s string) (n int) {
+ var last rune
+ for _, c := range s {
+ if last == 0 {
+ last = c
+ }
+ if c != last {
+ break
+ }
+ n++
+ }
+ return n
+}
+
+func RunLengthEncode(input string) string {
+ var s strings.Builder
+ for len(input) != 0 {
+ n := encodeLength(input)
+ if n == 1 {
+ fmt.Fprintf(&s, "%c", input[0])
+ } else {
+ fmt.Fprintf(&s, "%d%c", n, input[0])
+ }
+ input = input[n:]
+ }
+ return s.String()
+}
+
+func decodeLength(s string) (number, count int) {
+ for _, c := range s {
+ if c >= '0' && c <= '9' {
+ number *= 10
+ number += int(c) - '0'
+ count++
+ } else {
+ break
+ }
+ }
+ if number == 0 {
+ number = 1
+ }
+ return number, count
+}
+
+func RunLengthDecode(input string) string {
+ var s strings.Builder
+ for len(input) > 0 {
+ n, c := decodeLength(input)
+ s.WriteString(strings.Repeat(string(input[c]), n))
+ input = input[c+1:]
+ }
+ return s.String()
+}
diff --git a/go/run-length-encoding/run_length_encoding_test.go b/go/run-length-encoding/run_length_encoding_test.go
new file mode 100644
index 0000000..2440d65
--- /dev/null
+++ b/go/run-length-encoding/run_length_encoding_test.go
@@ -0,0 +1,53 @@
+package encode
+
+import "testing"
+
+func TestRunLengthEncode(t *testing.T) {
+ for _, tc := range encodeTests {
+ t.Run(tc.description, func(t *testing.T) {
+ if actual := RunLengthEncode(tc.input); actual != tc.expected {
+ t.Errorf("RunLengthEncode(%q) = %q, want:%q", tc.input, actual, tc.expected)
+ }
+ })
+ }
+}
+func TestRunLengthDecode(t *testing.T) {
+ for _, tc := range decodeTests {
+ t.Run(tc.description, func(t *testing.T) {
+ if actual := RunLengthDecode(tc.input); actual != tc.expected {
+ t.Errorf("RunLengthDecode(%q) = %q, want:%q", tc.input, actual, tc.expected)
+ }
+ })
+ }
+}
+func TestRunLengthEncodeDecode(t *testing.T) {
+ for _, tc := range encodeDecodeTests {
+ t.Run(tc.description, func(t *testing.T) {
+ if actual := RunLengthDecode(RunLengthEncode(tc.input)); actual != tc.expected {
+ t.Errorf("RunLengthDecode(RunLengthEncode(%q)) = %q, want:%q", tc.input, actual, tc.expected)
+ }
+ })
+ }
+}
+
+func BenchmarkRunLengthEncode(b *testing.B) {
+ if testing.Short() {
+ b.Skip("skipping benchmark in short mode.")
+ }
+ for i := 0; i < b.N; i++ {
+ for _, test := range encodeTests {
+ RunLengthEncode(test.input)
+ }
+ }
+}
+
+func BenchmarkRunLengthDecode(b *testing.B) {
+ if testing.Short() {
+ b.Skip("skipping benchmark in short mode.")
+ }
+ for i := 0; i < b.N; i++ {
+ for _, test := range decodeTests {
+ RunLengthDecode(test.input)
+ }
+ }
+}
diff --git a/rust/hello-world/src/lib.rs b/rust/hello-world/src/lib.rs
index f147ab7..8f68273 100644
--- a/rust/hello-world/src/lib.rs
+++ b/rust/hello-world/src/lib.rs
@@ -1,5 +1,5 @@
// The &'static here means the return type has a static lifetime.
// This is a Rust feature that you don't need to worry about now.
pub fn hello() -> &'static str {
- "Goodbye, World!"
+ "Hello, World!"
}
diff --git a/rust/lucians-luscious-lasagna/.exercism/config.json b/rust/lucians-luscious-lasagna/.exercism/config.json
new file mode 100644
index 0000000..ab713a6
--- /dev/null
+++ b/rust/lucians-luscious-lasagna/.exercism/config.json
@@ -0,0 +1,20 @@
+{
+ "blurb": "Learn about the basics of Rust by following a lasagna recipe.",
+ "icon": "lasagna",
+ "authors": [
+ "coriolinus",
+ "ErikSchierboom"
+ ],
+ "files": {
+ "solution": [
+ "src/lib.rs",
+ "Cargo.toml"
+ ],
+ "test": [
+ "tests/lucians-luscious-lasagna.rs"
+ ],
+ "exemplar": [
+ ".meta/exemplar.rs"
+ ]
+ }
+}
diff --git a/rust/lucians-luscious-lasagna/.exercism/metadata.json b/rust/lucians-luscious-lasagna/.exercism/metadata.json
new file mode 100644
index 0000000..2c3cfe7
--- /dev/null
+++ b/rust/lucians-luscious-lasagna/.exercism/metadata.json
@@ -0,0 +1 @@
+{"track":"rust","exercise":"lucians-luscious-lasagna","id":"b409cb38deba48f4a34ea8d00a8395c7","url":"https://exercism.org/tracks/rust/exercises/lucians-luscious-lasagna","handle":"dim13","is_requester":true,"auto_approve":false} \ No newline at end of file
diff --git a/rust/lucians-luscious-lasagna/.gitignore b/rust/lucians-luscious-lasagna/.gitignore
new file mode 100644
index 0000000..db7f315
--- /dev/null
+++ b/rust/lucians-luscious-lasagna/.gitignore
@@ -0,0 +1,8 @@
+# Generated by Cargo
+# will have compiled files and executables
+/target/
+**/*.rs.bk
+
+# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
+# More information here http://doc.crates.io/guide.html#cargotoml-vs-cargolock
+Cargo.lock
diff --git a/rust/lucians-luscious-lasagna/Cargo.toml b/rust/lucians-luscious-lasagna/Cargo.toml
new file mode 100644
index 0000000..6f88766
--- /dev/null
+++ b/rust/lucians-luscious-lasagna/Cargo.toml
@@ -0,0 +1,4 @@
+[package]
+name = "lucians-luscious-lasagna"
+version = "0.1.0"
+edition = "2021"
diff --git a/rust/lucians-luscious-lasagna/HELP.md b/rust/lucians-luscious-lasagna/HELP.md
new file mode 100644
index 0000000..7857ff6
--- /dev/null
+++ b/rust/lucians-luscious-lasagna/HELP.md
@@ -0,0 +1,85 @@
+# Help
+
+## Running the tests
+
+Execute the tests with:
+
+```bash
+$ cargo test
+```
+
+All but the first test have been ignored. After you get the first test to
+pass, open the tests source file which is located in the `tests` directory
+and remove the `#[ignore]` flag from the next test and get the tests to pass
+again. Each separate test is a function with `#[test]` flag above it.
+Continue, until you pass every test.
+
+If you wish to run _only ignored_ tests without editing the tests source file, use:
+
+```bash
+$ cargo test -- --ignored
+```
+
+If you are using Rust 1.51 or later, you can run _all_ tests with
+
+```bash
+$ cargo test -- --include-ignored
+```
+
+To run a specific test, for example `some_test`, you can use:
+
+```bash
+$ cargo test some_test
+```
+
+If the specific test is ignored, use:
+
+```bash
+$ cargo test some_test -- --ignored
+```
+
+To learn more about Rust tests refer to the online [test documentation][rust-tests].
+
+[rust-tests]: https://doc.rust-lang.org/book/ch11-02-running-tests.html
+
+## Submitting your solution
+
+You can submit your solution using the `exercism submit src/lib.rs Cargo.toml` 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 [Rust track's documentation](https://exercism.org/docs/tracks/rust)
+- [Exercism's programming category on the forum](https://forum.exercism.org/c/programming/5)
+- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs)
+
+Should those resources not suffice, you could submit your (incomplete) solution to request mentoring.
+
+## Rust Installation
+
+Refer to the [exercism help page][help-page] for Rust installation and learning
+resources.
+
+## Submitting the solution
+
+Generally you should submit all files in which you implemented your solution (`src/lib.rs` in most cases). If you are using any external crates, please consider submitting the `Cargo.toml` file. This will make the review process faster and clearer.
+
+## Feedback, Issues, Pull Requests
+
+The GitHub [track repository][github] is the home for all of the Rust exercises. If you have feedback about an exercise, or want to help implement new exercises, head over there and create an issue. Members of the rust track team are happy to help!
+
+If you want to know more about Exercism, take a look at the [contribution guide].
+
+## Submitting Incomplete Solutions
+It's possible to submit an incomplete solution so you can see how others have completed the exercise.
+
+[help-page]: https://exercism.org/tracks/rust/learning
+[github]: https://github.com/exercism/rust
+[contribution guide]: https://exercism.org/docs/community/contributors \ No newline at end of file
diff --git a/rust/lucians-luscious-lasagna/HINTS.md b/rust/lucians-luscious-lasagna/HINTS.md
new file mode 100644
index 0000000..5d1a5ff
--- /dev/null
+++ b/rust/lucians-luscious-lasagna/HINTS.md
@@ -0,0 +1,31 @@
+# Hints
+
+## General
+
+- An integer literal can be defined as one or more consecutive digits.
+
+## 1. Define the expected oven time in minutes
+
+- You need to define a [function][functions] without any parameters.
+
+## 2. Calculate the remaining oven time in minutes
+
+- You need to define a [function][functions] with a single parameter.
+- You can use and refer to the previously defined item by its name.
+- The last expression in a function is [automatically returned][return-values] from the function; you don't have to explicitly indicate which value to return.
+- You can use the [mathematical operator for subtraction][operators] to subtract values.
+
+## 3. Calculate the preparation time in minutes
+
+- You need to define a [function][functions] with a single parameter.
+- You can use the [mathematical operator for multiplicaton][operators] to multiply values.
+
+## 4. Calculate the elapsed time in minutes
+
+- You need to define a [function][functions] with two parameters.
+- You can [call][functions] one of the other functions you've defined previously.
+- You can use the [mathematical operator for addition][operators] to add values.
+
+[functions]: https://doc.rust-lang.org/book/ch03-03-how-functions-work.html
+[return-values]: https://doc.rust-lang.org/book/ch03-03-how-functions-work.html#functions-with-return-values
+[operators]: https://doc.rust-lang.org/book/appendix-02-operators.html \ No newline at end of file
diff --git a/rust/lucians-luscious-lasagna/README.md b/rust/lucians-luscious-lasagna/README.md
new file mode 100644
index 0000000..4e40672
--- /dev/null
+++ b/rust/lucians-luscious-lasagna/README.md
@@ -0,0 +1,159 @@
+# Lucian's Luscious Lasagna
+
+Welcome to Lucian's Luscious Lasagna on Exercism's Rust Track.
+If you need help running the tests or submitting your code, check out `HELP.md`.
+If you get stuck on the exercise, check out `HINTS.md`, but try and solve it without using those first :)
+
+## Introduction
+
+In Rust, assigning a value to a name is referred to as a _binding_. Bindings are immutable unless declared with the `mut` keyword. As Rust is a statically-typed language, each binding has a type known at compile-time.
+
+Bindings are most commonly defined using the `let` keyword. Specifying a binding's type is optional for most bindings, as Rust's _type inference_ can usually infer the type based on their value. A binding looks like this:
+
+```rust
+// Automatically inferred type
+let fingers = 10;
+```
+
+Functions are _items_. Where bindings typically refer to a particular value, items refer to a unit of code organization, typically a function or a module, which is available throughout the lifetime of the program. A function automatically returns the result of its last expression. A function may have 0 or more parameters, which are bindings with a lifetime of the function call.
+
+Type inference is theoretically possible for functions, but is disabled as an intentional language design choice. While this means that you need to spend a little more time when writing code to specify precisely what a function's input and output types are, you save the time when you're reading the code, because all the input and output types are explicitly defined.
+
+```rust
+fn add(x: i32, y: i32) -> i32 {
+ x + y
+}
+```
+
+Invoking a function is done by specifying its name followed by parentheses. If the function requires parameters, an argument must be specified for each within the parentheses.
+
+```rust
+let five = add(2, 3);
+```
+
+If a binding's type cannot be inferred, the compiler will report an error. To fix this, add an explicit type annotation to the binding.
+
+```rust
+// Explicit type annotation
+let fingers: i32 = 10;
+```
+
+Items in Rust can be used before or after they are defined, because they have a static lifetime. Bindings, on the other hand, can only be used _after_ they have been defined. Using a binding before it has been defined results in a compile error.
+
+```rust
+fn main() {
+ // `fn add` hasn't yet been defined, but that's perfectly ok
+ dbg!(add(3, 4));
+}
+
+fn add(x: i32, y: i32) -> i32 {
+ x + y
+}
+```
+
+```rust
+// this won't compile; `a` is used before its binding is defined
+let b = a;
+let a = x + y;
+```
+
+Rust uses curly braces (`{}`) to define a scope. A binding defined within a scope can't escape from it.
+
+```rust
+let a = 1;
+dbg!(a); // 1
+{
+ // Here, we re-bind `a` to a new value, which is still immutable.
+ // This technique is called _shadowing_. The new binding is constrained to
+ // this anonymous scope. Outside this scope, the previous binding still
+ // applies.
+ let a = 2;
+ let b = 3;
+ dbg!(a, b); // 2, 3
+}
+// can't use `b` anymore because it is out of scope
+// dbg!(b);
+
+// The shadowed `a` in the inner scope above has fallen out of scope,
+// leaving us with our original binding.
+dbg!(a); // 1
+```
+
+Rust items are often organized in modules. Each crate is implicitly a module, but it can define inner sub-modules of arbitrary depth. A module groups related functionality and is defined using the `mod` keyword.
+
+```rust
+mod calc_i32 {
+ fn add(a: i32, b: i32) -> i32 { a + b }
+ fn sub(a: i32, b: i32) -> i32 { a - b }
+ fn mul(a: i32, b: i32) -> i32 { a * b }
+ fn div(a: i32, b: i32) -> i32 { a / b }
+}
+```
+
+Rust supports two types of comments. The keyword `//` indicates a single-line comment; everything following the keyword until the end of the line is ignored. The keywords `/*` and `*/` indicate a multi-line comment; everything within those two keywords is ignored. It is idiomatic and good practice to prefer single-line comments.
+
+Rust also supports doc-comments, which show up in the generated documentation produced by `cargo doc`. Outer doc comments are formed with the keyword `///`, which acts identically to the `//` keyword. They apply to the item which follows them, such as a function:
+
+```rust
+/// The `add` function produces the sum of its arguments.
+fn add(x: i32, y: i32) -> i32 { x + y }
+```
+
+Inner doc comments are formed with the keyword `//!`, which acts identically to the `//` keyword. They apply to the item enclosing them, such as a module:
+
+```rust
+mod my_cool_module {
+ //! This module is the bee's knees.
+}
+```
+
+Doc comments can be of arbitrary length and contain markdown, which is rendered into the generated documentation.
+
+## Instructions
+
+In this exercise you're going to write some code to help you cook a brilliant lasagna from your favorite cooking book.
+
+You have four tasks, all related to the time spent cooking the lasagna.
+
+## 1. Define the expected oven time in minutes
+
+Define the `expected_minutes_in_oven` binding to check how many minutes the lasagna should be in the oven. According to the cooking book, the expected oven time in minutes is 40:
+
+```rust
+expected_minutes_in_oven()
+// Returns: 40
+```
+
+## 2. Calculate the remaining oven time in minutes
+
+Define the `remaining_minutes_in_oven` function that takes the actual minutes the lasagna has been in the oven as a parameter and returns how many minutes the lasagna still has to remain in the oven, based on the expected oven time in minutes from the previous task.
+
+```rust
+remaining_minutes_in_oven(30)
+// Returns: 10
+```
+
+## 3. Calculate the preparation time in minutes
+
+Define the `preparation_time_in_minutes` function that takes the number of layers you added to the lasagna as a parameter and returns how many minutes you spent preparing the lasagna, assuming each layer takes you 2 minutes to prepare.
+
+```rust
+preparation_time_in_minutes(2)
+// Returns: 4
+```
+
+## 4. Calculate the elapsed time in minutes
+
+Define the `elapsed_time_in_minutes` function that takes two parameters: the first parameter is the number of layers you added to the lasagna, and the second parameter is the number of minutes the lasagna has been in the oven. The function should return how many minutes you've worked on cooking the lasagna, which is the sum of the preparation time in minutes, and the time in minutes the lasagna has spent in the oven at the moment.
+
+```rust
+elapsed_time_in_minutes(3, 20)
+// Returns: 26
+```
+
+## Source
+
+### Created by
+
+- @coriolinus
+- @ErikSchierboom \ No newline at end of file
diff --git a/rust/lucians-luscious-lasagna/src/lib.rs b/rust/lucians-luscious-lasagna/src/lib.rs
new file mode 100644
index 0000000..67e5ba3
--- /dev/null
+++ b/rust/lucians-luscious-lasagna/src/lib.rs
@@ -0,0 +1,19 @@
+// This stub file contains items that aren't used yet; feel free to remove this module attribute
+// to enable stricter warnings.
+#![allow(unused)]
+
+pub fn expected_minutes_in_oven() -> i32 {
+ return 40
+}
+
+pub fn remaining_minutes_in_oven(actual_minutes_in_oven: i32) -> i32 {
+ return expected_minutes_in_oven() - actual_minutes_in_oven
+}
+
+pub fn preparation_time_in_minutes(number_of_layers: i32) -> i32 {
+ return number_of_layers * 2
+}
+
+pub fn elapsed_time_in_minutes(number_of_layers: i32, actual_minutes_in_oven: i32) -> i32 {
+ return preparation_time_in_minutes(number_of_layers) + actual_minutes_in_oven
+}
diff --git a/rust/lucians-luscious-lasagna/tests/lucians-luscious-lasagna.rs b/rust/lucians-luscious-lasagna/tests/lucians-luscious-lasagna.rs
new file mode 100644
index 0000000..ea381d8
--- /dev/null
+++ b/rust/lucians-luscious-lasagna/tests/lucians-luscious-lasagna.rs
@@ -0,0 +1,39 @@
+use lucians_luscious_lasagna::{
+ elapsed_time_in_minutes, expected_minutes_in_oven, preparation_time_in_minutes,
+ remaining_minutes_in_oven,
+};
+
+#[test]
+fn expected_minutes_in_oven_is_correct() {
+ assert_eq!(40, expected_minutes_in_oven());
+}
+
+#[ignore]
+#[test]
+fn remaining_minutes_in_oven_after_fifteen_minutes() {
+ assert_eq!(15, remaining_minutes_in_oven(25));
+}
+
+#[ignore]
+#[test]
+fn preparation_time_in_minutes_for_one_layer() {
+ assert_eq!(2, preparation_time_in_minutes(1));
+}
+
+#[ignore]
+#[test]
+fn preparation_time_in_minutes_for_multiple_layers() {
+ assert_eq!(8, preparation_time_in_minutes(4));
+}
+
+#[ignore]
+#[test]
+fn elapsed_time_in_minutes_for_one_layer() {
+ assert_eq!(32, elapsed_time_in_minutes(1, 30));
+}
+
+#[ignore]
+#[test]
+fn elapsed_time_in_minutes_for_multiple_layers() {
+ assert_eq!(16, elapsed_time_in_minutes(4, 8));
+}