"카타 7급 Moves in squared strings (I)"의 두 판 사이의 차이

(새 문서: ==R== {{카타|7급|R|3}} <source lang='r'> </source>)
 
2번째 줄: 2번째 줄:
{{카타|7급|R|3}}
{{카타|7급|R|3}}
<source lang='r'>
<source lang='r'>
reverseString <- function(s) {
  paste(rev(unlist(strsplit(s,""))),collapse="")
}
vertMirror <- function(s) {
  paste(lapply(unlist(strsplit(s,"\n")), reverseString),collapse="\n")
}
horMirror <- function(s) {
  paste(rev(unlist(strsplit(s,"\n"))),collapse="\n")
}
oper <- function(f, s) {
  f(s)
}
</source>
<source lang='r'>
vertMirror <- function(s) {
    res <- lapply(strsplit(s, "\n")[[1]],
    (function (str) paste(rev(strsplit(str, "")[[1]]), collapse = "")))
    return (paste(res, collapse = '\n'))
}
horMirror <- function(s) {
    res <- rev(strsplit(s, "\n")[[1]])
    return (paste(res, collapse = "\n"))
}
oper <- function(f, s) {
  return (f(s))
}
</source>
<source lang='r'>
library(stringi)
vertMirror <- function(s) {
  paste(Map(stri_reverse, unlist(strsplit(s,"\n"))), collapse="\n")
}
horMirror <- function(s) {
  paste(rev(unlist(strsplit(s,"\n"))), collapse="\n")
}
oper <- function(f, s) {
  f(s)
}
</source>
</source>

2019년 5월 3일 (금) 01:24 판

R

reverseString <- function(s) {
  paste(rev(unlist(strsplit(s,""))),collapse="")
}
vertMirror <- function(s) {
  paste(lapply(unlist(strsplit(s,"\n")), reverseString),collapse="\n")
}
horMirror <- function(s) {
  paste(rev(unlist(strsplit(s,"\n"))),collapse="\n")
}
oper <- function(f, s) {
  f(s)
}
vertMirror <- function(s) {
    res <- lapply(strsplit(s, "\n")[[1]],
    (function (str) paste(rev(strsplit(str, "")[[1]]), collapse = "")))
    return (paste(res, collapse = '\n'))
}
horMirror <- function(s) {
    res <- rev(strsplit(s, "\n")[[1]])
    return (paste(res, collapse = "\n"))
}
oper <- function(f, s) {
   return (f(s))
}
library(stringi)
vertMirror <- function(s) {
  paste(Map(stri_reverse, unlist(strsplit(s,"\n"))), collapse="\n")
}
horMirror <- function(s) {
  paste(rev(unlist(strsplit(s,"\n"))), collapse="\n")
}
oper <- function(f, s) {
  f(s)
}
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}