高校数学の質問スレ(医者・東大卒専用) Part438 (750レス)
上
下
前
次
1-
新
512
: 01/08(水)04:11
ID:X/URcmTf(1/3)
AA×
[240|
320
|
480
|
600
|
100%
|
JPG
|
べ
|
レス栞
|
レス消
]
512: [sage] 2025/01/08(水) 04:11:37.72 ID:X/URcmTf 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) http://rio2016.5ch.net/test/read.cgi/math/1723152147/512
上
下
前
次
1-
新
書
関
写
板
覧
索
設
栞
歴
あと 238 レスあります
スレ情報
赤レス抽出
画像レス抽出
歴の未読スレ
AAサムネイル
ぬこの手
ぬこTOP
0.037s