fork download
  1. is_kaprekar <- function(n) {
  2.  
  3. nch <- unlist(strsplit(format(n^2, scientific = FALSE), ""))
  4. len <- length(nch)
  5.  
  6. if(len < 2) {
  7. return(FALSE)
  8. }
  9.  
  10. for(i in 1:(len - 1)) {
  11. first <- as.integer(paste0(nch[1:i], collapse = ""))
  12. second <- as.integer(paste0(nch[(i+1):length(nch)], collapse = ""))
  13. if(first + second == n && (second > 0)) {
  14. cat(first, "+", second, "=", n,"\n")
  15. return(TRUE)
  16. }
  17. }
Success #stdin #stdout #stderr 0.22s 60752KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Error: unexpected end of input
Execution halted