+ 3
Can anyone help me to understand this question?
Im a little new here and I've been trying to use JavaScript loops to solve this problem but I just can't seem to get my head around it. Question : The snail climbs up 7 feet each day and slips back 2 feet each night. How many days will it take the snail to get out of a well with the given depth? Sample Input: 31 Sample Output: 6 Explanation: Let's break down the distance the snail covers each day: Day 1: 7-2=5 Day 2: 5+7-2=10 Day 3: 10+7-2=15 Day 4: 15+7-2=20 Day 5: 20+7-2=25 Day 6: 25+7=32 So, on Day 6 the snail will reach 32 feet and get out of the well at day, without slipping back that night.
37 Answers
+ 7
and the logic is independent of the programming language. if you have the wrong algorithm, you will also solve it incorrectly on python for example. I'm trying three languages: js, python, and ruby. and imagine, the logic is the same! only the syntax of writing the program differs
+ 4
There is one š and it is daily climbs the wall 7 feet up but at night it slips out 2 feet. means it slips from 7 feet so 7-2 = 5.
Now you have to figure out how many days it takes to get out from particular given depth.
In question input is 31 so 31 is total feet you have. now if š is climb 7 feet at day and slip 2 feet at night so in 1 entire day it climb only 5 feet.
so 31-5 = 26 feet is still remains.
now next day it again climb 7 feet and slips 2 feet so. 1st 5feet + 7feet - 2feet slips =10.
Two entire day is completed. and snail is climbed 10 feet. still snail have to climb 21 feet
+ 4
function main() {
var depth = parseInt(readLine(), 10);
//your code goes here
var day = depth / (5);
console.log(Math.round(day));
}
+ 4
function main() {
var depth = parseInt(readLine(), 10);
//your code goes here
var day = depth / (5);
console.log(Math.round(day));
}
+ 4
Look at my post it's solution and is too easy to understand...
+ 4
Post is closed
+ 4
Discussion is closed...
+ 4
Question is closed...
+ 4
Ask something ELSE!!!
+ 3
function main() {
var depth = parseInt(readLine(), 10);
//your code goes here
var day = depth / (7-2);
console.log(Math.round(day));
}
+ 2
Tapabrata Banerjee you solved this task?
+ 2
why do you get attached to five instead of seven? that's not how it works there
+ 2
With your skills, you can work as an error generator in the code for the testers service š¤
+ 2
The solution is to round off your result..
the code will be:
// without slips back at night.
var day = depth / (7-2);
//to print out put and round the result.
console.log(Math.round(day));
+ 1
Hi! Can you show us your code attempt?
+ 1
I have not completely solved this problem, but I think that you are suggesting the wrong thing. think about when the snail should come out? and when should I check it out or not?
+ 1
In simple input / 5. if it is less than or equal to (<=0) than return that number otherwise add 1 in that
+ 1
we had a heated discussion here, but nothing came from the owner of the question... what does he think about it? welcome to join us!
+ 1
Tapabrata Banerjee you forgot print command number of days
+ 1
and why do you need the "d" - counter variable when the "i" loop variable does a great job of it