{"id":20463143,"url":"https://github.com/shubhamharitash/snakeandladder","last_synced_at":"2026-04-19T00:07:28.868Z","repository":{"id":204174858,"uuid":"711247471","full_name":"shubhamharitash/SnakeAndLadder","owner":"shubhamharitash","description":"Design Snake And Ladder | Machine Coding Round Questions ","archived":false,"fork":false,"pushed_at":"2024-04-28T05:41:57.000Z","size":10,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-16T00:55:40.112Z","etag":null,"topics":["commandlineapp","design","lld","machinecoding","sde2","sde3","snakeandladder","snakeandladdergame","snakeladder","systemdesign"],"latest_commit_sha":null,"homepage":"https://youtu.be/rwBmrSfRP0Y","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shubhamharitash.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"shubhamharitash","patreon":"shubhamharitash","open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"lfx_crowdfunding":null,"custom":null}},"created_at":"2023-10-28T16:49:17.000Z","updated_at":"2024-11-03T17:15:07.000Z","dependencies_parsed_at":null,"dependency_job_id":"1476d273-9765-4574-8f42-4925940e3854","html_url":"https://github.com/shubhamharitash/SnakeAndLadder","commit_stats":null,"previous_names":["shubhamharitash/snakeandladder"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shubhamharitash%2FSnakeAndLadder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shubhamharitash%2FSnakeAndLadder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shubhamharitash%2FSnakeAndLadder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shubhamharitash%2FSnakeAndLadder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shubhamharitash","download_url":"https://codeload.github.com/shubhamharitash/SnakeAndLadder/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242023204,"owners_count":20059297,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["commandlineapp","design","lld","machinecoding","sde2","sde3","snakeandladder","snakeandladdergame","snakeladder","systemdesign"],"created_at":"2024-11-15T13:09:33.061Z","updated_at":"2026-04-19T00:07:28.825Z","avatar_url":"https://github.com/shubhamharitash.png","language":"Java","funding_links":["https://github.com/sponsors/shubhamharitash","https://patreon.com/shubhamharitash"],"categories":[],"sub_categories":[],"readme":"# SnakeAndLadder\nDesign Snake And Ladder | Machine Coding Round Questions \n\nProblem Statement: https://workat.tech/machine-coding/practice/snake-and-ladder-problem-zgtac9lxwntg\n\nVideo Explanation Link : https://youtu.be/rwBmrSfRP0Y\n\nCreate a snake and ladder application. The application should take as input (from the command line or a file):\n\nNumber of snakes (s) followed by s lines each containing 2 numbers denoting the head and tail positions of the snake.\nNumber of ladders (l) followed by l lines each containing 2 numbers denoting the start and end positions of the ladder.\nNumber of players (p) followed by p lines each containing a name.\nAfter taking these inputs, you should print all the moves in the form of the current player name followed by a random number between 1 to 6 denoting the die roll and the initial and final position based on the move.\nFormat: \u003cplayer_name\u003e rolled a \u003cdice_value\u003e and moved from \u003cinitial_position\u003e to \u003cfinal_position\u003e\n\nWhen someone wins the game, print that the player won the game.\nFormat: \u003cplayer_name\u003e wins the game\n\nRules of the game\nThe board will have 100 cells numbered from 1 to 100.\nThe game will have a six sided dice numbered from 1 to 6 and will always give a random number on rolling it.\nEach player has a piece which is initially kept outside the board (i.e., at position 0).\nEach player rolls the dice when their turn comes.\nBased on the dice value, the player moves their piece forward that number of cells. Ex: If the dice value is 5 and the piece is at position 21, the player will put their piece at position 26 now (21+5).\nA player wins if it exactly reaches the position 100 and the game ends there.\nAfter the dice roll, if a piece is supposed to move outside position 100, it does not move.\nThe board also contains some snakes and ladders.\nEach snake will have its head at some number and its tail at a smaller number.\nWhenever a piece ends up at a position with the head of the snake, the piece should go down to the position of the tail of that snake.\nEach ladder will have its start position at some number and end position at a larger number.\nWhenever a piece ends up at a position with the start of the ladder, the piece should go up to the position of the end of that ladder.\nThere could be another snake/ladder at the tail of the snake or the end position of the ladder and the piece should go up/down accordingly.\nAssumptions you can take apart from those already mentioned in rules\nThere won’t be a snake at 100.\nThere won’t be multiple snakes/ladders at the same start/head point.\nIt is possible to reach 100, i.e., it is possible to win the game.\nSnakes and Ladders do not form an infinite loop.\nSample Input\n9\n62 5\n33 6\n49 9\n88 16\n41 20\n56 53\n98 64\n93 73\n95 75\n8\n2 37\n27 46\n10 32\n51 68\n61 79\n65 84\n71 91\n81 100\n2\nGaurav\nSagar\nSample Output\nGaurav rolled a 6 and moved from 0 to 6\nSagar rolled a 1 and moved from 0 to 1\nGaurav rolled a 6 and moved from 6 to 12\nSagar rolled a 4 and moved from 1 to 5\nGaurav rolled a 4 and moved from 12 to 16\nSagar rolled a 6 and moved from 5 to 11\nGaurav rolled a 5 and moved from 16 to 21\nSagar rolled a 4 and moved from 11 to 15\nGaurav rolled a 1 and moved from 21 to 22\nSagar rolled a 6 and moved from 15 to 21\nGaurav rolled a 6 and moved from 22 to 28\nSagar rolled a 2 and moved from 21 to 23\nGaurav rolled a 6 and moved from 28 to 34\nSagar rolled a 6 and moved from 23 to 29\nGaurav rolled a 5 and moved from 34 to 39\nSagar rolled a 2 and moved from 29 to 31\nGaurav rolled a 2 and moved from 39 to 20\nSagar rolled a 5 and moved from 31 to 36\nGaurav rolled a 3 and moved from 20 to 23\nSagar rolled a 5 and moved from 36 to 20\nGaurav rolled a 6 and moved from 23 to 29\nSagar rolled a 3 and moved from 20 to 23\nGaurav rolled a 2 and moved from 29 to 31\nSagar rolled a 3 and moved from 23 to 26\nGaurav rolled a 3 and moved from 31 to 34\nSagar rolled a 5 and moved from 26 to 31\nGaurav rolled a 3 and moved from 34 to 37\nSagar rolled a 4 and moved from 31 to 35\nGaurav rolled a 2 and moved from 37 to 39\nSagar rolled a 5 and moved from 35 to 40\nGaurav rolled a 2 and moved from 39 to 20\nSagar rolled a 5 and moved from 40 to 45\nGaurav rolled a 2 and moved from 20 to 22\nSagar rolled a 6 and moved from 45 to 68\nGaurav rolled a 3 and moved from 22 to 25\nSagar rolled a 3 and moved from 68 to 91\nGaurav rolled a 5 and moved from 25 to 30\nSagar rolled a 2 and moved from 91 to 73\nGaurav rolled a 5 and moved from 30 to 35\nSagar rolled a 6 and moved from 73 to 79\nGaurav rolled a 5 and moved from 35 to 40\nSagar rolled a 1 and moved from 79 to 80\nGaurav rolled a 4 and moved from 40 to 44\nSagar rolled a 2 and moved from 80 to 82\nGaurav rolled a 5 and moved from 44 to 9\nSagar rolled a 4 and moved from 82 to 86\nGaurav rolled a 1 and moved from 9 to 32\nSagar rolled a 6 and moved from 86 to 92\nGaurav rolled a 3 and moved from 32 to 35\nSagar rolled a 4 and moved from 92 to 96\nGaurav rolled a 1 and moved from 35 to 36\nSagar rolled a 1 and moved from 96 to 97\nGaurav rolled a 1 and moved from 36 to 37\nSagar rolled a 5 and moved from 97 to 97\nGaurav rolled a 6 and moved from 36 to 42\nSagar rolled a 3 and moved from 97 to 100\nSagar wins the game\n\nExpectations\nMake sure that you have a working and demonstrable code\nMake sure that the code is functionally correct\nCode should be modular and readable\nSeparation of concern should be addressed\nPlease do not write everything in a single file\nCode should easily accommodate new requirements and minimal changes\nThere should be a main method from where the code could be easily testable\n[Optional] Write unit tests, if possible\nNo need to create a GUI\nOptional Requirements\nPlease do these only if you’ve time left. You can write your code such that these could be accommodated without changing your code much.\n\nThe game is played with two dice instead of 1 and so the total dice value could be between 2 to 12 in a single move.\nThe board size can be customizable and can be taken as input before other input (snakes, ladders, players).\nIn case of more than 2 players, the game continues until only one player is left.\nOn getting a 6, you get another turn and on getting 3 consecutive 6s, all the three of those get cancelled.\nOn starting the application, the snakes and ladders should be created programmatically without any user input, keeping in mind the constraints mentioned in rules.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshubhamharitash%2Fsnakeandladder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshubhamharitash%2Fsnakeandladder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshubhamharitash%2Fsnakeandladder/lists"}