0

# Help plz

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.

12/10/2020 3:20:26 PM

AJAY SANTH

+23

function main() { var depth = parseInt(readLine(), 10); //your code goes here var day = 0; var total = 0; while(total<depth){ day = day + 1; total = total + 7; if(total >= depth){ console.log(day); break; } total = total - 2; } } Hope it helps!!

+5

AJ #Learn With Me 👨‍💻 I agree but he should think that he had learnt or not he wanted help and that's what I did....

+3

Hi! Can someone explain me how comment version with "while" is better than my with "for", im pretty sure what i did is a long term wrong approach. It works with all test cases though function main() { var depth = parseInt(readLine(), 10); //your code for (i = 2,d=0; i < depth; i = i+7) { //i for how far snail moved, and d for day. if (i < depth ) { i = i - 2,d++ } } console.log(d); }

+3

var days =(depth-7)/5 + 1; console.log(Math.ceil(days));

+3

function main() { var depth = parseInt(readLine(), 10); //your code goes here var day = 0; var total = 0; while(total<depth){ day = day + 1; total = total + 7; if(total >= depth){ console.log(day); break; } total = total - 2; } }

+3

function main() { var depth = parseInt(readLine(), 10); //your code goes here var sum = 0; var count = 0; for (i=1;i<depth;i++) { sum=sum+7; count++; if (sum>=depth) { break; } else { sum=sum-2; } } console.log(count); }

+1

var day = 0; var total = 0; while(total<depth){ day = day + 1; total = total + 7; if(total >= depth){ console.log(day); break; } total = total - 2; }

+1

function main() { var depth = parseInt(readLine(), 10); //your code goes here var feet_each_day = 7 ; var back_feet_each_night = 2 ; var day = 0; var total = 0; while(total<depth){ day = day + 1; total = total + feet_each_day; if(total >= depth){ break; } total = total - back_feet_each_night; } console.log(day); }

+1

//it is easy function main() { var depth = parseInt(readLine(), 10); //your code goes here var x; var count=0; for(x=0; x<depth;){ x+=7; if(x<depth){ x-=2; } count++; } console.log(count); } //or you can go through while loop function main() { var depth = parseInt(readLine(), 10); //your code goes here var total=0; var day_count=0; while(total<depth){ total+=7; day_count++; if(total>=depth){ console.log(day_count); } else{ total=total-2; } } }

0

AJAY SANTH Where is your attempts?

0

\$ααρԋιɾє ☆☆☆ . It's not good to share full code because he will never learn.

0

function main() { var depth = parseInt(readLine(), 10); //your code goes here var day = 0; var night_distance = 2; var total_distance = 0; var day_distance = 7; while(true) { day = day + 1; total_distance = total_distance + day_distance; if (total_distance >= depth) { break; } else { total_distance = total_distance - night_distance; } } console.log(day); } // I love to KISS the code

0

function main() { var depth = parseInt(readLine(), 10); //your code goes here var days = 0; while (depth > 0) { depth -= 7 if (depth > 0) { depth +=2 } days++ } console.log(days) }

0

Hey! How about this code? it works for some, but... function main() { var depth = parseInt(readLine(), 10); let day = 0; for (day = 0; day <= depth; day += 5) { if (day * 5 >= depth) break; } console.log(day) } some help, please?

0

LMFAO......what the hell was I doing😭🤣 function main() { var depth = parseInt(readLine(), 10); //your code goes here switch(day){ Day 1: for (i=1;i<=7;i++){ if(i==6){ break; } document.write(i+"<br/>") } break; Day 2: for (i=1;i<=12;i++){ if(i==11){ break; } document.write(i+"<br/>") } break; Day 3: for (i=1;i<=17;i++){ if(i==16){ break; } document.write(i+"<br/>") } break; Day 4: for (i=1;i<=22;i++){ if(i==21){ break; } document.write(i+"<br/>") } break; Day 5: for (i=1;i<=27;i++){ if(i==26){ break; } document.write(i+"<br/>") } break; Day 6: for (i=1;i<=32;i++){ document.write(i+"<br/>") } break; } }

0

function main() { var depth = parseInt(readLine(), 10); const progress = 5; var days = Math.round(depth / progress); console.log(days); } // Note the addition in each day is 5

0

function main() { var depth = parseInt(readLine(), 10); //your code goes here var jour = 0; var passer = 0; while(passer<depth){ jour = jour + 1; passerr= passer + 7; if(passer>= depth){ console.log(jour); break; } passer = passer - 2; } }

0

function main() { var depth = parseInt(readLine(), 10); //your code goes here var c =depth % 5; if(c<3) console.log(Math.floor(depth/5)) ; else console.log(Math.ceil(depth/5)); }

0

function main() { var depth = parseInt(readLine(), 10); //your code goes here var day = 0; var total = 0; while(total<depth){ day = day + 1; total = total + 7; if(total >= depth){ console.log(day); break; } total = total - 2; } }

0

function main() { var depth = parseInt(readLine(), 10); //your code goes here var day = 0; var total = 0; while(total<depth){ day = day + 1; total = total + 7; if(total >= depth){ console.log(day); break; } total = total - 2; } }