Skip to content

Commit

Permalink
wren examples
Browse files Browse the repository at this point in the history
  • Loading branch information
colinleach committed Jan 13, 2023
1 parent 3402608 commit 33e124d
Show file tree
Hide file tree
Showing 21 changed files with 690 additions and 7 deletions.
10 changes: 3 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ julia/killer-sudoku-helper/Untitled1.ipynb

python/Untitled.ipynb

wren/hello-world/package.wren

wren/hello-world/LICENSE

wren/hello-world/wren_modules/

wren/two-fer/wren_modules/
package.wren
LICENSE
wren_modules/
47 changes: 47 additions & 0 deletions wren/hamming/HELP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Help

## Running the tests

## Installing the test suite

Inside your exercise folder simply run:

```
$ wrenc package.wren install
```

## Running the tests

Execute the test suite with:

```
$ wrenc [spec-file]
```

Example:

```
$ wrenc hello-world.spec.wren
```

## Submitting your solution

You can submit your solution using the `exercism submit hamming.wren` 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 [Wren track's documentation](https://exercism.org/docs/tracks/wren)
- [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.

If you're having trouble with an exercise, feel free to ask for help in the [Wren Discord](https://discord.gg/VTzuWmBavH).
37 changes: 37 additions & 0 deletions wren/hamming/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Hamming

Welcome to Hamming on Exercism's Wren Track.
If you need help running the tests or submitting your code, check out `HELP.md`.

## Instructions

Calculate the Hamming Distance between two DNA strands.

Your body is made up of cells that contain DNA. Those cells regularly wear out and need replacing, which they achieve by dividing into daughter cells. In fact, the average human body experiences about 10 quadrillion cell divisions in a lifetime!

When cells divide, their DNA replicates too. Sometimes during this process mistakes happen and single pieces of DNA get encoded with the incorrect information. If we compare two strands of DNA and count the differences between them we can see how many mistakes occurred. This is known as the "Hamming Distance".

We read DNA using the letters C,A,G and T. Two strands might look like this:

GAGCCTACTAACGGGAT
CATCGTAATGACGGCCT
^ ^ ^ ^ ^ ^^

They have 7 differences, and therefore the Hamming Distance is 7.

The Hamming Distance is useful for lots of things in science, not just biology, so it's a nice phrase to be familiar with :)

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.

## Source

### Created by

- @joshgoebel

### Based on

The Calculating Point Mutations problem at Rosalind - http://rosalind.info/problems/hamm/
48 changes: 48 additions & 0 deletions wren/hamming/hamming.spec.wren
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import "./hamming" for Hamming
import "wren-testie/testie" for Testie, Expect

Testie.test("Hamming") { |do, skip|
do.test("empty strands") {
Expect.value(Hamming.compute("", "")).toEqual(0)
}

do.test("single letter identical strands") {
Expect.value(Hamming.compute("A", "A")).toEqual(0)
}

do.test("single letter different strands") {
Expect.value(Hamming.compute("G", "T")).toEqual(1)
}

do.test("long identical strands") {
Expect.value(Hamming.compute("GGACTGAAATCTG", "GGACTGAAATCTG")).toEqual(0)
}

do.test("long different strands") {
Expect.value(Hamming.compute("GGACGGATTCTG", "AGGACGGATTCT")).toEqual(9)
}

do.test("disallow first strand longer") {
Expect.that {
Hamming.compute("AATG", "AAA")
}.abortsWith("strands must be of equal length")
}

do.test("disallow second strand longer") {
Expect.that {
Hamming.compute("ATA", "AGTG")
}.abortsWith("strands must be of equal length")
}

do.test("disallow left empty strand") {
Expect.that {
Hamming.compute("", "G")
}.abortsWith("strands must be of equal length")
}

do.test("disallow right empty strand") {
Expect.that {
Hamming.compute("G", "")
}.abortsWith("strands must be of equal length")
}
}
13 changes: 13 additions & 0 deletions wren/hamming/hamming.wren
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class Hamming {
static compute(first, second) {
if (first.count != second.count) Fiber.abort("strands must be of equal length")

var result = 0
if (first != "") {
for (i in 0..first.count-1) {
if (first[i] != second[i]) result = result + 1
}
}
return result
}
}
47 changes: 47 additions & 0 deletions wren/high-scores/HELP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Help

## Running the tests

## Installing the test suite

Inside your exercise folder simply run:

```
$ wrenc package.wren install
```

## Running the tests

Execute the test suite with:

```
$ wrenc [spec-file]
```

Example:

```
$ wrenc hello-world.spec.wren
```

## Submitting your solution

You can submit your solution using the `exercism submit high-scores.wren` 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 [Wren track's documentation](https://exercism.org/docs/tracks/wren)
- [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.

If you're having trouble with an exercise, feel free to ask for help in the [Wren Discord](https://discord.gg/VTzuWmBavH).
20 changes: 20 additions & 0 deletions wren/high-scores/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# High Scores

Welcome to High Scores on Exercism's Wren Track.
If you need help running the tests or submitting your code, check out `HELP.md`.

## Instructions

Manage a game player's High Score list.

Your task is to build a high-score component of the classic Frogger game, one of the highest selling and addictive games of all time, and a classic of the arcade era. Your task is to write methods that return the highest score from the list, the last added score and the three highest scores.

## Source

### Created by

- @joshgoebel

### Based on

Tribute to the eighties' arcade game Frogger
67 changes: 67 additions & 0 deletions wren/high-scores/high-scores.spec.wren
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import "wren-testie/testie" for Testie, Expect
import "./high-scores" for HighScores

Testie.test("High scores") { |do, skip|
do.test("List of scores") {
var input = [30, 50, 20, 70]
Expect.value(HighScores.new(input).scores).toEqual([30, 50, 20, 70])
}

do.test("Latest score") {
var input = [100, 0, 90, 30]
Expect.value(HighScores.new(input).latest).toEqual(30)
}

do.test("Personal best") {
var input = [40, 100, 70]
Expect.value(HighScores.new(input).personalBest).toEqual(100)
}

do.describe("Top 3 scores") {
do.test("Personal top three from a list of scores") {
var input = [10, 30, 90, 30, 100, 20, 10, 0, 30, 40, 40, 70, 70]
Expect.value(HighScores.new(input).personalTopThree).toEqual([100, 90, 70])
}

do.test("Personal top highest to lowest") {
var input = [20, 10, 30]
Expect.value(HighScores.new(input).personalTopThree).toEqual([30, 20, 10])
}

do.test("Personal top when there is a tie") {
var input = [40, 20, 40, 30]
Expect.value(HighScores.new(input).personalTopThree).toEqual([40, 40, 30])
}

do.test("Personal top when there are less than 3") {
var input = [30, 70]
Expect.value(HighScores.new(input).personalTopThree).toEqual([70, 30])
}

do.test("Personal top when there is only one") {
var input = [40]
Expect.value(HighScores.new(input).personalTopThree).toEqual([40])
}
}

do.describe("Immutable") {
do.test("Latest score after personal top scores") {
var hs = HighScores.new([70, 50, 20, 30])
var top3 = hs.personalTopThree
Expect.value(hs.latest).toEqual(30)
}

do.test("Scores after personal top scores") {
var hs = HighScores.new([30, 50, 20, 70])
var top3 = hs.personalTopThree
Expect.value(hs.scores).toEqual([30, 50, 20, 70])
}

do.test("Altering the input list does not alter the scores") {
var input = [30, 50, 20, 70]
var hs = HighScores.new(input)
input.add(100)
Expect.value(hs.scores).toEqual([30, 50, 20, 70])
}
}
}
21 changes: 21 additions & 0 deletions wren/high-scores/high-scores.wren
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class HighScores {
construct new(input) {
_scores = input[0..-1]
}

scores = (input) { _scores = input }

scores { _scores }

latest { _scores[-1] }

personalBest {
var sorted = _scores[0..-1].sort()
return sorted[-1]
}

personalTopThree {
var sorted = _scores[0..-1].sort {|a, b| a > b}
return sorted.count > 2 ? sorted[0..2] : sorted
}
}
47 changes: 47 additions & 0 deletions wren/leap/HELP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Help

## Running the tests

## Installing the test suite

Inside your exercise folder simply run:

```
$ wrenc package.wren install
```

## Running the tests

Execute the test suite with:

```
$ wrenc [spec-file]
```

Example:

```
$ wrenc hello-world.spec.wren
```

## Submitting your solution

You can submit your solution using the `exercism submit leap.wren` 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 [Wren track's documentation](https://exercism.org/docs/tracks/wren)
- [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.

If you're having trouble with an exercise, feel free to ask for help in the [Wren Discord](https://discord.gg/VTzuWmBavH).
Loading

0 comments on commit 33e124d

Please sign in to comment.