-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Colin Leach
committed
Dec 3, 2023
1 parent
ef61b67
commit e68579b
Showing
18 changed files
with
624 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# 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 collatz-conjecture.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) | ||
- The [Wren track's programming category on the forum](https://forum.exercism.org/c/programming/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). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# Collatz Conjecture | ||
|
||
Welcome to Collatz Conjecture on Exercism's Wren Track. | ||
If you need help running the tests or submitting your code, check out `HELP.md`. | ||
|
||
## Instructions | ||
|
||
The Collatz Conjecture or 3x+1 problem can be summarized as follows: | ||
|
||
Take any positive integer n. | ||
If n is even, divide n by 2 to get n / 2. | ||
If n is odd, multiply n by 3 and add 1 to get 3n + 1. | ||
Repeat the process indefinitely. | ||
The conjecture states that no matter which number you start with, you will always reach 1 eventually. | ||
|
||
Given a number n, return the number of steps required to reach 1. | ||
|
||
## Examples | ||
|
||
Starting with n = 12, the steps would be as follows: | ||
|
||
0. 12 | ||
1. 6 | ||
2. 3 | ||
3. 10 | ||
4. 5 | ||
5. 16 | ||
6. 8 | ||
7. 4 | ||
8. 2 | ||
9. 1 | ||
|
||
Resulting in 9 steps. | ||
So for input n = 12, the return value would be 9. | ||
|
||
## Source | ||
|
||
### Created by | ||
|
||
- @joshgoebel | ||
|
||
### Based on | ||
|
||
An unsolved problem in mathematics named after mathematician Lothar Collatz - https://en.wikipedia.org/wiki/3x_%2B_1_problem |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import "./collatz-conjecture" for Collatz | ||
import "wren-testie/testie" for Testie, Expect | ||
|
||
Testie.test("Collatz.steps()") { |do, skip| | ||
do.test("zero steps for one") { | ||
Expect.value(Collatz.steps(1)).toEqual(0) | ||
} | ||
|
||
do.test("divide if even") { | ||
Expect.value(Collatz.steps(16)).toEqual(4) | ||
} | ||
|
||
do.test("even and odd steps") { | ||
Expect.value(Collatz.steps(12)).toEqual(9) | ||
} | ||
|
||
do.test("large number of even and odd steps") { | ||
Expect.value(Collatz.steps(1000000)).toEqual(152) | ||
} | ||
|
||
do.test("zero is an error") { | ||
Expect.that { | ||
Collatz.steps(0) | ||
}.abortsWith("Only positive numbers are allowed") | ||
} | ||
|
||
do.test("negative value is an error") { | ||
Expect.that { | ||
Collatz.steps(-15) | ||
}.abortsWith("Only positive numbers are allowed") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
class Collatz { | ||
static steps(n) { | ||
if (n < 1) Fiber.abort("Only positive numbers are allowed") | ||
|
||
var steps = 0 | ||
while (n > 1) { | ||
n = (n % 2 == 0) ? n / 2 : 3 * n + 1 | ||
steps = steps + 1 | ||
} | ||
return steps | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# 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 darts.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) | ||
- The [Wren track's programming category on the forum](https://forum.exercism.org/c/programming/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). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Darts | ||
|
||
Welcome to Darts on Exercism's Wren Track. | ||
If you need help running the tests or submitting your code, check out `HELP.md`. | ||
|
||
## Instructions | ||
|
||
Write a function that returns the earned points in a single toss of a Darts game. | ||
|
||
[Darts][darts] is a game where players throw darts at a [target][darts-target]. | ||
|
||
In our particular instance of the game, the target rewards 4 different amounts of points, depending on where the dart lands: | ||
|
||
 | ||
|
||
- If the dart lands outside the target, player earns no points (0 points). | ||
- If the dart lands in the outer circle of the target, player earns 1 point. | ||
- If the dart lands in the middle circle of the target, player earns 5 points. | ||
- If the dart lands in the inner circle of the target, player earns 10 points. | ||
|
||
The outer circle has a radius of 10 units (this is equivalent to the total radius for the entire target), the middle circle a radius of 5 units, and the inner circle a radius of 1. | ||
Of course, they are all centered at the same point — that is, the circles are [concentric][] defined by the coordinates (0, 0). | ||
|
||
Write a function that given a point in the target (defined by its [Cartesian coordinates][cartesian-coordinates] `x` and `y`, where `x` and `y` are [real][real-numbers]), returns the correct amount earned by a dart landing at that point. | ||
|
||
## Credit | ||
|
||
The scoreboard image was created by [habere-et-dispertire][habere-et-dispertire] using [Inkscape][inkscape]. | ||
|
||
[darts]: https://en.wikipedia.org/wiki/Darts | ||
[darts-target]: https://en.wikipedia.org/wiki/Darts#/media/File:Darts_in_a_dartboard.jpg | ||
[concentric]: https://mathworld.wolfram.com/ConcentricCircles.html | ||
[cartesian-coordinates]: https://www.mathsisfun.com/data/cartesian-coordinates.html | ||
[real-numbers]: https://www.mathsisfun.com/numbers/real-numbers.html | ||
[habere-et-dispertire]: https://exercism.org/profiles/habere-et-dispertire | ||
[inkscape]: https://en.wikipedia.org/wiki/Inkscape | ||
|
||
## Source | ||
|
||
### Created by | ||
|
||
- @joshgoebel | ||
|
||
### Based on | ||
|
||
Inspired by an exercise created by a professor Della Paolera in Argentina |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import "./darts" for Darts | ||
import "wren-testie/testie" for Testie, Expect | ||
|
||
Testie.test("Darts") { |do, skip| | ||
do.test("Missed target") { | ||
Expect.value(Darts.score(-9, 9)).toEqual(0) | ||
} | ||
|
||
do.test("On the outer circle") { | ||
Expect.value(Darts.score(0, 10)).toEqual(1) | ||
} | ||
|
||
do.test("On the middle circle") { | ||
Expect.value(Darts.score(-5, 0)).toEqual(5) | ||
} | ||
|
||
do.test("On the inner circle") { | ||
Expect.value(Darts.score(0, -1)).toEqual(10) | ||
} | ||
|
||
do.test("Exactly on centre") { | ||
Expect.value(Darts.score(0, 0)).toEqual(10) | ||
} | ||
|
||
do.test("Near the centre") { | ||
Expect.value(Darts.score(-0.1, -0.1)).toEqual(10) | ||
} | ||
|
||
do.test("Just within the inner circle") { | ||
Expect.value(Darts.score(0.7, 0.7)).toEqual(10) | ||
} | ||
|
||
do.test("Just outside the inner circle") { | ||
Expect.value(Darts.score(0.8, -0.8)).toEqual(5) | ||
} | ||
|
||
do.test("Just within the middle circle") { | ||
Expect.value(Darts.score(-3.5, 3.5)).toEqual(5) | ||
} | ||
|
||
do.test("Just outside the middle circle") { | ||
Expect.value(Darts.score(-3.6, -3.6)).toEqual(1) | ||
} | ||
|
||
do.test("Just within the outer circle") { | ||
Expect.value(Darts.score(-7.0, 7.0)).toEqual(1) | ||
} | ||
|
||
do.test("Just outside the outer circle") { | ||
Expect.value(Darts.score(7.1, -7.1)).toEqual(0) | ||
} | ||
|
||
do.test("Asymmetric position between the inner and middle circles") { | ||
Expect.value(Darts.score(0.5, -4)).toEqual(5) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class Darts { | ||
static score(x,y) { | ||
var r_sq = x * x + y * y | ||
if (r_sq <= 1) return 10 | ||
if (r_sq <= 25) return 5 | ||
if (r_sq <= 100) return 1 | ||
return 0 | ||
} | ||
} |
Oops, something went wrong.