Brick Tower Building Puzzle

前端 未结 2 1811
你的背包
你的背包 2021-01-16 19:27

I\'ve been given a little brainteaser to solve.

The task is to make a function with a single integer parameter. You have to figure out how many different combination

2条回答
  •  滥情空心
    2021-01-16 20:12

    Imagine calling the function answer(6). Your code returns 2, the correct answer however is 3 (5, 1; 4, 2; 3, 2, 1). Why is this? your code stops when the amount of blocks above the bottom tower is greater than the length of the bottom tower, so it sees 3, 3 and stops, it therefor never considers the combination 3, 2, 1.

    My advice would be to rethink the function, try to take into account the idea that you can stack a number of blocks N on top of a tower that is less than N high.

提交回复
热议问题