勉強日記

チラ裏

ガルパンコラボカフェのランダムコースター(12種)を25枚ツモってもコンプできなかった話


背景

sega-collabocafe.com

  • ガルパン最終章第2話が上映される
  • セガコラボカフェでガルパンコラボが行われる
  • ドリンク(600円)を飲むとコースター(12種類)がランダムで1枚もらえる
  • コンプしたくもなるよなぁ?
    • なるべく自力で

経済回した結果

f:id:wand_ta:20190714023816j:plain

いや5枚被りはおかしいだろ
ケイさん好きだけどさ

f:id:wand_ta:20190714024738j:plain

下の塊がランダムでもらえるコースター
秋山殿以外被ってるっておかしくないか

25枚ツモって10/12種類って屑運なのでは

  • 12の2倍以上ツモってるんだぜ?コンプできてても不思議ではないのでは
  • 確率分布が知りたくなる
  • 数式で簡単に算出できそうに見えて、そうでもなかったので動的計画法で解いた

f:id:wand_ta:20190714024922j:plain

数年ぶりにC++書いてみる

#include <boost/multiprecision/cpp_int.hpp>
#include <iostream>
#include <iomanip>
#include <array>

namespace mp = boost::multiprecision;

constexpr int NUM_COASTER_TYPES = 12;

// コースターの種類は[0, NUM_COASTER_TYPES + 1)
// さらなる+1は番兵
using histogram_t = std::array<mp::cpp_int, NUM_COASTER_TYPES + 2>;


void show_probability(int trial, const histogram_t& histogram) {
  // 確率の分母
  mp::cpp_int denominator = mp::pow((mp::cpp_int)NUM_COASTER_TYPES, trial);
  
  std::cout << "----------------------------------------" << std::endl
            << trial << "th trial" << std::endl
            << "----------------------------------------"  << std::endl;

  // 見出し
  for(int i = 0; i <= NUM_COASTER_TYPES; ++i) {
    std::cout << std::setw(4) << i << "    ";
  }
  std::cout << std::endl;

  // 確率
  for(auto column: histogram) {
    // XXX.X%という感じに表示する
    double probability = (double)(column * 10000 / denominator) / 100;
    std::cout << std::fixed
              << std::setw(5)
              << std::setprecision(1)
              << probability
              << "%, ";
  }
  std::cout << std::endl << std::endl;
}


int main() {
  int coaster_num;
  std::cin >> coaster_num;

  // 初期条件
  // 0枚数ツモ時点で0種1通り
  histogram_t histogram{};
  histogram.fill(0);
  histogram[0] = 1;

  // 計算結果一時格納
  histogram_t work{};

  for (int trial = 1; trial <= coaster_num;  ++trial) {
    work.fill(0);

    // 動的計画法
    for (int type_num = 0; type_num <= NUM_COASTER_TYPES; ++type_num) {
      const auto column = histogram[type_num];
      work[type_num] += column * type_num;
      work[type_num + 1] += column * (NUM_COASTER_TYPES - type_num);
    }

    std::swap(histogram, work);

    show_probability(trial, histogram);
  }

  return 0;
}

wandbox

出力結果

全出力(クリックで展開)

----------------------------------------
1th trial
----------------------------------------
   0       1       2       3       4       5       6       7       8       9      10      11      12    
  0.0%, 100.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%, 

----------------------------------------
2th trial
----------------------------------------
   0       1       2       3       4       5       6       7       8       9      10      11      12    
  0.0%,   8.3%,  91.7%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%, 

----------------------------------------
3th trial
----------------------------------------
   0       1       2       3       4       5       6       7       8       9      10      11      12    
  0.0%,   0.7%,  22.9%,  76.4%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%, 

----------------------------------------
4th trial
----------------------------------------
   0       1       2       3       4       5       6       7       8       9      10      11      12    
  0.0%,   0.1%,   4.5%,  38.2%,  57.3%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%, 

----------------------------------------
5th trial
----------------------------------------
   0       1       2       3       4       5       6       7       8       9      10      11      12    
  0.0%,   0.0%,   0.8%,  13.3%,  47.7%,  38.2%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%, 

----------------------------------------
6th trial
----------------------------------------
   0       1       2       3       4       5       6       7       8       9      10      11      12    
  0.0%,   0.0%,   0.1%,   4.0%,  25.9%,  47.7%,  22.3%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%, 

