高校数学の質問スレ(医者・東大卒専用) Part438 (991レス)
上下前次1-新
抽出解除 必死チェッカー(本家) (べ) 自ID レス栞 あぼーん
512: 01/08(水)04:11 ID:X/URcmTf(1/3) AAS
rm(list=ls())
JugRiddle <- function(
big=5,
small=3,
end=4){
# starting from the bigger jug
movebig <- function(xy){ # start from c(big,0)
x=xy[1] ; y=xy[2]
# x==big
if(x==big) re=c(big-(small-y),small)
# x==0
if(x==0) re=c(big,y)
# y==small
if(y==small) re=c(x,0)
# y==0
if(y==0 & x!=big){
if(x>=small) re=c(x-small,small)
else re=c(0,x)
}
return(re)
}
STATUS=status=c(big,0)
i=1
while(!identical(status,c(0,0))){#
i=i+1
status=movebig(status)
STATUS=rbind(STATUS,status)
}
rownames(STATUS)=1:nrow(STATUS)
colnames(STATUS)=c(paste0(big,'L'),paste0(small,'L'))
(Bigger=STATUS)
# starting from the smaller jug
movesmall <- function(xy){ # start from c(0,small)
x=xy[1] ; y=xy[2]
if(y==small){
if(x<=(big-small)) re=c(x+small,0)
else re=c(big, small-(big-x))
}
if(y==0) re=c(x,small)
if(x==big) re=c(0,y)
if(x==0) re=c(y,0)
return(re)
}
STATUS=status=c(0,small)
i=1
while(!identical(status,c(0,0))){ #
i=i+1
status=movesmall(status)
STATUS=rbind(STATUS,status)
}
rownames(STATUS)=1:nrow(STATUS)
colnames(STATUS)=c(paste0(big,'L'),paste0(small,'L'))
(Smaller=STATUS)
if(all(end != c(Bigger,Smaller))) return(NA)
min_Bigger=min(which(apply(Bigger,1,function(x) end %in% x)))
min_Smaller=min(which(apply(Smaller,1,function(x) end %in% x)))
list(Bigger=as.matrix(Bigger)[1:min_Bigger,],
Smaller=as.matrix(Smaller)[1:min_Smaller,],
min_Bigger=min_Bigger,min_Smaller=min_Smaller)
}
JugRiddle(5,3,4)
JugRiddle(10,5,3)
514(1): 01/08(水)19:29 ID:X/URcmTf(2/3) AAS
>>513
(2)回数の差の分布
画像リンク
515: 01/08(水)20:16 ID:X/URcmTf(3/3) AAS
>>514
画像リンク
上下前次1-新書関写板覧索設栞歴
スレ情報 赤レス抽出 画像レス抽出 歴の未読スレ
ぬこの手 ぬこTOP 1.997s*