letitburn <- function(x, input) {
x <- strsplit(x, "\n")[[1]]
x <- strsplit(x, "")
floor <- matrix
(unlist
(x
), nrow
= length
(x
), ncol
= length
(x
[[1]]), byrow
= T
) input <- read.table(textConnection(input))
for(i in 1:nrow(input)) {
s <- as.integer(input[i,]) + 1
if(!all
(rev
(s
) <= dim
(floor))) next
poss
<- floor[s
[2], s
[1]] if(poss %in% c("F", "#", "|", "/", "=", "_"))
next
if(poss == "S")
else
}
smoke
<- which
(floor == "S") for(i in 1:length(smoke)) {
top
<- floor[smoke
[i
] - 1] bot
<- floor[smoke
[i
] + 1] all <- c(top, bot, lef, rig)
if("F" %in% all){
next
}
pass <- which(all == "/" | all == "=" | all == "_")
if(length(which) == 0) next
for(j in seq_along(pass)) {
check
<- ifelse
(pass
[j
] <= 2, 2, nrow
(floor)*2) if(pass[j] %% 2 == 0)
check
<- floor[smoke
[i
] + check
] else
check
<- floor[smoke
[i
] - check
] if("F" == check
) floor[smoke
[i
]] <- "F" }
}
}
shouse <- "#############/#\n# | #\n# # #\n# # #\n####### #\n# _ #\n###############"
shinput <- "1 1\n1 2\n1 3\n5 6\n4 2\n1 1\n1 2\n5 5\n5 5\n9 1\n5 7\n2 2"
output <- letitburn(shouse, shinput)
apply(output, 1, cat, "\n")
bGV0aXRidXJuIDwtIGZ1bmN0aW9uKHgsIGlucHV0KSB7CiAgeCA8LSBzdHJzcGxpdCh4LCAiXG4iKVtbMV1dCiAgeCA8LSBzdHJzcGxpdCh4LCAiIikKICBmbG9vciA8LSBtYXRyaXgodW5saXN0KHgpLCBucm93ID0gbGVuZ3RoKHgpLCBuY29sID0gbGVuZ3RoKHhbWzFdXSksIGJ5cm93ID0gVCkKICBpbnB1dCA8LSByZWFkLnRhYmxlKHRleHRDb25uZWN0aW9uKGlucHV0KSkKICBmb3IoaSBpbiAxOm5yb3coaW5wdXQpKSB7CiAgICBzIDwtIGFzLmludGVnZXIoaW5wdXRbaSxdKSArIDEKICAgIGlmKCFhbGwocmV2KHMpID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