# A Common-Sense Guide to Data Structures and Algorithms, Second Edition: number\_of\_paths implementations are not equivalent (pg. 176/177)

**URL:** <https://forum.devtalk.com/t/a-common-sense-guide-to-data-structures-and-algorithms-second-edition-number-of-paths-implementations-are-not-equivalent-pg-176-177/25807>\
**Category:** PragProg Customers\
**Tags:** book-a-common-sense-guide-to-data-structures-and-algorithms-second-edition, errata\
**Created:** [19 October 2021 11:01 UTC](https://forum.devtalk.com/t/a-common-sense-guide-to-data-structures-and-algorithms-second-edition-number-of-paths-implementations-are-not-equivalent-pg-176-177/25807 "2021-10-19T11:01:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![iwc](https://forum.devtalk.com/user_avatar/forum.devtalk.com/iwc/32/3512_2.png) [@iwc](https://forum.devtalk.com/u/iwc)\
**Post date:** [19 October 2021 11:01 UTC](https://forum.devtalk.com/t/a-common-sense-guide-to-data-structures-and-algorithms-second-edition-number-of-paths-implementations-are-not-equivalent-pg-176-177/25807/1 "2021-10-19T11:01:43Z")

</div>

There are two provided implementations for the `number_of_paths` function. The ‘hardcoded’ version is correct, but the simplified version is not.

**pg. 176**

```auto
def number_of_paths(n):
  return 0 if n <= 0
  return 1 if n == 1
  return 2 if n == 2
  return 4 if n == 3
  return number_of_paths(n - 1) + number_of_paths(n - 2) + number_of_paths(n - 3)
end

```

**pg. 177**

```auto
def number_of_paths(n):
  return 0 if n < 0
  return 1 if n == 1 || n == 0
  return number_of_paths(n - 1) + number_of_paths(n - 2) + number_of_paths(n - 3)
end

```

Page 177’s implementation returns 1 instead of 0 for `number_of_paths(0)`.

---

<div class="post-metadata">

**Author:** ![jaywengrow](https://forum.devtalk.com/user_avatar/forum.devtalk.com/jaywengrow/32/527_2.png) [@jaywengrow](https://forum.devtalk.com/u/jaywengrow)\
**Post date:** [10 March 2023 03:03 UTC](https://forum.devtalk.com/t/a-common-sense-guide-to-data-structures-and-algorithms-second-edition-number-of-paths-implementations-are-not-equivalent-pg-176-177/25807/2 "2023-03-10T03:03:17Z")

</div>

Thanks for submitting this. While you are correct that the two methods are not identical in this regard, that is by design. I explain there in the text between the two versions that in the simplified version, we are “rigging” the base case of 0 to return 1 for the very sake of simplifying the code. I hope that helps!
