Setup
In this challenge, the world has been hit with a new virus! There is a new pandemic that humanity is struggling to fight against. The continents are separated by oceans, but some infected people have traveled before the quarantine.
You'll be given a map of the world in the form of a string:
s = "01000000X000X011X0X" "0" : uninfected "1" : infected "X" : ocean
- If one person gets infected on a continent, the entire continent will get infected.
- The first and last continents are not connected.
- The virus cannot spread across the ocean.
- For maps without
X
, there are no oceans so the entire planet would become infected, return0%
- For maps without
0
or1
, there are no people, return0
.
Return the percentage of the population that are infected by the virus.
Example
start: map1 = "01000000X000X011X0X" end: map1 = "11111111X000X111X0X" total = 15 infected = 11 percentage = 100*11/15 = 73.33333333333333
Tests
Which worlds are doomed? Which ones are saved?
A: 01000000X000X011X0X B: 01X000X010X011XX C: XXXXX D: 00000000X00X0000 E: 0000000010 F: 000001XXXX0010X1X00010 G: X00X000000X10X0100
Good luck!
This challenge comes from JJason 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 (11)
Ruby with heavy use of regexp and functional paradigm:
In Javascript
`
nice function name :D
JavaScript:
js
Alternative to @candidateplanet 's Python implementation:
Late to the party. JavaScript.
PHP
Rust:
RUBY