Loading [MathJax]/jax/output/CommonHTML/jax.js
Back
Close

Basics of Recursive Programming (recitation)

madooei
920 views

Count Paths

Meet bugbug the Caterpillar.

Imagine bugbug is in an M by N grid. He starts at the bottom left corner, (0,0), and wants to end up at the top right corner (M1,N1).

Bugbug is only capable of moving right or up. Write a function count_paths that takes a grid length and width and returns the number of different paths bugbug can take from the start to the goal. (There is a closed-form solution to this problem, but try to answer it procedurally using recursion.)

Implement count_paths
// { autofold
package com.yourself;
public class CountPath {
// }
// Goal: count how many different paths one can take in order to get from
// the bottom left corner to the top right corner of a grid.
// Constraint: you can only move right or up.
// Parameters: eight and width correspond the size of a rectangle grid.
// REQUIRES: width >= 1 && height >= 1
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Create your playground on Tech.io
This playground was created on Tech.io, our hands-on, knowledge-sharing platform for developers.
Go to tech.io
codingame x discord
Join the CodinGame community on Discord to chat about puzzle contributions, challenges, streams, blog articles - all that good stuff!
JOIN US ON DISCORD
Online Participants