----------------------------------------
7th trial
----------------------------------------
   0       1       2       3       4       5       6       7       8       9      10      11      12    
  0.0%,   0.0%,   0.0%,   1.1%,  11.6%,  37.1%,  39.0%,  11.1%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%, 

----------------------------------------
8th trial
----------------------------------------
   0       1       2       3       4       5       6       7       8       9      10      11      12    
  0.0%,   0.0%,   0.0%,   0.3%,   4.7%,  23.2%,  41.1%,  26.0%,   4.6%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%, 

----------------------------------------
9th trial
----------------------------------------
   0       1       2       3       4       5       6       7       8       9      10      11      12    
  0.0%,   0.0%,   0.0%,   0.1%,   1.8%,  12.8%,  34.1%,  35.7%,  13.9%,   1.5%,   0.0%,   0.0%,   0.0%,   0.0%, 

----------------------------------------
10th trial
----------------------------------------
   0       1       2       3       4       5       6       7       8       9      10      11      12    
  0.0%,   0.0%,   0.0%,   0.0%,   0.7%,   6.5%,  24.5%,  37.9%,  24.2%,   5.8%,   0.4%,   0.0%,   0.0%,   0.0%, 

----------------------------------------
11th trial
----------------------------------------
   0       1       2       3       4       5       6       7       8       9      10      11      12    
  0.0%,   0.0%,   0.0%,   0.0%,   0.2%,   3.1%,  16.1%,  34.4%,  31.9%,  12.4%,   1.8%,   0.1%,   0.0%,   0.0%, 

----------------------------------------
12th trial
----------------------------------------
   0       1       2       3       4       5       6       7       8       9      10      11      12    
  0.0%,   0.0%,   0.0%,   0.0%,   0.1%,   1.5%,   9.9%,  28.1%,  35.6%,  19.9%,   4.6%,   0.3%,   0.0%,   0.0%, 

----------------------------------------
13th trial
----------------------------------------
   0       1       2       3       4       5       6       7       8       9      10      11      12    
  0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.7%,   5.8%,  21.3%,  35.4%,  26.8%,   8.8%,   1.1%,   0.0%,   0.0%, 

----------------------------------------
14th trial
----------------------------------------
   0       1       2       3       4       5       6       7       8       9      10      11      12    
  0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.3%,   3.3%,  15.3%,  32.5%,  31.9%,  14.0%,   2.5%,   0.1%,   0.0%, 

----------------------------------------
15th trial
----------------------------------------
   0       1       2       3       4       5       6       7       8       9      10      11      12    
  0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.1%,   1.8%,  10.6%,  28.1%,  34.8%,  19.7%,   4.6%,   0.3%,   0.0%, 

----------------------------------------
16th trial
----------------------------------------
   0       1       2       3       4       5       6       7       8       9      10      11      12    
  0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.1%,   1.0%,   7.1%,  23.1%,  35.4%,  25.1%,   7.5%,   0.7%,   0.0%, 

----------------------------------------
17th trial
----------------------------------------
   0       1       2       3       4       5       6       7       8       9      10      11      12    
  0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.5%,   4.6%,  18.4%,  34.3%,  29.8%,  11.1%,   1.3%,   0.0%, 

----------------------------------------
18th trial
----------------------------------------
   0       1       2       3       4       5       6       7       8       9      10      11      12    
  0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.3%,   3.0%,  14.2%,  31.8%,  33.4%,  15.1%,   2.3%,   0.0%, 

----------------------------------------
19th trial
----------------------------------------
   0       1       2       3       4       5       6       7       8       9      10      11      12    
  0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.1%,   1.9%,  10.7%,  28.6%,  35.8%,  19.4%,   3.5%,   0.0%, 

----------------------------------------
20th trial
----------------------------------------
   0       1       2       3       4       5       6       7       8       9      10      11      12    
  0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.1%,   1.2%,   7.9%,  25.0%,  37.0%,  23.7%,   5.1%,   0.0%, 

----------------------------------------
21th trial
----------------------------------------
   0       1       2       3       4       5       6       7       8       9      10      11      12    
  0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.7%,   5.7%,  21.4%,  37.0%,  27.9%,   7.1%,   0.0%, 

----------------------------------------
22th trial
----------------------------------------
   0       1       2       3       4       5       6       7       8       9      10      11      12    
  0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.4%,   4.1%,  18.0%,  36.2%,  31.8%,   9.4%,   0.0%, 

