DeathZyte Posted December 4, 2012 Report Posted December 4, 2012 (edited) Here's a sample logical question for aspiring programmers. There are two robots that will be walking in a single straight line and between them is a rock. At this time we don't know where each robot is facing, it can be on the left or right. What we know is that the following commands are available: isHit -> if a robot hits anything this flag will be equal to true. MoveOneStepLeft MoveOneStepRight MoveTwoStepLeft MoveTwoStepRight Question: We are task to create 1 program/pseudo-code to be loaded to both robots and our goal is to make both of them collide with each other. Hint 1: you can use loops such as while, for-loop. Hint 2: 4 lines of code will be enough Prize: 100 tokens for the first one to solve it correctly :) Edited December 4, 2012 by DeathZyte
Forum~ Posted February 8, 2013 Report Posted February 8, 2013 (edited) bool isLeft; do{ (rand()%2) ? MoveTwoStepLeft, isLeft=true : MoveTwoStepRight, isLeft=false; }while(!isHit); isLeft ? MoveTwoStepLeft : MoveTwoStepRight; //final steps to "climb over rock" and collide with each other. //loops until robot hits rock. given infinite time, robots will hit the rock, even with random movement. //i wonder what the point of the rock was? //i wonder what the point of MoveOneStepLeft and MoveOneStepRight was? edit: necro'd an old thread. but it's interesting enough to warrant it. >_< Edited February 8, 2013 by Forum~