324,811 views
38 votes
38 votes
2.17.5 coders answers

User Serhii Onishchenko
by
2.6k points

1 Answer

26 votes
26 votes

Answer:

start();

if(colorIs(Color.blue)){

paint(Color.red);

if(frontIsClear());

move();

}else{

if(colorIs(Color.red)){

paint(Color.blue);

if(frontIsClear());

move();

}

}

if(colorIs(Color.blue)){

paint(Color.red);

if(frontIsClear());

move();

}else{

if(colorIs(Color.red)){

paint(Color.blue);

if(frontIsClear());

move();

}

}

if(colorIs(Color.blue)){

paint(Color.red);

if(frontIsClear());

move();

}else{

if(colorIs(Color.red)){

paint(Color.blue);

if(frontIsClear());

move();

}

}

if(colorIs(Color.blue)){

paint(Color.red);

if(frontIsClear());

move();

}else{

if(colorIs(Color.red)){

paint(Color.blue);

if(frontIsClear());

move();

}

}

if(colorIs(Color.blue)){

paint(Color.red);

if(frontIsClear());

move();

}else{

if(colorIs(Color.red)){

paint(Color.blue);

if(frontIsClear());

move();

}

}

if(colorIs(Color.blue)){

paint(Color.red);

if(frontIsClear());

move();

}else{

if(colorIs(Color.red)){

paint(Color.blue);

if(frontIsClear());

move();

}

}

if(colorIs(Color.blue)){

paint(Color.red);

if(frontIsClear());

move();

}else{

if(colorIs(Color.red)){

paint(Color.blue);

if(frontIsClear());

move();

}

}

if(colorIs(Color.blue)){

paint(Color.red);

if(frontIsClear());

move();

}else{

if(colorIs(Color.red)){

paint(Color.blue);

if(frontIsClear());

move();

}

}

if(colorIs(Color.blue)){

paint(Color.red);

if(frontIsClear());

move();

}else{

if(colorIs(Color.red)){

paint(Color.blue);

if(frontIsClear());

move();

}

}

if(colorIs(Color.blue)){

paint(Color.red);

if(frontIsClear());

}else{

if(colorIs(Color.red)){

paint(Color.blue);

if(frontIsClear());

}

}

function start(){

}

Q. 5.1.3: Move to Wall

Ans:

function start(){

while(frontIsClear()){

move();

}

}

I apologize if its incorrect

User Dudemanbearpig
by
3.1k points