+ 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)); } }
9 Antworten
+ 6
The equation is depth = 7d - 2(d-1)
This simplifies to d = (depth - 2)/5
Did not create this equation, found a reference on
https://www.google.com/url?sa=t&source=web&rct=j&url=http://www.math.armstrong.edu/faculty/brown/SnailWordProblem.pdf&ved=2ahUKEwiwo-jU1bPtAhUhxVkKHXnRC5MQFjADegQIERAB&usg=AOvVaw2SiLqyJchSvF-LrH4f34mR
+ 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!
+ 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
+ 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));
}
+ 1
Ciara Sullivan Thanks.
0
I also can't solve this 😢😢
https://www.sololearn.com/Discuss/2610695/?ref=app
My attempt.
https://code.sololearn.com/cD5h9k1VCV22/?ref=app
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 :).
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);
}
}
- 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!