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.180 tracks/r/exercises/largest-series-product/example.R
trackler-2.2.1.179 tracks/r/exercises/largest-series-product/example.R
trackler-2.2.1.178 tracks/r/exercises/largest-series-product/example.R
trackler-2.2.1.177 tracks/r/exercises/largest-series-product/example.R
trackler-2.2.1.176 tracks/r/exercises/largest-series-product/example.R
trackler-2.2.1.175 tracks/r/exercises/largest-series-product/example.R
trackler-2.2.1.174 tracks/r/exercises/largest-series-product/example.R
trackler-2.2.1.173 tracks/r/exercises/largest-series-product/example.R
trackler-2.2.1.172 tracks/r/exercises/largest-series-product/example.R
trackler-2.2.1.171 tracks/r/exercises/largest-series-product/example.R
trackler-2.2.1.170 tracks/r/exercises/largest-series-product/example.R
trackler-2.2.1.169 tracks/r/exercises/largest-series-product/example.R
trackler-2.2.1.167 tracks/r/exercises/largest-series-product/example.R
trackler-2.2.1.166 tracks/r/exercises/largest-series-product/example.R
trackler-2.2.1.165 tracks/r/exercises/largest-series-product/example.R
trackler-2.2.1.164 tracks/r/exercises/largest-series-product/example.R
trackler-2.2.1.163 tracks/r/exercises/largest-series-product/example.R
trackler-2.2.1.162 tracks/r/exercises/largest-series-product/example.R
trackler-2.2.1.161 tracks/r/exercises/largest-series-product/example.R
trackler-2.2.1.160 tracks/r/exercises/largest-series-product/example.R