2013/01/14

博杯密技:二分搜索/Coin Flipping Technique: Binary Search

博杯密技:二分搜索/Coin Flipping Technique: Binary Search

剛剛在新聞挖挖哇裡聽到于美人說她用博杯請圓環關公挑年菜:八道湯,一道道博。零北的軟體工程師聽到槌心肝:不用博八道菜啊!可以用二分搜索 (Binary Search) 啊!比如說,要從 A B C D E F G H 選出一鍋。

When there is no logical choice, I always resort to coin flipping. With Binary Search, I can always flip my way out within very few flips. For example, to flip a choice out of eight candidates. For example, to flip out a choice from A B C D E F G and H.
  1. Divide the candidates into two groups:
    Group Head (A, B, C, D)
    Group Tail (E, F, G, H).
  2. Flip the coin. If head, keep Group Head, and vice versa. For the purpose of demonstration, let's say we get head.
  3. Divide the remaining group gain:
    Group Head (A, B)
    Group Tail (C, D)
  4. Flip the coin again. Let's say we get tail this time.
  5. Now we have only C and D left. One last flip would get us the final answer
In above example, we get to pick one choice out of eight candidate by flipping a coin only three times.

  1. 將所有選項分兩組:
    甲組:(A, B, C, D)
    乙組:(E, F, G, H)
  2. 博杯請教關老爺:是不是甲組?如果是,就剔除乙組;否則就剔除甲組。在這個示範裡,假設關老爺選了甲組。
  3. 再將剩下的選項再分組:
    甲組:(A, B)
    乙組:(C, D)
  4. 再博杯請教關老爺是不是甲組?假設這次關老爺不給聖筊,我們就留下乙組。
  5. 再博杯,問是不是C?如果不是,關老爺挑的就是 D 了。
這樣博杯,只要博三杯,就可以從八道年菜裡,問出關老爺的旨意了。

同理,如果要從名單中挑人,比方說:選爐主,也可以這般請教。省事多了。

江蕙-博杯:

詞:武雄 曲:陳子鴻

窗外清風一直吹 心事欲講抹詳細 
有時悶悶想歸瞑 等無月光入來坐
雙親頭鬃漸漸白 情愛誰人會賜配 
無講出的彼句話 只有博杯問天地

問世間冷暖怎輪迴 事業前途應該走去叨 
希望一切就會凍順適 大大小小平安快樂過
問緣份到底欠外多 為何真意真心 無地找 
雖然就慣習孤單一個 並無放棄 有情人來陪

惦惦無聲 頭犁犁 看著紛亂的土地 
誠心最後博一杯 望天替咱保庇這個家

延伸閱讀:

Flag Counter



No comments:

Post a Comment

Related Posts with Thumbnails

Popular Posts (All Time)/滿堂紅

Popular Posts (7 Days)/七日紅