"카타 7급 Count the Digit"의 두 판 사이의 차이

12번째 줄: 12번째 줄:
<source lang='r'>
<source lang='r'>
nbDig <- function(n, d) {
nbDig <- function(n, d) {
options(scipen=100)
  sum(strsplit(paste(as.integer((0:n)^2),collapse=''),'')[[1]]==d)
sum(strsplit(paste((0:n)^2,collapse=""),"")[[1]]==d)
}
}
</source>
</source>
<source lang='r'>
<source lang='r'>
nbDig <- function(n, d) {
nbDig <- function(n, d) {
   sum(strsplit(paste(as.integer((0:n)^2),collapse=''),'')[[1]]==d)
   nchar( gsub(paste('[^',d,']'), '', paste(as.integer((0:n)^2),collapse='')) )
}
}
</source>
</source>
<source lang='r'>
<source lang='r'>
nbDig <- function(n, d) {
nbDig <- function(n, d) {
  nchar( gsub(paste('[^',d,']'), '', paste(as.integer((0:n)^2),collapse='')) )
options(scipen=100)
sum(strsplit(paste((0:n)^2,collapse=""),"")[[1]]==d)
}
}
</source>
</source>

2019년 4월 25일 (목) 02:11 판

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 }}