"0"
.UTF8
as integers.a
through e
.add
and sub
, which add
to a register and assign it back to that register and or sub
tract a value from that register’s value and assign it back to that register.[[1]]
[1] "add" "b" "8"
[[2]]
[1] "sub" "e" "29"
[[3]]
[1] "add" "d" "1"
[[4]]
[1] "sub" "d" "16"
[[5]]
[1] "sub" "a" "21"
[[6]]
[1] "add" "b" "28"
[[7]]
[1] "add" "b" "5"
[[8]]
[1] "add" "d" "16"
[[9]]
[1] "add" "a" "10"
[[10]]
[1] "add" "c" "61"
[[11]]
[1] "add" "e" "14"
[[12]]
[1] "sub" "c" "15"
[[13]]
[1] "add" "a" "41"
[[14]]
[1] "add" "e" "15"
[[15]]
[1] "sub" "c" "12"
f
unction, r
egister, and y
aluesinstructions <-
readLines(ins_txt) |>
stringr::str_split(' ') |>
purrr::map(\(x) { names(x) <- c('f', 'r', 'y'); return(x); }) |>
print()
[[1]]
f r y
"add" "b" "8"
[[2]]
f r y
"sub" "e" "29"
[[3]]
f r y
"add" "d" "1"
[[4]]
f r y
"sub" "d" "16"
[[5]]
f r y
"sub" "a" "21"
[[6]]
f r y
"add" "b" "28"
[[7]]
f r y
"add" "b" "5"
[[8]]
f r y
"add" "d" "16"
[[9]]
f r y
"add" "a" "10"
[[10]]
f r y
"add" "c" "61"
[[11]]
f r y
"add" "e" "14"
[[12]]
f r y
"sub" "c" "15"
[[13]]
f r y
"add" "a" "41"
[[14]]
f r y
"add" "e" "15"
[[15]]
f r y
"sub" "c" "12"
R6
objectself
objectpublic
and private
methods (functions)R6
objectself
objectpublic
and private
methods (functions)"0"
.UTF8
as integers.a
through e
."0"
.UTF8
as integers.a
through e
."0"
.UTF8
as integers.a
through e
.add
and sub
, which add
to a register and assign it back to that register and or sub
tract a value from that register’s value and assign it back to that register.add
and sub
, which add
to a register and assign it back to that register and or sub
tract a value from that register’s value and assign it back to that register.R6::R6Class(
'classname' = 'nyr10',
'public' = list(
'index' = 1,
'call' = \(fun, reg, y) {
self[[fun]](reg, y)
private$.inc()
},
'run' = \(insructions) {
while(self$index <= length(insructions)) {
ins <- instructions[[self$index]]
self$call(ins['f'], ins['r'], as.integer(ins['y']))
}
return(self)
}
),
'private' = list(
'.inc' = \() { self$index <- self$index + 1; return(self); }
)
)
computer <- R6::R6Class(
'nyr10',
'public' = unlist(list(
as.list(c(registers, functions)),
'index' = 1,
'call' = \(fun, reg, y) {
self[[fun]](reg, y)
private$.inc()
},
'run' = \(insructions) {
while(self$index <= length(insructions)) {
ins <- instructions[[self$index]]
self$call(ins['f'], ins['r'], as.integer(ins['y']))
}
return(self)
}
)),
'private' = list(
'.inc' = \() { self$index <- self$index + 1; return(self); }
)
)