Problem 116と同じような問題.今度は違う長さのタイルを混ぜて使った場合の合計パターンを求める.ユニットの長さは同じく50.また,タイルを入れないパターンもカウントする.
これもProblem 114-116と同じように解けるのでもうほとんど考えてない.2ms.久しぶりに綺麗に解けている.
## 列の長さをn+1にしたときのパタン n.plus <- function(tile, n = 50){ tile.new <- numeric(n+1) tile.new[1] <- sum(tile[2:(n+1)]) + sum(tile[3:(n+1)]) + sum(tile[4:(n+1)]) tile.new[2:(n+1)] <- tile[1:n] return(tile.new) } ## 長さnの列にタイルを敷き詰めるパタン pattern <- function(n){ tile <- numeric(n+1) tile[2] <- 1 for(i in 2:n) tile <- n.plus(tile, n) sum(tile) } as.character(pattern(50))