blog/assets/js/d1aceb2e.b4411d5f.js

1 line
12 KiB
JavaScript
Raw Normal View History

"use strict";(self.webpackChunkfi=self.webpackChunkfi||[]).push([[1353],{1466:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>a,contentTitle:()=>s,default:()=>h,frontMatter:()=>i,metadata:()=>l,toc:()=>d});var o=t(5893),r=t(1151);const i={id:"karel-1",title:"Recursion and backtracking with Robot Karel",description:"A problem with too many restrictions.\n",tags:["python","karel","recursion","backtracking"],last_update:{date:new Date("2022-11-29T00:00:00.000Z")}},s=void 0,l={id:"recursion/karel-1",title:"Recursion and backtracking with Robot Karel",description:"A problem with too many restrictions.\n",source:"@site/algorithms/04-recursion/2022-11-29-karel-1.md",sourceDirName:"04-recursion",slug:"/recursion/karel-1",permalink:"/algorithms/recursion/karel-1",draft:!1,unlisted:!1,editUrl:"https://github.com/mfocko/blog/tree/main/algorithms/04-recursion/2022-11-29-karel-1.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"}],version:"current",lastUpdatedAt:166968e4,formattedLastUpdatedAt:"Nov 29, 2022",frontMatter:{id:"karel-1",title:"Recursion and backtracking with Robot Karel",description:"A problem with too many restrictions.\n",tags:["python","karel","recursion","backtracking"],last_update:{date:"2022-11-29T00:00:00.000Z"}},sidebar:"autogeneratedBar",previous:{title:"Recursion",permalink:"/algorithms/category/recursion"},next:{title:"Introduction to dynamic programming",permalink:"/algorithms/recursion/pyramid-slide-down"}},a={},d=[{value:"Introduction",id:"introduction",level:2},{value:"Your environment and problem description",id:"your-environment-and-problem-description",level:2},{value:"Environment",id:"environment",level:3},{value:"Interface",id:"interface",level:3},{value:"Problem",id:"problem",level:3},{value:"Simple problem to get familiar with the robot",id:"simple-problem-to-get-familiar-with-the-robot",level:2},{value:"Brainstorm the idea",id:"brainstorm-the-idea",level:2},{value:"\xbbRough\xab pseudocode",id:"rough-pseudocode",level:2},{value:"\xbbProper\xab pseudocode",id:"proper-pseudocode",level:2},{value:"Library",id:"library",level:2},{value:"Solution",id:"solution",level:2}];function c(e){const n={a:"a",admonition:"admonition",code:"code",em:"em",h2:"h2",h3:"h3",img:"img",li:"li",p:"p",strong:"strong",ul:"ul",...(0,r.a)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(n.ul,{children:["\n",(0,o.jsx)(n.li,{children:(0,o.jsx)(n.a,{href:"pathname:///files/algorithms/recursion/karel-1.tar.gz",children:"Sources"})}),"\n"]}),"\n",(0,o.jsx)(n.h2,{id:"introduction",children:"Introduction"}),"\n",(0,o.jsx)(n.p,{children:"In this exercise we will be working with a Robot Karel and with a \xbbvery\xab limited\nresources. The point of this exercise is to show how powerful recursion and\nbacktracking can be even without anything else at your hand."}),"\n",(0,o.jsx)(n.h2,{id:"your-environment-and-problem-description",children:"Your environment and problem description"}),"\n",(0,o.jsx)(n.h3,{id:"environment",children:"Environment"}),"\n",(0,o.jsx)(n.p,{children:"You are given a robot that is present in a maze and is looking for an exit. Maze\nconsists of different walls and exit is marked with a single so-called \u201cbeeper\u201d."}),"\n",(0,o.jsx)(n.p,{children:"Walking into a wall results in a permanent damage of the robot."}),"\n",(0,o.jsx)(n.h3,{id:"interface",children:"Interface"}),"\n",(0,o.jsx)(n.p,{children:"You can control the robot using the following interface:"}),"\n",(0,o.jsxs)(n.ul,{children:["\n",(0,o.jsxs)(n.li,{children:["actions \u200b\xad\u2014 you can use them to change the current state of the robot and its\nsurroundings","\n",(0,o.jsxs)(n.ul,{children:["\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.code,{children:"robot.step()"})," \u2014 moves robot one step further"]}),"\n",(0,o.jsxs)(n.li,{children:[(0,o.jsx)(n.code,{children:"robot.turn_left()"})," \u2014 turns robot 90-degrees counter-clockwise","\n",(0,o.js