카타 7급 Count the Digit

1 Kotlin[ | ]

2 R[ | ]

nbDig <- function(n, d) {
  sum(strsplit(paste(as.integer((0:n)^2),collapse=''),'')[[1]]==d)
}
nbDig <- function(n, d) {
  nchar( gsub(paste('[^',d,']'), '', paste(as.integer((0:n)^2),collapse='')) )
}
nbDig <- function(n, d) {
 options(scipen=100)
 sum(strsplit(paste((0:n)^2,collapse=""),"")[[1]]==d)
}
library(stringr)
nbDig <- function(n, d) {
  v <- 0:n
  sum(str_count(as.character(v*v), as.character(d)))
}
library(stringr)
nbDig <- function(n, d) {
  sum(str_count(as.character(as.integer((0:n)^2)), as.character(d)))
}
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}