0

How do you solve Snell in the well problem, I have tried everything I need some guidance

29th May 2021, 10:08 AM
Basswell Mbilima
Basswell Mbilima - avatar
7 Réponses
+ 3
Basswell Mbilima , Nwokoma Chimezirim If you post your attempts, the community is more able to assist you. We may be able to assist you with your misunderstanding. Quite often, complete codes provided to others merely confuses them, & nothing is learnt. But if you get assistance pertaining to your concept, then you have a better chance of understanding
29th May 2021, 10:32 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 2
Please post your attempt.
29th May 2021, 10:19 AM
Eashan Morajkar
Eashan Morajkar - avatar
+ 1
Rik Wittkopp this is my code .. test 1 n 3 are what's failing.... It's in JavaScript function main() { var depth = parseInt(readLine(), 10); //your code goes here var distance = 0; var day = 0; do{ day++; distance = distance + 5; }while(distance < depth); console.log(day); }
29th May 2021, 12:08 PM
Basswell Mbilima
Basswell Mbilima - avatar
29th May 2021, 12:08 PM
Basswell Mbilima
Basswell Mbilima - avatar
+ 1
I finally solved it We have to add 7 to the snail every day, then check if it has climbed out, if not we then minus 2. This is my code below function main() { var depth = parseInt(readLine(), 10); //your code goes here var days = 0; var h = 0; for (h;h<=depth;) { days++; h += 7; if (h >= depth) { break; } h -= 2; } console.log(days);
29th May 2021, 10:32 PM
Mehzie
Mehzie - avatar
0
Same here honestly, it is either I get case 1 correct and fail case 2, then when I change a particul variable, I get case 1 wrong and fail case 2 I hope the snail in a well challenge is the one from Javascript course?
29th May 2021, 10:16 AM
Mehzie
Mehzie - avatar
0
function main() { var depth = parseInt(readLine(), 10); //your code goes here var days = 0 var i = 0 while (i<depth){ i+=7 ++days if (i>=depth){break} i-=2 } console.log(days) }
29th May 2021, 12:22 PM
Eashan Morajkar
Eashan Morajkar - avatar