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

잔글 (봇: 자동으로 텍스트 교체 (-</source> +</syntaxhighlight>, -<source +<syntaxhighlight ))
 
1번째 줄: 1번째 줄:
==Kotlin==
==Kotlin==
{{카타|7급|Kotlin|2}}
{{카타|7급|Kotlin|2}}
<source lang='kotlin'>
<syntaxhighlight lang='kotlin'>
</source>
</syntaxhighlight>
<source lang='kotlin'>
<syntaxhighlight lang='kotlin'>
</source>
</syntaxhighlight>
<source lang='kotlin'>
<syntaxhighlight lang='kotlin'>
</source>
</syntaxhighlight>


==R==
==R==
{{카타|7급|R|2}}
{{카타|7급|R|2}}
<source lang='r'>
<syntaxhighlight lang='r'>
nbDig <- function(n, d) {
nbDig <- function(n, d) {
   sum(strsplit(paste(as.integer((0:n)^2),collapse=''),'')[[1]]==d)
   sum(strsplit(paste(as.integer((0:n)^2),collapse=''),'')[[1]]==d)
}
}
</source>
</syntaxhighlight>
<source lang='r'>
<syntaxhighlight lang='r'>
nbDig <- function(n, d) {
nbDig <- function(n, d) {
   nchar( gsub(paste('[^',d,']'), '', paste(as.integer((0:n)^2),collapse='')) )
   nchar( gsub(paste('[^',d,']'), '', paste(as.integer((0:n)^2),collapse='')) )
}
}
</source>
</syntaxhighlight>
<source lang='r'>
<syntaxhighlight lang='r'>
nbDig <- function(n, d) {
nbDig <- function(n, d) {
  options(scipen=100)
  options(scipen=100)
  sum(strsplit(paste((0:n)^2,collapse=""),"")[[1]]==d)
  sum(strsplit(paste((0:n)^2,collapse=""),"")[[1]]==d)
}
}
</source>
</syntaxhighlight>
<source lang='r'>
<syntaxhighlight lang='r'>
library(stringr)
library(stringr)
nbDig <- function(n, d) {
nbDig <- function(n, d) {
32번째 줄: 32번째 줄:
   sum(str_count(as.character(v*v), as.character(d)))
   sum(str_count(as.character(v*v), as.character(d)))
}
}
</source>
</syntaxhighlight>
<source lang='r'>
<syntaxhighlight lang='r'>
library(stringr)
library(stringr)
nbDig <- function(n, d) {
nbDig <- function(n, d) {
   sum(str_count(as.character(as.integer((0:n)^2)), as.character(d)))
   sum(str_count(as.character(as.integer((0:n)^2)), as.character(d)))
}
}
</source>
</syntaxhighlight>

2020년 11월 2일 (월) 02:55 기준 최신판

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