[Community Puzzle] 1D Bush Fire

https://www.codingame.com/training/easy/1d-bush-fire

Send your feedback or ask for help here!

Created by @java_coffee_cup,validated by @Deltaspace,@dbdr and @cg123.
If you have any issues, feel free to ping them.

Nice URL :slight_smile: https://www.codingame.com/learn/💦💦💦🔥🔥🔥
(Don’t use Internet Explorer 1.0 though…)

4 Likes

I want to go for 100% achivement for this puzzle. There’s no description over Validator 2.
What’s behind that check ?

It is very similar to the corresponding testcase.

Hey, I can’t pass test case 3 because of the run time of my program.
My solution is brute force. I can’t think of better solution to this. I have thought of
saving the result of each array of bush fire and when I will ran into identical array
I will be able to use my saved result from before, but I saw that the arrays aren’t identical.
What can I do to reduce my program run time?

You can look at small examples and find which cells receive water and in what conditions.
For example if cell 1 and cell 3 are both on fire, then it doesn’t matter if cell 2 is on fire or not, it will have to receive water (‘fff’ and ‘f f’ lead to the same result).

2 Likes

I tried it, so first I erase the fire from all the ones that look like this ‘.f.f.’ or ‘.fff.’ (Like you said) and put ‘…’ instead (I did this: ‘.f.f.’ because of this case: [f , f , . , f , f]).
Second before making brute force I clean up all the places that have no fire around them and in them (’…’).

But it still didn’t help me to pass the test… :disappointed_relieved:

What else can I do?

I also made that if there is no fire it will print 0 immediately and if all the array has fire
print Case.length%3==0?console.log(Case.length/3):console.log(1 + Math.floor(Case.length/3))

Thanks, I got it :smiley:

1 Like

Hello, I have a pretty simple solution is (SPOILER) to count groups of regex (f{1,3})
But I’m in trouble with the tests cases, example in testcase 4: .f…f.f.f is supposed to be 3 in the testcase, but it’s obviously 4, right ?

Is there somewhere I can report this error ?

If you mean this one:

.f..f.f.f

the correct answer is obviously 3. Your “pretty simple” solution may be defective to get output 4.

1 Like
Code removed by a moderator.

What is the interest to post your complete code here, without asking any question ?

i guess i posted que. at wrong place and program here,
sorry

Was trying to recursively try all the possible positions of droplets but that led to timeouts. Turns out a greedy approach works where you iterate through the forest from left to right and put a drop at the right-most possible square every time you find a fire.

This was an interesting and thoughtful piece of code to work on, I liked how simple it really was to solve the problem. Thank you for this!