#!/usr/bin/perl

print "This recursive routine finds the number of paths after r blocks.\n";
print "Enter r: "; $r = <STDIN>; chomp($r);

$p = streets($r, $r);

print "The number of paths is $p.\n";

sub streets {
  my($a, $b) = @_;
  if ($b == 0) {
    return 1;
  } elsif ($b == $a + 1) {
    return streets($a, $b - 1);
  } else {
    return streets($a, $b - 1) + streets($a - 1, $b);
  }
}
