Skip to content

Commit

Permalink
jq/raindrops: 1st iteration
Browse files Browse the repository at this point in the history
  • Loading branch information
vpayno committed Apr 9, 2024
1 parent eca9bae commit b7e7f10
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 2 deletions.
1 change: 1 addition & 0 deletions jq/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@
- [assembly-line](./assembly-line/README.md)
- [bird-count](./bird-count/README.md)
- [regular-chatbot](./regular-chatbot/README.md)
- [raindrops](./raindrops/README.md)
7 changes: 6 additions & 1 deletion jq/raindrops/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,9 @@ outputs

### 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
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

### My Solution

- [my solution](./raindrops.jq)
- [run-tests](./run-tests-bats.txt)
13 changes: 12 additions & 1 deletion jq/raindrops/raindrops.jq
Original file line number Diff line number Diff line change
@@ -1 +1,12 @@
"Remove this line and implement your solution" | halt_error
def is_pling: . % 3 == 0;
def is_plang: . % 5 == 0;
def is_plong: . % 7 == 0;

def not_sound: (is_pling | not) and (is_plang | not ) and (is_plong | not);

.number | if not_sound then (. | tostring)
else (
(if is_pling then "Pling" else "" end )+
(if is_plang then "Plang" else "" end )+
(if is_plong then "Plong" else "" end)
) end
28 changes: 28 additions & 0 deletions jq/raindrops/run-tests-bats.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

[./test-raindrops.bats]

bats ./test-raindrops.bats

1..18
ok 1 the sound for 1 is 1
ok 2 the sound for 3 is Pling
ok 3 the sound for 5 is Plang
ok 4 the sound for 7 is Plong
ok 5 the sound for 6 is Pling as it has a factor 3
ok 6 2 to the power 3 does not make a raindrop sound as 3 is the exponent not the base
ok 7 the sound for 9 is Pling as it has a factor 3
ok 8 the sound for 10 is Plang as it has a factor 5
ok 9 the sound for 14 is Plong as it has a factor of 7
ok 10 the sound for 15 is PlingPlang as it has factors 3 and 5
ok 11 the sound for 21 is PlingPlong as it has factors 3 and 7
ok 12 the sound for 25 is Plang as it has a factor 5
ok 13 the sound for 27 is Pling as it has a factor 3
ok 14 the sound for 35 is PlangPlong as it has factors 5 and 7
ok 15 the sound for 49 is Plong as it has a factor 7
ok 16 the sound for 52 is 52
ok 17 the sound for 105 is PlingPlangPlong as it has factors 3, 5 and 7
ok 18 the sound for 3125 is Plang as it has a factor 5

real 0m2.435s
user 0m1.320s
sys 0m1.185s

0 comments on commit b7e7f10

Please sign in to comment.