底辺私立医大を卒業した医者って頭悪いよね? Part17at HOSP底辺私立医大を卒業した医者って頭悪いよね? Part17 - 暇つぶし2ch■コピペモード□スレを通常表示□オプションモード□このスレッドのURL■項目テキスト50:卵の名無しさん 20/06/26 16:07:15.07 vSOmQn7C.net pa=1/3 ; qa=1-pa # probability of dead ; alive pb=1/2 ; qb=1-pb pc=1 ; qc=1-pc # simulation of 3 alive to 2 alive # each shoots at the superior sniper # Hence,A shoots C -> B shoots C -> C shoots B f3 <- function(){ a=b=c=1 bshoot=FALSE # is next shooter B? while(a+b+c==3){ c=rbinom(1,1,qa) # A shoots C if(c==0) bshoot=TRUE # if A kills C, next shooter is B c=rbinom(1,1,qb) # B shoots C if(c==1) b=rbinom(1,1,qc) # if C alive, C shoots B } return(list(abc=c(a,b,c),bshoot=bshoot)) } 51:卵の名無しさん 20/06/26 16:07:45.68 vSOmQn7C.net # simulation of 2 alive to 1 alive # Notice who has the right to shoot f2 <- function(){ re3=f3() # simulation to 2 suvivors a=re3$abc[1] # 1 1 b=re3$abc[2] # 1 0 c=re3$abc[3] # 0 1 while(a+b+c==2){ # while 2 alive if(c==0){ # when C dead if(re3$bshoot){ # when A killed C, B can shoot A a=rbinom(1,1,qb) if(a==0) return(c(a,b,c)) } else{ # when B killed C b=rbinom(1,1,qa) # A can shoot B if(b==0) return(c(a,b,c)) } } else{ # when C alive (C killed B, C shot at superior B) c=rbinom(1,1,qa) # A can shoot C if(c==0) return(c(a,b,c)) # if A killed C a=rbinom(1,1,qc) # when A missed C,C can shoot A if(a==0) return(c(a,b,c)) # C can always kill A } } } k=1e5 re2=replicate(k,f2()) apply(re2,1,mean) # c(1/2,1/6,1/3) 次ページ最新レス表示レスジャンプ類似スレ一覧スレッドの検索話題のニュースおまかせリストオプションしおりを挟むスレッドに書込スレッドの一覧暇つぶし2ch