ダーツの問題.正解者少ない割に簡単な問題だった.
222ms.ベクトルで計算するように工夫したらもっと早くできそう.
あと実はProblem 108と110も答えは出てるんだけどやり方がひどすぎるのとさっぱり改善できないのでとりあえず後回しにしてます.
## 終了はダブル throw.last <- c(1:20*2, 50) ## 1, 2投目は全てのパターン throw <- c(1:20, 1:20*2, 1:20*3, 25, 50) ## 得点が100未満のチェックアウトをカウント count <- numeric(1) limit <- 100 ## 1投だけヒット count <- count + length(throw.last[throw.last < limit]) ## 2投だけヒット for(i in throw.last){ count <- count + sum(i + throw < limit) } ## 3投ヒット for(i in throw.last){ for(j in 1:length(throw)){ for(k in 1:j){ if(sum(c(i, throw[c(j,k)])) < limit) count <- count + 1 } } } count