Skip to content

Instantly share code, notes, and snippets.

@fedeisas
Created February 20, 2017 23:21
Show Gist options
  • Save fedeisas/cb0df94f7ff37870d30022a75ec4e7cc to your computer and use it in GitHub Desktop.
Save fedeisas/cb0df94f7ff37870d30022a75ec4e7cc to your computer and use it in GitHub Desktop.
% Define a function pieces so that pieces(N) tells you the maximum number of pieces into which you can cut a piece of paper with N cuts.
% You can see an illustration of this problem at the top of this step.
% If you’d like to take this problem further, think about the 3-dimensional case. Into how many pieces can you cut a wooden block with N saw cuts?
% Taking it even further: What is the general problem in n dimensions?
-module(howManyPieces).
-export([howManyPieces/1]).
howManyPieces(0) ->
1;
howManyPieces(X) when X > 0 ->
X + howManyPieces(X - 1).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment