Skip to content

Commit 0ebd0c6

Browse files
authored
raindrops (#18)
1 parent 866374e commit 0ebd0c6

File tree

10 files changed

+219
-0
lines changed

10 files changed

+219
-0
lines changed

config.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,14 @@
126126
"practices": [],
127127
"prerequisites": [],
128128
"difficulty": 2
129+
},
130+
{
131+
"slug": "raindrops",
132+
"name": "Raindrops",
133+
"uuid": "9c6613c5-3df7-44a5-bb6e-4e7f0663b888",
134+
"practices": [],
135+
"prerequisites": [],
136+
"difficulty": 2
129137
}
130138
]
131139
},
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
return {
2+
default = {
3+
ROOT = { '.' }
4+
}
5+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Instructions
2+
3+
Your task is to convert a number into its corresponding raindrop sounds.
4+
5+
If a given number:
6+
7+
- is divisible by 3, add "Pling" to the result.
8+
- is divisible by 5, add "Plang" to the result.
9+
- is divisible by 7, add "Plong" to the result.
10+
- **is not** divisible by 3, 5, or 7, the result should be the number as a string.
11+
12+
## Examples
13+
14+
- 28 is divisible by 7, but not 3 or 5, so the result would be `"Plong"`.
15+
- 30 is divisible by 3 and 5, but not 7, so the result would be `"PlingPlang"`.
16+
- 34 is not divisible by 3, 5, or 7, so the result would be `"34"`.
17+
18+
~~~~exercism/note
19+
A common way to test if one number is evenly divisible by another is to compare the [remainder][remainder] or [modulus][modulo] to zero.
20+
Most languages provide operators or functions for one (or both) of these.
21+
22+
[remainder]: https://exercism.org/docs/programming/operators/remainder
23+
[modulo]: https://en.wikipedia.org/wiki/Modulo_operation
24+
~~~~
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Introduction
2+
3+
Raindrops is a slightly more complex version of the FizzBuzz challenge, a classic interview question.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"authors": [
3+
"glennj"
4+
],
5+
"files": {
6+
"solution": [
7+
"raindrops.moon"
8+
],
9+
"test": [
10+
"raindrops_spec.moon"
11+
],
12+
"example": [
13+
".meta/example.moon"
14+
]
15+
},
16+
"blurb": "Convert a number into its corresponding raindrop sounds - Pling, Plang and Plong.",
17+
"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.",
18+
"source_url": "https://en.wikipedia.org/wiki/Fizz_buzz"
19+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
raindrops = (num) ->
2+
result = ''
3+
result ..= 'Pling' if num % 3 == 0 else ''
4+
result ..= 'Plang' if num % 5 == 0 else ''
5+
result ..= 'Plong' if num % 7 == 0 else ''
6+
7+
result == '' and (tostring num) or result
8+
9+
raindrops
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
module_name: "raindrops",
3+
generate_test: (case, level) ->
4+
lines = {
5+
"result = raindrops #{case.input.number}"
6+
"assert.are.equal '#{case.expected}', result"
7+
}
8+
table.concat [string.rep(' ', level) .. line for line in *lines], '\n'
9+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# This is an auto-generated file.
2+
#
3+
# Regenerating this file via `configlet sync` will:
4+
# - Recreate every `description` key/value pair
5+
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications
6+
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion)
7+
# - Preserve any other key/value pair
8+
#
9+
# As user-added comments (using the # character) will be removed when this file
10+
# is regenerated, comments can be added via a `comment` key.
11+
12+
[1575d549-e502-46d4-a8e1-6b7bec6123d8]
13+
description = "the sound for 1 is 1"
14+
15+
[1f51a9f9-4895-4539-b182-d7b0a5ab2913]
16+
description = "the sound for 3 is Pling"
17+
18+
[2d9bfae5-2b21-4bcd-9629-c8c0e388f3e0]
19+
description = "the sound for 5 is Plang"
20+
21+
[d7e60daa-32ef-4c23-b688-2abff46c4806]
22+
description = "the sound for 7 is Plong"
23+
24+
[6bb4947b-a724-430c-923f-f0dc3d62e56a]
25+
description = "the sound for 6 is Pling as it has a factor 3"
26+
27+
[ce51e0e8-d9d4-446d-9949-96eac4458c2d]
28+
description = "2 to the power 3 does not make a raindrop sound as 3 is the exponent not the base"
29+
30+
[0dd66175-e3e2-47fc-8750-d01739856671]
31+
description = "the sound for 9 is Pling as it has a factor 3"
32+
33+
[022c44d3-2182-4471-95d7-c575af225c96]
34+
description = "the sound for 10 is Plang as it has a factor 5"
35+
36+
[37ab74db-fed3-40ff-b7b9-04acdfea8edf]
37+
description = "the sound for 14 is Plong as it has a factor of 7"
38+
39+
[31f92999-6afb-40ee-9aa4-6d15e3334d0f]
40+
description = "the sound for 15 is PlingPlang as it has factors 3 and 5"
41+
42+
[ff9bb95d-6361-4602-be2c-653fe5239b54]
43+
description = "the sound for 21 is PlingPlong as it has factors 3 and 7"
44+
45+
[d2e75317-b72e-40ab-8a64-6734a21dece1]
46+
description = "the sound for 25 is Plang as it has a factor 5"
47+
48+
[a09c4c58-c662-4e32-97fe-f1501ef7125c]
49+
description = "the sound for 27 is Pling as it has a factor 3"
50+
51+
[bdf061de-8564-4899-a843-14b48b722789]
52+
description = "the sound for 35 is PlangPlong as it has factors 5 and 7"
53+
54+
[c4680bee-69ba-439d-99b5-70c5fd1a7a83]
55+
description = "the sound for 49 is Plong as it has a factor 7"
56+
57+
[17f2bc9a-b65a-4d23-8ccd-266e8c271444]
58+
description = "the sound for 52 is 52"
59+
60+
[e46677ed-ff1a-419f-a740-5c713d2830e4]
61+
description = "the sound for 105 is PlingPlangPlong as it has factors 3, 5 and 7"
62+
63+
[13c6837a-0fcd-4b86-a0eb-20572f7deb0b]
64+
description = "the sound for 3125 is Plang as it has a factor 5"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
raindrops = (num) ->
2+
error 'Implement me!'
3+
4+
raindrops
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
raindrops = require 'raindrops'
2+
3+
describe 'raindrops', ->
4+
it 'the sound for 1 is 1', ->
5+
result = raindrops 1
6+
assert.are.equal '1', result
7+
8+
pending 'the sound for 3 is Pling', ->
9+
result = raindrops 3
10+
assert.are.equal 'Pling', result
11+
12+
pending 'the sound for 5 is Plang', ->
13+
result = raindrops 5
14+
assert.are.equal 'Plang', result
15+
16+
pending 'the sound for 7 is Plong', ->
17+
result = raindrops 7
18+
assert.are.equal 'Plong', result
19+
20+
pending 'the sound for 6 is Pling as it has a factor 3', ->
21+
result = raindrops 6
22+
assert.are.equal 'Pling', result
23+
24+
pending '2 to the power 3 does not make a raindrop sound as 3 is the exponent not the base', ->
25+
result = raindrops 8
26+
assert.are.equal '8', result
27+
28+
pending 'the sound for 9 is Pling as it has a factor 3', ->
29+
result = raindrops 9
30+
assert.are.equal 'Pling', result
31+
32+
pending 'the sound for 10 is Plang as it has a factor 5', ->
33+
result = raindrops 10
34+
assert.are.equal 'Plang', result
35+
36+
pending 'the sound for 14 is Plong as it has a factor of 7', ->
37+
result = raindrops 14
38+
assert.are.equal 'Plong', result
39+
40+
pending 'the sound for 15 is PlingPlang as it has factors 3 and 5', ->
41+
result = raindrops 15
42+
assert.are.equal 'PlingPlang', result
43+
44+
pending 'the sound for 21 is PlingPlong as it has factors 3 and 7', ->
45+
result = raindrops 21
46+
assert.are.equal 'PlingPlong', result
47+
48+
pending 'the sound for 25 is Plang as it has a factor 5', ->
49+
result = raindrops 25
50+
assert.are.equal 'Plang', result
51+
52+
pending 'the sound for 27 is Pling as it has a factor 3', ->
53+
result = raindrops 27
54+
assert.are.equal 'Pling', result
55+
56+
pending 'the sound for 35 is PlangPlong as it has factors 5 and 7', ->
57+
result = raindrops 35
58+
assert.are.equal 'PlangPlong', result
59+
60+
pending 'the sound for 49 is Plong as it has a factor 7', ->
61+
result = raindrops 49
62+
assert.are.equal 'Plong', result
63+
64+
pending 'the sound for 52 is 52', ->
65+
result = raindrops 52
66+
assert.are.equal '52', result
67+
68+
pending 'the sound for 105 is PlingPlangPlong as it has factors 3, 5 and 7', ->
69+
result = raindrops 105
70+
assert.are.equal 'PlingPlangPlong', result
71+
72+
pending 'the sound for 3125 is Plang as it has a factor 5', ->
73+
result = raindrops 3125
74+
assert.are.equal 'Plang', result

0 commit comments

Comments
 (0)