-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbook_binding2.R
executable file
·65 lines (37 loc) · 1.37 KB
/
book_binding2.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
x = c("one", "two", "tree", "four", "five", "six", "one", "tree", "four")
xf = as.factor(x)
xf2 = factor(x, levels = c("one", "two", "tree", "four", "five", "six"))
x = gsub("two", "other", x)
x = gsub("one", "other", x)
x
book.binding <- function(n, blank = "blank", bindings = 1) {
leftower.sheets = ceiling(n/4) - floor(ceiling(n/4)/bindings)*bindings
vector = rep(c(1,0), times = c(leftower.sheets, bindings - leftower.sheets))
print(vector)
for (k in 1:bindings) {
n1 = floor(ceiling(n/4)/bindings)*4*(k-1)+1
n2 = floor(ceiling(n/4)/bindings)*4*k
x = c(n1:n2, rep(blank, ifelse(n2%%4==0,0,4-n2%%4)))
# nn = ceiling(n2/4)*4
nn = n2/k
odd = x[c(TRUE, FALSE)]
even = x[c(FALSE, TRUE)]
even = even[(nn/2):1]
y = as.vector(t(data.frame(even, odd)))
y1 = y[1:(nn/2)]
y2 = y[(nn/2+1):nn]
cat(paste0("Binding ", k, ", Number of sheets = ", (n2-n1+1)/4, collapse = ""))
cat("\n")
cat(paste0(y1, collapse=", "))
cat("\n")
cat(paste0(y2, collapse=", "))
cat("\n")
}
}
book.binding(28*3, bindings = 3)
book.b <- function(n, bindings = 1) {
leftower.sheets = ceiling(n/4) - floor(ceiling(n/4)/bindings)*bindings
vector = rep(c(1,0), times = c(leftower.sheets, bindings - leftower.sheets))
print(vector)
}
book.b(100,3)