Story
The Pied Piper has been enlisted to play his magical tune and coax all the rats out of town.
But some of the rats are deaf and are going the wrong way!
How many deaf rats are there?
Legend
-
P
= The Pied Piper -
O~
= Rat going left -
~O
= Rat going right
Example
- ex1
~O~O~O~O P
has 0 deaf rats - ex2
P O~ O~ ~O O~
has 1 deaf rat - ex3
~O~O~O~OP~O~OO~
has 2 deaf rats
This challenge comes from dinglemouse on CodeWars. Thank you to CodeWars, who has licensed redistribution of this challenge under the 2-Clause BSD License!
Want to propose a challenge idea for a future post? Email yo+challenge@dev.to with your suggestions!
Top comments (8)
Thanks for the feedback. With a little inspiration from Avalander's Scala solution, I've got it what I had in mind in the first place.
Nice math trick with the piper, hadn't thought of that!
Done very quickly, but works.
F#
Slightly over-engineered solution in Scala.
And the tests:
Using javascript
CodeSandbox example
Using Ruby and Regex
Output:
Here is my javascript walkthrough, I've used repl.it for the first time and it felt like a great use case.
Let me know if the video helps you!
JS