Snake and ladder is a unique puzzle-like problem. The problem is approached and solved using the BFS(Breadth-First Search) technique in C++ language.
In the snake and ladder problem, if we reach the bottom of the ladder, we should go to the top, and if we reach the head of the snake, we should follow along its tail to reach its bottom. Due to this condition, we should avoid snakehead blocks at all costs to find the minimum number of dice rolls.
The problem is approached and solved using the BFS(Breadth-First Search) technique. The idea is to imagine all the next 6 consecutive numbers as the present block's neighbours because dice can roll from 1 to 6. Now all the neighbours are pushed into the queue, and classic BFS is done with visited stamping. The code is further commented on for better understanding.
Please check the zip for output as it couldn't be uploaded like previous images due to some error.
Submitted by Lokesh Madhav S (2208loki)
Download packets of source code on Coders Packet