----------------------------------------
23th trial
----------------------------------------
   0       1       2       3       4       5       6       7       8       9      10      11      12    
  0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.3%,   2.9%,  14.8%,  34.7%,  35.2%,  12.1%,   0.0%, 

----------------------------------------
24th trial
----------------------------------------
   0       1       2       3       4       5       6       7       8       9      10      11      12    
  0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.1%,   2.1%,  12.1%,  32.6%,  38.0%,  15.0%,   0.0%, 

----------------------------------------
25th trial
----------------------------------------
   0       1       2       3       4       5       6       7       8       9      10      11      12    
  0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.1%,   1.4%,   9.8%,  30.2%,  40.3%,  18.2%,   0.0%, 

----------------------------------------
26th trial
----------------------------------------
   0       1       2       3       4       5       6       7       8       9      10      11      12    
  0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.1%,   1.0%,   7.8%,  27.6%,  42.0%,  21.5%,   0.0%, 

----------------------------------------
27th trial
----------------------------------------
   0       1       2       3       4       5       6       7       8       9      10      11      12    
  0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.7%,   6.2%,  25.0%,  43.1%,  25.0%,   0.0%, 

----------------------------------------
28th trial
----------------------------------------
   0       1       2       3       4       5       6       7       8       9      10      11      12    
  0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.5%,   4.9%,  22.4%,  43.6%,  28.6%,   0.0%, 

----------------------------------------
29th trial
----------------------------------------
   0       1       2       3       4       5       6       7       8       9      10      11      12    
  0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.3%,   3.8%,  19.8%,  43.7%,  32.3%,   0.0%, 

----------------------------------------
30th trial
----------------------------------------
   0       1       2       3       4       5       6       7       8       9      10      11      12    
  0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.2%,   3.0%,  17.5%,  43.4%,  35.9%,   0.0%, 

----------------------------------------
31th trial
----------------------------------------
   0       1       2       3       4       5       6       7       8       9      10      11      12    
  0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.1%,   2.3%,  15.3%,  42.7%,  39.5%,   0.0%, 

----------------------------------------
32th trial
----------------------------------------
   0       1       2       3       4       5       6       7       8       9      10      11      12    
  0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.1%,   1.8%,  13.3%,  41.7%,  43.1%,   0.0%, 

----------------------------------------
33th trial
----------------------------------------
   0       1       2       3       4       5       6       7       8       9      10      11      12    
  0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.1%,   1.4%,  11.6%,  40.4%,  46.6%,   0.0%, 

----------------------------------------
34th trial
----------------------------------------
   0       1       2       3       4       5       6       7       8       9      10      11      12    
  0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   1.0%,  10.0%,  39.0%,  49.9%,   0.0%, 

----------------------------------------
35th trial
----------------------------------------
   0       1       2       3       4       5       6       7       8       9      10      11      12    
  0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.8%,   8.6%,  37.4%,  53.2%,   0.0%, 

----------------------------------------
36th trial
----------------------------------------
   0       1       2       3       4       5       6       7       8       9      10      11      12    
  0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.6%,   7.3%,  35.7%,  56.3%,   0.0%, 

考察

25枚ツモったときの確率分布

----------------------------------------
25th trial
----------------------------------------
   0       1       2       3       4       5       6       7       8       9      10      11      12    
  0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.1%,   1.4%,   9.8%,  30.2%,  40.3%,  18.2%,   0.0%, 
  • 10種類以下しか揃わない確率は約42%
  • 11種類ちょうど揃う確率は約40%
  • 12種類コンプできる確率は約18%
  • うーん、妥当!w
    • 強いて言えば11種類揃ってないのが若干運悪いですね

Q. コンプ率5割超えるためには何枚ツモらないといけないの

----------------------------------------
34th trial
----------------------------------------
   0       1       2       3       4       5       6       7       8       9      10      11      12    
  0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   1.0%,  10.0%,  39.0%,  49.9%,   0.0%, 

----------------------------------------
35th trial
----------------------------------------
   0       1       2       3       4       5       6       7       8       9      10      11      12    
  0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.8%,   8.6%,  37.4%,  53.2%,   0.0%, 

----------------------------------------
36th trial
----------------------------------------
   0       1       2       3       4       5       6       7       8       9      10      11      12    
  0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.0%,   0.6%,   7.3%,  35.7%,  56.3%,   0.0%, 

A. 35枚

  • あと10杯飲んでもコンプできるか五分五分
    • これも戦車道…