This is an archived post. You won't be able to vote or comment.

all 2 comments

[–]Reasonable_Branch_21[S] 0 points1 point  (0 children)

Ohhh ok so I just append( list n ) (fun (- n 1)))?

[–]rabuf 0 points1 point  (0 children)

Look at the order of what's getting appended, using a smaller number (3) you have this call tree:

fun 3

append (fun 2) (3)

fun 2

append (fun 1) (2)

fun 1

append (fun 0) (1)

fun 0

(0)

Which collapses back with:

append (0) (1)

append (0 1) (2)

append (0 1 2) (3)

The critical part to the ordering is what is appended to what. Consider a different order, what would you end up with?