Ceci est une ancienne révision du document !
Warning: Undefined array key 1 in /home/goupillf/wiki.goupill.fr/lib/plugins/codeprettify/syntax/code.php on line 172
Warning: Undefined array key 1 in /home/goupillf/wiki.goupill.fr/lib/plugins/codeprettify/syntax/code.php on line 172
Warning: Undefined array key 2 in /home/goupillf/wiki.goupill.fr/lib/plugins/codeprettify/syntax/code.php on line 214
Warning: Undefined array key 2 in /home/goupillf/wiki.goupill.fr/lib/plugins/codeprettify/syntax/code.php on line 214
Warning: Undefined array key 2 in /home/goupillf/wiki.goupill.fr/lib/plugins/codeprettify/syntax/code.php on line 214
Warning: Undefined array key 2 in /home/goupillf/wiki.goupill.fr/lib/plugins/codeprettify/syntax/code.php on line 214
Table des matières
Parcours du robot rebondissant
Le problème
Dans un fichier texte on vous fournit une carte comme celle-ci
...#........ ...........# ............ ..........#. ..#O........ ..........#.
Le O représente le point de départ d'un robot. Les # représentent des obstacles. Un bord est considéré comme un obstacle.
Initialement le robot se dirige vers le haut. Chaque fois qu'il rencontre un obstacle, il tourne sur sa droite. Il s'arrête quand il a rencontré n obstacles.
Notre but est de déterminer, pour n et une carte donnés, la position du robot quand il s'arrête. La réponse est donnée par le fichier texte donnant la même carte mais avec le robot dans sa position finale.
Par exemple, avec la carte précédente et n = 4, on obtiendra
...#........ ...........# O........... ..........#. ..#......... ..........#.
À faire
Écrire une fonction parcours(source:str, dest:str, n:int) qui reçoit les arguments
source, le nom du fichier contenant la carte,dest, le nom du fichier qui contiendra la réponse,n, le nombre d'obstacle avant l'arrêt.
La fonction ouvre le fichier source, détermine le parcours du robot, déduit la position finale du robot, écrit la réponse dans le fichier dest.
For several years now, in elementary schools, we have seen the emergence of a new educational model, playful programming. The students must program a small robot using assembly blocks. This allows them to get familiar with programming from an early age while exercising their logic and perception of space.
You are a student at one such school. The purpose of the exercise is simple: your teacher has crafted a circuit for your robot, told you how many moves n the robot may make, and you must find out the final position of the robot at end of execution.
To do this you need to know some principles of robot operation. – When the robot encounters an obstacle (represented by #) it turns right (on same operation) until there's no obstacle ahead anymore. Otherwise on an empty area (represented by .) it moves straight ahead. – The robot initially moves upwards. – The robot stops after n moves. – The top left corner represents the coordinates (0,0) – The robot's environment is represented as follows, where O is the robot's initial position:
