トップ «前の日記(2013-10-10(Thu)) 最新 次の日記(2013-10-12(Sat))» 編集

屑俺日記

僕の備忘録(PC、UN*X、ネットワーク関連が中心)なんです。
自分の書いたところは適当(な時とか)に書き換えますので御了承を。


2013-10-11(Fri) 真夏の姿で雨を避けながら

サイコロ三つ

を振ると、パターンは6^3で216通り。
合計数のパターンを計算させてみた。
最小が3で、最大が18。

#include<stdio.h>
int atoi(char *foo);
 
int main(int argc, char *argv[])
{
  int one=1;
  int last=7;
  int count=0;
  int first, second, third;
  int total = atoi(argv[1]);
 
  for(first=one; first < last; first++)
  {
    for(second=one; second < last; second++)
    {
      for(third=one; third < last; third++)
      {
        if(first + second + third == total)
        {
           count++;
/*           printf("%d:%d:%d\n", first, second, third);*/
        }
      }
    }
 
  }
  printf("%2d: %2d\n", total, count);
 
return 0;
}
$ for num in `seq 3 18`; do ./3dice-2 $num; done
 3:  1
 4:  3
 5:  6
 6: 10
 7: 15
 8: 21
 9: 25
10: 27
11: 27
12: 25
13: 21
14: 15
15: 10
16:  6
17:  3
18:  1

リンクはご自由にどうぞ。でもURLや内容が変った場合はあしからず。

index.htmlは ここから。