Some solutions for the julia path
This commit is contained in:
23
julia/raindrops/.exercism/config.json
Normal file
23
julia/raindrops/.exercism/config.json
Normal file
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"authors": [
|
||||
"andrej-makarov-skrt"
|
||||
],
|
||||
"contributors": [
|
||||
"cmcaine",
|
||||
"SaschaMann"
|
||||
],
|
||||
"files": {
|
||||
"solution": [
|
||||
"raindrops.jl"
|
||||
],
|
||||
"test": [
|
||||
"runtests.jl"
|
||||
],
|
||||
"example": [
|
||||
".meta/example.jl"
|
||||
]
|
||||
},
|
||||
"blurb": "Convert a number into its corresponding raindrop sounds - Pling, Plang and Plong.",
|
||||
"source": "A variation on FizzBuzz, a famous technical interview question that is intended to weed out potential candidates. That question is itself derived from Fizz Buzz, a popular children's game for teaching division.",
|
||||
"source_url": "https://en.wikipedia.org/wiki/Fizz_buzz"
|
||||
}
|
||||
1
julia/raindrops/.exercism/metadata.json
Normal file
1
julia/raindrops/.exercism/metadata.json
Normal file
@@ -0,0 +1 @@
|
||||
{"track":"julia","exercise":"raindrops","id":"db442d635d8643bf9d7f0fa48936e303","url":"https://exercism.org/tracks/julia/exercises/raindrops","handle":"Kimawari","is_requester":true,"auto_approve":false}
|
||||
34
julia/raindrops/HELP.md
Normal file
34
julia/raindrops/HELP.md
Normal file
@@ -0,0 +1,34 @@
|
||||
# Help
|
||||
|
||||
## Running the tests
|
||||
|
||||
To run the tests, run this command from within the exercise directory:
|
||||
|
||||
```bash
|
||||
$ julia runtests.jl
|
||||
```
|
||||
|
||||
## Submitting your solution
|
||||
|
||||
You can submit your solution using the `exercism submit raindrops.jl` 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 [Julia track's documentation](https://exercism.org/docs/tracks/julia)
|
||||
- The [Julia track's programming category on the forum](https://forum.exercism.org/c/programming/julia)
|
||||
- [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, we recommend that you submit your code and request mentoring :)
|
||||
|
||||
If you don't want to do that for whatever reason, then you can find the wider Julia community channels [here](https://julialang.org/community/).
|
||||
48
julia/raindrops/README.md
Normal file
48
julia/raindrops/README.md
Normal file
@@ -0,0 +1,48 @@
|
||||
# Raindrops
|
||||
|
||||
Welcome to Raindrops on Exercism's Julia Track.
|
||||
If you need help running the tests or submitting your code, check out `HELP.md`.
|
||||
|
||||
## Introduction
|
||||
|
||||
Raindrops is a slightly more complex version of the FizzBuzz challenge, a classic interview question.
|
||||
|
||||
## Instructions
|
||||
|
||||
Your task is to convert a number into its corresponding raindrop sounds.
|
||||
|
||||
If a given number:
|
||||
|
||||
- is divisible by 3, add "Pling" to the result.
|
||||
- is divisible by 5, add "Plang" to the result.
|
||||
- is divisible by 7, add "Plong" to the result.
|
||||
- **is not** divisible by 3, 5, or 7, the result should be the number as a string.
|
||||
|
||||
## Examples
|
||||
|
||||
- 28 is divisible by 7, but not 3 or 5, so the result would be `"Plong"`.
|
||||
- 30 is divisible by 3 and 5, but not 7, so the result would be `"PlingPlang"`.
|
||||
- 34 is not divisible by 3, 5, or 7, so the result would be `"34"`.
|
||||
|
||||
~~~~exercism/note
|
||||
A common way to test if one number is evenly divisible by another is to compare the [remainder][remainder] or [modulus][modulo] to zero.
|
||||
Most languages provide operators or functions for one (or both) of these.
|
||||
|
||||
[remainder]: https://exercism.org/docs/programming/operators/remainder
|
||||
[modulo]: https://en.wikipedia.org/wiki/Modulo_operation
|
||||
~~~~
|
||||
|
||||
## Source
|
||||
|
||||
### Created by
|
||||
|
||||
- @andrej-makarov-skrt
|
||||
|
||||
### Contributed to by
|
||||
|
||||
- @cmcaine
|
||||
- @SaschaMann
|
||||
|
||||
### Based on
|
||||
|
||||
A variation on FizzBuzz, a famous technical interview question that is intended to weed out potential candidates. That question is itself derived from Fizz Buzz, a popular children's game for teaching division. - https://en.wikipedia.org/wiki/Fizz_buzz
|
||||
16
julia/raindrops/raindrops.jl
Normal file
16
julia/raindrops/raindrops.jl
Normal file
@@ -0,0 +1,16 @@
|
||||
function raindrops(number)
|
||||
res = ""
|
||||
if number % 3 == 0
|
||||
res *= "Pling"
|
||||
end
|
||||
if number % 5 == 0
|
||||
res *= "Plang"
|
||||
end
|
||||
if number % 7 == 0
|
||||
res *= "Plong"
|
||||
end
|
||||
if number % 3 != 0 && number % 5 != 0 && number % 7 != 0
|
||||
res *= string(number)
|
||||
end
|
||||
return res
|
||||
end
|
||||
74
julia/raindrops/runtests.jl
Normal file
74
julia/raindrops/runtests.jl
Normal file
@@ -0,0 +1,74 @@
|
||||
using Test
|
||||
|
||||
include("raindrops.jl")
|
||||
|
||||
@testset verbose = true "tests" begin
|
||||
@testset "detect numbers" begin
|
||||
@testset "the sound for 1 is 1" begin
|
||||
@test raindrops(1) == "1"
|
||||
end
|
||||
@testset "2 to the power 3 does not make a raindrop sound as 3 is the exponent not the base" begin
|
||||
@test raindrops(8) == "8"
|
||||
end
|
||||
@testset "the sound for 52 is 52" begin
|
||||
@test raindrops(52) == "52"
|
||||
end
|
||||
end
|
||||
|
||||
@testset "detect pling" begin
|
||||
@testset "the sound for 3 is Pling" begin
|
||||
@test raindrops(3) == "Pling"
|
||||
end
|
||||
@testset "the sound for 6 is Pling as it has a factor 3" begin
|
||||
@test raindrops(6) == "Pling"
|
||||
end
|
||||
@testset "the sound for 9 is Pling as it has a factor 3" begin
|
||||
@test raindrops(9) == "Pling"
|
||||
end
|
||||
@testset "the sound for 27 is Pling as it has a factor 3" begin
|
||||
@test raindrops(27) == "Pling"
|
||||
end
|
||||
end
|
||||
|
||||
@testset "detect plang" begin
|
||||
@testset "the sound for 5 is Plang" begin
|
||||
@test raindrops(5) == "Plang"
|
||||
end
|
||||
@testset "the sound for 10 is Plang as it has a factor 5" begin
|
||||
@test raindrops(10) == "Plang"
|
||||
end
|
||||
@testset "the sound for 25 is Plang as it has a factor 5" begin
|
||||
@test raindrops(25) == "Plang"
|
||||
end
|
||||
@testset "the sound for 3125 is Plang as it has a factor 5" begin
|
||||
@test raindrops(3125) == "Plang"
|
||||
end
|
||||
end
|
||||
|
||||
@testset "detect plong" begin
|
||||
@testset "the sound for 7 is Plong" begin
|
||||
@test raindrops(7) == "Plong"
|
||||
end
|
||||
@testset "the sound for 14 is Plong as it has a factor of 7" begin
|
||||
@test raindrops(14) == "Plong"
|
||||
end
|
||||
@testset "the sound for 49 is Plong as it has a factor 7" begin
|
||||
@test raindrops(49) == "Plong"
|
||||
end
|
||||
end
|
||||
|
||||
@testset "detect multiple sounds" begin
|
||||
@testset "the sound for 15 is PlingPlang as it has factors 3 and 5" begin
|
||||
@test raindrops(15) == "PlingPlang"
|
||||
end
|
||||
@testset "the sound for 21 is PlingPlong as it has factors 3 and 7" begin
|
||||
@test raindrops(21) == "PlingPlong"
|
||||
end
|
||||
@testset "the sound for 35 is PlangPlong as it has factors 5 and 7" begin
|
||||
@test raindrops(35) == "PlangPlong"
|
||||
end
|
||||
@testset "the sound for 105 is PlingPlangPlong as it has factors 3, 5 and 7" begin
|
||||
@test raindrops(105) == "PlingPlangPlong"
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user