+ 4

Help me

I am solving snail in the wall Here is my try function main() { var depth = parseInt(readLine(), 10); //your code goes here var result = []; var isCompleted = false; var myCos = 7 - 2; var output = 0; var myDigits = depth.toString().split("") while (!isCompleted) { if(isCompleted){ break; }else{ output += myCos; result.push(output); if(output > depth ) { isCompleted = true; } } } if(parseInt(myDigits[myDigits.length - 1]) < 5){ console.log(Math.floor(result[result.length - 2] / 5)); } else { console.log(Math.floor(result[result.length - 1] / 5)); } }

3rd Dec 2020, 5:55 PM
🥇👩‍💻 Kintu Michael Evans 🔥🔥( Active)
🥇👩‍💻 Kintu Michael Evans 🔥🔥( Active) - avatar
9 odpowiedzi
4th Dec 2020, 6:32 AM
Ciara
Ciara - avatar
+ 10
function main() { var depth = parseInt(readLine(), 10); var a = 0; var day = 0 while(a <= depth) { a += 7 day += 1 if (a >= depth) { break; } a -= 2 } console.log(day) } This is the code I used! Hope this helps!
4th Dec 2020, 11:12 PM
Pieter Edwards
Pieter Edwards - avatar
+ 6
function main() { var depth = parseInt(readLine(), 10); var covereddistance = 0; var day = 0 while(covereddistance <= depth) { covereddistance += 7 day += 1 if (covereddistance >= depth) { break; } else(covereddistance -= 2) } console.log(day) } // learnt from other peoples code
10th Jan 2021, 8:24 PM
XTANLEE
XTANLEE - avatar
+ 1
I just got it with this: function main() { var depth = parseInt(readLine(), 10); //your code goes here var d; console.log(Math.ceil(d = (depth - 2)/5)); }
4th Dec 2020, 6:30 AM
Ciara
Ciara - avatar
+ 1
4th Dec 2020, 7:49 AM
🇮🇳Vivek🇮🇳
🇮🇳Vivek🇮🇳 - avatar
4th Dec 2020, 1:28 AM
🇮🇳Vivek🇮🇳
🇮🇳Vivek🇮🇳 - avatar
0
function main() { var depth = parseInt(readLine(), 10); //your code goes here var day = 0; var i = 0; while(i<depth){ i = i+7; day = day+1; if (i>= depth) { break; } else (i=i-2); } console.log(day) } This is the code I used :).
2nd Jan 2021, 10:37 PM
Maxim
0
----------------------------------- PASSED ALL TEST CASES ----------------------------------- function main() { var depth = parseInt(readLine(), 10); var dist = 0; for (i=1; dist<depth; i++) { dist += 7; if (dist<depth) { dist -= 2; // snail didn't make it so it slid back 2 feet } else { // snail did make it so the loop ends break; } } { console.log(i); } }
24th Sep 2022, 1:38 PM
Elton Kornmann
Elton Kornmann - avatar
- 1
Also just fixed it using an actual loop: var d = 0; var prevDay = 0; var total = 0; do { d++; var x = 7 - 2; var prevDay = x * d; var total = prevDay + 7 - 5; } while (total < depth) console.log(d); } Hope this helps!
4th Dec 2020, 6:46 PM
Ciara
Ciara - avatar