blog/assets/js/30814625.1cb0ad07.js

1 line
16 KiB
JavaScript
Raw Normal View History

"use strict";(self.webpackChunkfi=self.webpackChunkfi||[]).push([[115],{78416:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>a,contentTitle:()=>o,default:()=>c,frontMatter:()=>i,metadata:()=>l,toc:()=>d});var r=t(85893),s=t(11151);const i={id:"solution",slug:"/recursion/karel/solution",title:"Solution to the problem",description:"Solving the problem introduced in the previous post.\n",tags:["python","karel","recursion","backtracking","solution"],last_update:{date:new Date("2023-12-24T00:00:00.000Z")}},o="Solving the maze problem",l={id:"recursion/2022-11-29-karel/solution",title:"Solution to the problem",description:"Solving the problem introduced in the previous post.\n",source:"@site/algorithms/04-recursion/2022-11-29-karel/2023-12-24-solution.md",sourceDirName:"04-recursion/2022-11-29-karel",slug:"/recursion/karel/solution",permalink:"/algorithms/recursion/karel/solution",draft:!1,unlisted:!1,editUrl:"https://github.com/mfocko/blog/tree/main/algorithms/04-recursion/2022-11-29-karel/2023-12-24-solution.md",tags:[{label:"python",permalink:"/algorithms/tags/python"},{label:"karel",permalink:"/algorithms/tags/karel"},{label:"recursion",permalink:"/algorithms/tags/recursion"},{label:"backtracking",permalink:"/algorithms/tags/backtracking"},{label:"solution",permalink:"/algorithms/tags/solution"}],version:"current",lastUpdatedAt:1703376e3,formattedLastUpdatedAt:"Dec 24, 2023",frontMatter:{id:"solution",slug:"/recursion/karel/solution",title:"Solution to the problem",description:"Solving the problem introduced in the previous post.\n",tags:["python","karel","recursion","backtracking","solution"],last_update:{date:"2023-12-24T00:00:00.000Z"}},sidebar:"autogeneratedBar",previous:{title:"Recursion and backtracking with Robot Karel",permalink:"/algorithms/recursion/karel"},next:{title:"Introduction to dynamic programming",permalink:"/algorithms/recursion/pyramid-slide-down"}},a={},d=[{value:"Summary of the problem",id:"summary-of-the-problem",level:2},{value:"Brainstorming the idea",id:"brainstorming-the-idea",level:2},{value:"\xbbRough\xab pseudocode",id:"rough-pseudocode",level:2},{value:"\xbbProper\xab pseudocode",id:"proper-pseudocode",level:2},{value:"Actual implementation",id:"actual-implementation",level:2},{value:"Testing",id:"testing",level:2},{value:"Fixing the issue",id:"fixing-the-issue",level:2}];function u(e){const n={a:"a",admonition:"admonition",code:"code",em:"em",h1:"h1",h2:"h2",li:"li",ol:"ol",p:"p",pre:"pre",section:"section",strong:"strong",sup:"sup",ul:"ul",...(0,s.a)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(n.h1,{id:"solving-the-maze-problem",children:"Solving the maze problem"}),"\n",(0,r.jsx)(n.p,{children:"We will go through the given problem the same way as I have suggested in the\nprevious post."}),"\n",(0,r.jsx)(n.h2,{id:"summary-of-the-problem",children:"Summary of the problem"}),"\n",(0,r.jsxs)(n.p,{children:["We have a robot in some kind of a maze and we have to find our way out that is\nmarked with a so-called \u201cbeeper\u201d. We've been given a restriction ",(0,r.jsx)(n.strong,{children:"not to"})," use\nany variables, we can use just backtracking and recursion."]}),"\n",(0,r.jsx)(n.h2,{id:"brainstorming-the-idea",children:"Brainstorming the idea"}),"\n",(0,r.jsx)(n.p,{children:"Let's start with some brainstorming of the solution."}),"\n",(0,r.jsxs)(n.ul,{children:["\n",(0,r.jsxs)(n.li,{children:["How will I know what I've checked without any variables?","\n",(0,r.jsxs)(n.ul,{children:["\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.em,{children:"answer"}),": recursion will need to take care of that, cause I'm not allowed\nanything else"]}),"\n"]}),"\n"]}),"\n",(0,r.jsxs)(n.li,{children:["How will I pass around the fact I've found the exit?","\n",(0,r.jsxs)(n.ul,{children:["\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.em,{children:"answer"}),": I can return values from helper functions, so I should be able to\nindicate ",(0,r.jsx)(n.em,{children:"found"}),"/",(0,r.jsx)(n.em,{children:"not found"})]}),"\n"]}),"\n"]}),"\n",(0,r.jsxs)(n.li,{children:["How is the exit marked?","\n",(0,r