Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
13
Task/Roman-numerals-Decode/R/roman-numerals-decode-1.r
Normal file
13
Task/Roman-numerals-Decode/R/roman-numerals-decode-1.r
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
romanToArabic <- function(roman) {
|
||||
romanLookup <- c(I=1L, V=5L, X=10L, L=50L, C=100L, D=500L, M=1000L)
|
||||
rSplit <- strsplit(toupper(roman), character(0)) # Split input vector into characters
|
||||
toArabic <- function(item) {
|
||||
digits <- romanLookup[item]
|
||||
if (length(digits) > 1L) {
|
||||
smaller <- (digits[-length(digits)] < digits[-1L])
|
||||
digits[smaller] <- - digits[smaller]
|
||||
}
|
||||
sum(digits)
|
||||
}
|
||||
vapply(rSplit, toArabic, integer(1))
|
||||
}
|
||||
1
Task/Roman-numerals-Decode/R/roman-numerals-decode-2.r
Normal file
1
Task/Roman-numerals-Decode/R/roman-numerals-decode-2.r
Normal file
|
|
@ -0,0 +1 @@
|
|||
romanToArabic(c("MCMXII", "LXXXVI"))
|
||||
1
Task/Roman-numerals-Decode/R/roman-numerals-decode-3.r
Normal file
1
Task/Roman-numerals-Decode/R/roman-numerals-decode-3.r
Normal file
|
|
@ -0,0 +1 @@
|
|||
as.integer(as.roman(c("MCMXII", "LXXXVI"))
|
||||
Loading…
Add table
Add a link
Reference in a new issue