How would you program Pascal's triangle in R?

后端 未结 2 1163
轻奢々
轻奢々 2020-12-21 04:09

I am reading, on my own (not for HW) about programming, and one exercise involved programming Pascal\'s triangle in R. My first idea was to make a list and then append thin

2条回答
  •  无人及你
    2020-12-21 04:39

    using a property of the Pascal triangle:

    x <- 1
    print(x)
    for (i in 1:10) { x <- c(0, x) + c(x, 0); print(x) }
    

    I suppose this code is very fast.

提交回复
热议问题