+ 5

Snail in the well

Got the first two visible case couldnt solve the hidden cases My attempt https://code.sololearn.com/W6w4Iu3P2iLE/?ref=app

13th Dec 2020, 8:14 AM
elvisreal
elvisreal - avatar
32 Antworten
+ 22
elvisreal , in fact you don't need to perform so complex calculations using slice, split, reverse and Math.floor method. Just follow the description. Don't just add 5 each day, because you should make a check if the length >= depth after increasing the length with 7. Look at the corrected code. Hope it helps you. https://code.sololearn.com/Wk4uxTS9bHaB/?ref=app
13th Dec 2020, 8:45 AM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
+ 10
It's very simple TRY THIS 👇🏻 let day = 1; for(let height = 7; height < depth; height += 5 ){ day++; } console.log(day) 🥳🥳🥳🥳
10th May 2021, 7:29 AM
Rehan Roxx
Rehan Roxx - avatar
+ 7
I solved this about 3 hours So don’t just copy and paste the code next time, try also your best function main() { var depth = parseInt(readLine(), 10); var days = 0; seven = 7; two = 2; total = 0; isDone = false; while(!isDone){ total += seven; if(total >= depth){ isDone = true; } else{ total -= two; } days++; } console.log(days); }
1st Apr 2021, 12:02 PM
Dynamic Contender
+ 2
function main() { var depth = parseInt(readLine(), 10); //your code goes here day=0 for (;depth>0;day++){ depth-=7 if(depth>0){ depth+=2 } } console.log(day) }
18th Jul 2021, 5:59 AM
Mega Elisa
+ 2
//the best solution function main() { var depth = parseInt(readLine(), 10); //your code goes here var go = 7-2 var dist = 0 var day = 0 for(let go =5; dist<=depth-3; dist +=go){ day+=1 } console.log(day) }
8th Jun 2022, 10:13 AM
Ibrahim Aminu
Ibrahim Aminu - avatar
11th Feb 2021, 2:29 PM
👑Mahesh Khatri👑
👑Mahesh Khatri👑 - avatar
+ 1
function main() { var depth = parseInt(readLine(), 10); //your code goes here var d=0; var i=0; for(i=0;d<depth;i++) { d=d+7;/*during day(d) it covers 7 feet*/ if(d>=depth)/*the loop will break when it climbs the whole depth*/ { i=i+1;/* here,i= no.of days*/ break; } d=d-2;/*it slips down 2 feet at night*/ } console.log(i); }
28th May 2021, 8:29 AM
snehit_13
snehit_13 - avatar
+ 1
function main() { var depth = parseInt(readLine(), 10); //tu código va aquí var d = 0; // días var c = 0; // caracol while (c < depth) { c += 7 - 2; d += 1; if (c > depth) { if (c - 2 <= depth) { console.log(d); break; } else if (c > depth) { console.log(d - 1); break; } } } }
6th Jun 2021, 6:38 PM
Kevin Alexander Alvarez Echeverri
Kevin Alexander Alvarez Echeverri - avatar
+ 1
function main() { var depth = parseInt(readLine(), 10); //your code goes here var i=0; var day=0; while(i<depth){ day+=1; i+=7; //if the snail is already at the top by day it doesnt need to slip anymore at night if(i<depth){ i-=2; }else{ break; } } console.log(day); }
17th Jun 2021, 1:40 AM
david lee
david lee - avatar
+ 1
function main() { var depth = parseInt(readLine(), 10); //your code goes here console.log(Math.ceil((depth-2)/5)); }
12th Aug 2021, 12:02 AM
Александр Борисов
Александр Борисов - avatar
+ 1
function main() { var depth = parseInt(readLine(), 10); //your code goes here var day = 0; var num = 0; if (depth>0) { do{ num += 7; if (num==depth){ continue; } else if(num<depth) { num-=2; } day++; }while (num<=depth); } console.log(day); }
12th Feb 2022, 5:22 PM
Vibha Sengar
+ 1
console.log(Math.round(depth/5)) most efficient method
20th Sep 2022, 2:02 PM
VINAYAK ATHREYA B R
VINAYAK ATHREYA B R - avatar
+ 1
for(w=5; w <= w; w+=5){ var work=w; console.log(Math.round(depth/work)) {break;} } } The Math.round() function returns the value of a number rounded to the nearest integer. is if 48 dethp/w = 8.4 eith math .round its 8
14th Nov 2022, 10:27 AM
usman zahoor
0
In fact you don't even need a loop. You can get the answer with a single line of arithmetic operations. Hint: there is a linear relation between input and output
13th Dec 2020, 9:34 AM
Benjamin Jürgens
Benjamin Jürgens - avatar
13th Dec 2020, 10:58 AM
🇮🇳Vivek🇮🇳
🇮🇳Vivek🇮🇳 - avatar
0
Jesse Franco Latosa thanks but i solved it my own way nice code tho
1st Apr 2021, 12:13 PM
elvisreal
elvisreal - avatar
0
function main() { var x = parseInt(readLine(), 10); var y = 1; for (;;y++) { if ((y*5)>=(x-2)) { break;} } console.log(y); }
11th Jul 2021, 7:56 PM
Sean Wight
Sean Wight - avatar
0
@Jesse Franco Latosa could you please explain the code?
26th Aug 2021, 8:59 PM
Dami
Dami - avatar
0
function main() { var depth = parseInt(readLine(), 10); for(i=0;depth; i+7-5); }
3rd Sep 2021, 2:31 PM
PRO programmer
PRO programmer - avatar
0
function main() { var depth = parseInt(readLine(), 10); //your code goes var //D is distance travel each day var day=0; for(D=0; D<depth; day++) { D+=7; if(D>=depth){ day++ break; } D-=2; } console.log(day) }
2nd Dec 2021, 8:04 AM
Lucky Kim