高校数学の質問スレ(医者・東大卒専用) Part438 (894レス)
1-

773: 03/31(月)11:35 ID:u+Kd/O/2(3/3) AAS
# 赤玉a個、黒玉b個、白玉c個、青玉d個の合計(a+b+c+d)個の玉を空箱なしで3つの箱に分けて入れる。箱を区別しないとき、入れ方は何通りあるか?"

solve=function(a,b,c,d){
divide = function(n) {
indices = expand.grid(i = 0:n, j = 0:n)
indices = indices[indices$j >= indices$i, ]
result = lapply(1:nrow(indices), function(k) {
x = indices[k, ]
matrix(c(x$i, x$j - x$i, n - x$j), nrow = 1)
})
return(result)
}

reds = divide(a)
blacks = divide(b)
whites = divide(c)
blues = divide(d)
box3 = list()

combinations = expand.grid(red = reds, black = blacks, white = whites, blue = blues)

box3 = apply(combinations, 1, function(x) {
red = x[[1]]
black = x[[2]]
white = x[[3]]
blue = x[[4]]

box = do.call(rbind, lapply(1:3, function(i) {
sum_values = red[i] + black[i] + white[i] + blue[i]
if (sum_values > 0) c('red'=red[i], 'black'=black[i], 'white'=white[i], 'blue'=blue[i]) else NULL
}))

if (!is.null(box) & nrow(box) == 3) {
sorted_box = box[order(apply(box, 1, paste, collapse = ",")), ]
return(sorted_box)
}
return(NULL)
})

length(unique(Filter(Negate(is.null), box3)))
}

f=function(a,b,c,d){
ball=c(a,b,c,d)
x=(a+2)*(b+2)*(c+2)*(d+2)
y=(a+1)*(b+1)*(c+1)*(d+1)
z=floor(a/2+1)*floor(b/2+1)*floor(c/2+1)*floor(d/2+1)
u=ifelse(all(ball%%2==0),1,0)
v=ifelse(all(ball%%3==0),1,0)
x*y/96-(3*y-3*z-3*u+4*v)/6-u*v
}

p=sample(10,4)

solve(p[1],p[2],p[3],p[4])
f(p[1],p[2],p[3],p[4])
1-
あと 121 レスあります
スレ情報 赤レス抽出 画像レス抽出 歴の未読スレ AAサムネイル

ぬこの手 ぬこTOP 0.007s