-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaoc2021_14_Part2_format4.R
47 lines (37 loc) · 1.24 KB
/
aoc2021_14_Part2_format4.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# aoc2021_14_1 <- read_csv("data/aoc2021_14_1_example.txt")
# KEY <- dplyr::pull(aoc2021_14_1,KEY)
# RESULT <- dplyr::pull(aoc2021_14_1, RESULT)
# for (i in 1:length(KEY)) {
# cat(str_replace_all(paste("condition(x == '", KEY[i], "', '", RESULT[i], "'),", "\n"), " ", ""))
# }
library(fmtr)
fmt1 <- value(
condition(x=='CH','CB'),
condition(x=='HH','HN'),
condition(x=='CB','CH'),
condition(x=='NH','NC'),
condition(x=='HB','HC'),
condition(x=='HC','HB'),
condition(x=='HN','HC'),
condition(x=='NN','NC'),
condition(x=='BH','BH'),
condition(x=='NC','NB'),
condition(x=='NB','NB'),
condition(x=='BN','BB'),
condition(x=='BB','BN'),
condition(x=='BC','BB'),
condition(x=='CC','CN'),
condition(x=='CN','CC'))
orig_string <- "NNCB"
last_char <- str_sub(orig_string, -1)
recent_string <- orig_string
for (j in 1:20) {
#new_list <- vector("list", length(orig_list))
recent_list <- substring(recent_string, first = 1:(nchar(recent_string) - 1), last = 2:nchar(recent_string))
new_list <- fapply(recent_list, fmt1)
new_list[[length(new_list)+1]] <- last_char
recent_string <- paste(new_list, collapse = "")
rm(new_list)
cat("End of loop j= ", j, " Count: ", count_chars(recent_string), "\n")
}
count_chars(recent_string)