Sha256: 71f69a69c84c98d8fc5252eb5f2ce8e90aaf320d6c26241484ef6d33d6813672

Contents?: true

Size: 482 Bytes

Versions: 219

Compression:

Stored size: 482 Bytes

Contents

largest_series_product <- function(digits, span){

  nums <- as.numeric(unlist(strsplit(digits, "")))

  if (any(is.na(nums)) || span < 0 || span > length(nums)) {
    stop("Non-numeric characters or span less than digit length")
  }

  if (span == 0) {
    return(1)
  }

  indices <- 1:(length(nums) - span + 1)

  get_prod <- function(index, nums, span) {
    prod(nums[index:(index + span - 1)])
  }

  products <- sapply(indices, FUN = get_prod, nums, span)

  max(products)
}

Version data entries

219 entries across 219 versions & 1 rubygems

Version Path
trackler-2.2.1.159 tracks/r/exercises/largest-series-product/example.R
trackler-2.2.1.158 tracks/r/exercises/largest-series-product/example.R
trackler-2.2.1.157 tracks/r/exercises/largest-series-product/example.R
trackler-2.2.1.156 tracks/r/exercises/largest-series-product/example.R
trackler-2.2.1.155 tracks/r/exercises/largest-series-product/example.R
trackler-2.2.1.154 tracks/r/exercises/largest-series-product/example.R
trackler-2.2.1.153 tracks/r/exercises/largest-series-product/example.R
trackler-2.2.1.152 tracks/r/exercises/largest-series-product/example.R
trackler-2.2.1.151 tracks/r/exercises/largest-series-product/example.R
trackler-2.2.1.150 tracks/r/exercises/largest-series-product/example.R
trackler-2.2.1.149 tracks/r/exercises/largest-series-product/example.R
trackler-2.2.1.148 tracks/r/exercises/largest-series-product/example.R
trackler-2.2.1.147 tracks/r/exercises/largest-series-product/example.R
trackler-2.2.1.146 tracks/r/exercises/largest-series-product/example.R
trackler-2.2.1.145 tracks/r/exercises/largest-series-product/example.R
trackler-2.2.1.144 tracks/r/exercises/largest-series-product/example.R
trackler-2.2.1.143 tracks/r/exercises/largest-series-product/example.R
trackler-2.2.1.142 tracks/r/exercises/largest-series-product/example.R
trackler-2.2.1.141 tracks/r/exercises/largest-series-product/example.R
trackler-2.2.1.140 tracks/r/exercises/largest-series-product/example.R