SlideShare a Scribd company logo
1 of 1
Download to read offline
Karel Goes Home Karel the Robot lives in a world composed of streets and avenues laid out in a
regular rectangular grid that looks like this:
Where each column is from 1 to 5 Suppose that Karel is sitting on the intersection of 2nd Street
and 3rd Avenue as shown in the diagram and wants to get back to the origin at 1st Street and 1st
Avenue. Even if Karel wants to avoid going out of the way, there are still several equally short
paths. For example, in this diagram there are three possible routes, as follows:
Move left, then left, then down.
Move left, then down, then left.
Move down, then left, then left.
Your job in this problem is to design a recursive function int numPathsHome(int street, int
avenue) that returns the number of paths Karel could take back to the origin from the specified
starting position, subject to the condition that Karel doesn't want to take any unnecessary steps
and can therefore only move west or south (left or down in the diagram).
Watch out for the edge case where the street or avenue numbers are zero or below!

More Related Content

More from alkagifts345

Lea CA14-5 �tica (emisi�n de bonos) que se encuentra al final de los.pdf
Lea CA14-5 �tica (emisi�n de bonos) que se encuentra al final de los.pdfLea CA14-5 �tica (emisi�n de bonos) que se encuentra al final de los.pdf
Lea CA14-5 �tica (emisi�n de bonos) que se encuentra al final de los.pdf
alkagifts345
 
Lea el caso en Keith Dunn and McGuffeys Restaurant y responda las.pdf
Lea el caso en Keith Dunn and McGuffeys Restaurant y responda las.pdfLea el caso en Keith Dunn and McGuffeys Restaurant y responda las.pdf
Lea el caso en Keith Dunn and McGuffeys Restaurant y responda las.pdf
alkagifts345
 
Lea el art�culo a continuaci�n en 150-200 palabras, proporcione un b.pdf
Lea el art�culo a continuaci�n en 150-200 palabras, proporcione un b.pdfLea el art�culo a continuaci�n en 150-200 palabras, proporcione un b.pdf
Lea el art�culo a continuaci�n en 150-200 palabras, proporcione un b.pdf
alkagifts345
 
Lea el estudio de caso adjunto 2X y prep�rese para discutir y respon.pdf
Lea el estudio de caso adjunto 2X y prep�rese para discutir y respon.pdfLea el estudio de caso adjunto 2X y prep�rese para discutir y respon.pdf
Lea el estudio de caso adjunto 2X y prep�rese para discutir y respon.pdf
alkagifts345
 
Las cosas iban bien para Brenna durante la primera semana despu�s de.pdf
Las cosas iban bien para Brenna durante la primera semana despu�s de.pdfLas cosas iban bien para Brenna durante la primera semana despu�s de.pdf
Las cosas iban bien para Brenna durante la primera semana despu�s de.pdf
alkagifts345
 

More from alkagifts345 (20)

Leadership ReflectionReflect on a leadership or follower role you .pdf
Leadership ReflectionReflect on a leadership or follower role you .pdfLeadership ReflectionReflect on a leadership or follower role you .pdf
Leadership ReflectionReflect on a leadership or follower role you .pdf
 
Lea CA14-5 �tica (emisi�n de bonos) que se encuentra al final de los.pdf
Lea CA14-5 �tica (emisi�n de bonos) que se encuentra al final de los.pdfLea CA14-5 �tica (emisi�n de bonos) que se encuentra al final de los.pdf
Lea CA14-5 �tica (emisi�n de bonos) que se encuentra al final de los.pdf
 
Lea el siguiente pasaje y responda las preguntas que siguen.ht.pdf
Lea el siguiente pasaje y responda las preguntas que siguen.ht.pdfLea el siguiente pasaje y responda las preguntas que siguen.ht.pdf
Lea el siguiente pasaje y responda las preguntas que siguen.ht.pdf
 
Lea el caso en Keith Dunn and McGuffeys Restaurant y responda las.pdf
Lea el caso en Keith Dunn and McGuffeys Restaurant y responda las.pdfLea el caso en Keith Dunn and McGuffeys Restaurant y responda las.pdf
Lea el caso en Keith Dunn and McGuffeys Restaurant y responda las.pdf
 
Lea el art�culo a continuaci�n en 150-200 palabras, proporcione un b.pdf
Lea el art�culo a continuaci�n en 150-200 palabras, proporcione un b.pdfLea el art�culo a continuaci�n en 150-200 palabras, proporcione un b.pdf
Lea el art�culo a continuaci�n en 150-200 palabras, proporcione un b.pdf
 
Lea el estudio de caso adjunto 2X y prep�rese para discutir y respon.pdf
Lea el estudio de caso adjunto 2X y prep�rese para discutir y respon.pdfLea el estudio de caso adjunto 2X y prep�rese para discutir y respon.pdf
Lea el estudio de caso adjunto 2X y prep�rese para discutir y respon.pdf
 
Law Enforcement Agencies are having a difficult time addressing poli.pdf
Law Enforcement Agencies are having a difficult time addressing poli.pdfLaw Enforcement Agencies are having a difficult time addressing poli.pdf
Law Enforcement Agencies are having a difficult time addressing poli.pdf
 
