Sha256: 63e2591b2fe2c408f76f2262647f5dfd5410c879a05a3a92e4b1a290caa3a4a8

Contents?: true

Size: 376 Bytes

Versions: 26

Compression:

Stored size: 376 Bytes

Contents

is_perfect <- function(n){
  
  find_factors <- function(n) {
    factors <- c()
    for (i in 2:floor(n^0.5 + 1)) {
      
      if (n %% i == 0) {
        if (i^2 != n) {
          factors <- c(factors, i, n / i)
        }
        else {
          factors <- c(factors, i)
        }
      }
            
    }
    unique(factors)
  }
  
  sum(find_factors(n)) + 1 == n
  
}

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
trackler-2.1.0.48 tracks/r/exercises/perfect-numbers/example.R
trackler-2.1.0.47 tracks/r/exercises/perfect-numbers/example.R
trackler-2.1.0.46 tracks/r/exercises/perfect-numbers/example.R
trackler-2.1.0.45 tracks/r/exercises/perfect-numbers/example.R
trackler-2.1.0.44 tracks/r/exercises/perfect-numbers/example.R
trackler-2.1.0.43 tracks/r/exercises/perfect-numbers/example.R
trackler-2.1.0.42 tracks/r/exercises/perfect-numbers/example.R
trackler-2.1.0.41 tracks/r/exercises/perfect-numbers/example.R
trackler-2.1.0.40 tracks/r/exercises/perfect-numbers/example.R
trackler-2.1.0.39 tracks/r/exercises/perfect-numbers/example.R
trackler-2.1.0.38 tracks/r/exercises/perfect-numbers/example.R
trackler-2.1.0.37 tracks/r/exercises/perfect-numbers/example.R
trackler-2.1.0.36 tracks/r/exercises/perfect-numbers/example.R
trackler-2.1.0.34 tracks/r/exercises/perfect-numbers/example.R
trackler-2.1.0.33 tracks/r/exercises/perfect-numbers/example.R
trackler-2.1.0.32 tracks/r/exercises/perfect-numbers/example.R
trackler-2.1.0.31 tracks/r/exercises/perfect-numbers/example.R
trackler-2.1.0.30 tracks/r/exercises/perfect-numbers/example.R
trackler-2.1.0.29 tracks/r/exercises/perfect-numbers/example.R
trackler-2.1.0.28 tracks/r/exercises/perfect-numbers/example.R