Laurel Co. is a U.S.-based company with US dollar costs and with rev.pdf
Laurel Co. is a U.S.-based company with US dollar costs and with rev.pdfLaurel Co. is a U.S.-based company with US dollar costs and with rev.pdf
Laurel Co. is a U.S.-based company with US dollar costs and with rev.pdf
 
Las acciones de Dravo Corporation actualmente pagan un dividendo ( D.pdf
Las acciones de Dravo Corporation actualmente pagan un dividendo ( D.pdfLas acciones de Dravo Corporation actualmente pagan un dividendo ( D.pdf
Las acciones de Dravo Corporation actualmente pagan un dividendo ( D.pdf
 
Las barreras para una comunicaci�n efectiva incluyen todas las sigui.pdf
Las barreras para una comunicaci�n efectiva incluyen todas las sigui.pdfLas barreras para una comunicaci�n efectiva incluyen todas las sigui.pdf
Las barreras para una comunicaci�n efectiva incluyen todas las sigui.pdf
 
Las medidas del �xito del entrenamiento generalmente incluyen todo l.pdf
Las medidas del �xito del entrenamiento generalmente incluyen todo l.pdfLas medidas del �xito del entrenamiento generalmente incluyen todo l.pdf
Las medidas del �xito del entrenamiento generalmente incluyen todo l.pdf
 
Las elecciones no partidistas, a menudo utilizadas a nivel local, el.pdf
Las elecciones no partidistas, a menudo utilizadas a nivel local, el.pdfLas elecciones no partidistas, a menudo utilizadas a nivel local, el.pdf
Las elecciones no partidistas, a menudo utilizadas a nivel local, el.pdf
 
Las neuronas reales exhiben din�micas temporales que son capturadas .pdf
Las neuronas reales exhiben din�micas temporales que son capturadas .pdfLas neuronas reales exhiben din�micas temporales que son capturadas .pdf
Las neuronas reales exhiben din�micas temporales que son capturadas .pdf
 
Las cosas iban bien para Brenna durante la primera semana despu�s de.pdf
Las cosas iban bien para Brenna durante la primera semana despu�s de.pdfLas cosas iban bien para Brenna durante la primera semana despu�s de.pdf
Las cosas iban bien para Brenna durante la primera semana despu�s de.pdf
 
Larry is single and wants his two children to receive the $5,000 in .pdf
Larry is single and wants his two children to receive the $5,000 in .pdfLarry is single and wants his two children to receive the $5,000 in .pdf
Larry is single and wants his two children to receive the $5,000 in .pdf
 
Lake Shore Medical Center wants to keep track of all administrative .pdf
Lake Shore Medical Center wants to keep track of all administrative .pdfLake Shore Medical Center wants to keep track of all administrative .pdf
Lake Shore Medical Center wants to keep track of all administrative .pdf
 
Lafayette, Inc., 1 Ocak 2014te kuruldu. Lafayette, o tarihte .pdf
Lafayette, Inc., 1 Ocak 2014te kuruldu. Lafayette, o tarihte .pdfLafayette, Inc., 1 Ocak 2014te kuruldu. Lafayette, o tarihte .pdf
Lafayette, Inc., 1 Ocak 2014te kuruldu. Lafayette, o tarihte .pdf
 
Labrum & Doak LLP was a law partnership that began in 1904 in Pennsy.pdf
Labrum & Doak LLP was a law partnership that began in 1904 in Pennsy.pdfLabrum & Doak LLP was a law partnership that began in 1904 in Pennsy.pdf
Labrum & Doak LLP was a law partnership that began in 1904 in Pennsy.pdf
 
La subsidiaria del Reino Unido de Yeastfeast & Co mide el inventario.pdf
La subsidiaria del Reino Unido de Yeastfeast & Co mide el inventario.pdfLa subsidiaria del Reino Unido de Yeastfeast & Co mide el inventario.pdf
La subsidiaria del Reino Unido de Yeastfeast & Co mide el inventario.pdf
 
La Sra. Jones es una mujer de 75 a�os que sufri� un infarto de mioca.pdf
La Sra. Jones es una mujer de 75 a�os que sufri� un infarto de mioca.pdfLa Sra. Jones es una mujer de 75 a�os que sufri� un infarto de mioca.pdf
La Sra. Jones es una mujer de 75 a�os que sufri� un infarto de mioca.pdf
 

Recently uploaded

Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
KarakKing
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
AnaAcapella
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 

Recently uploaded (20)

Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 

Karel Goes Home Karel the Robot lives in a world composed of streets.pdf

  • 1. Karel Goes Home Karel the Robot lives in a world composed of streets and avenues laid out in a regular rectangular grid that looks like this: Where each column is from 1 to 5 Suppose that Karel is sitting on the intersection of 2nd Street and 3rd Avenue as shown in the diagram and wants to get back to the origin at 1st Street and 1st Avenue. Even if Karel wants to avoid going out of the way, there are still several equally short paths. For example, in this diagram there are three possible routes, as follows: Move left, then left, then down. Move left, then down, then left. Move down, then left, then left. Your job in this problem is to design a recursive function int numPathsHome(int street, int avenue) that returns the number of paths Karel could take back to the origin from the specified starting position, subject to the condition that Karel doesn't want to take any unnecessary steps and can therefore only move west or south (left or down in the diagram). Watch out for the edge case where the street or avenue numbers are zero or below!