LoginSignup
14
12

More than 5 years have passed since last update.

ズンドコキヨシ with C

Last updated at Posted at 2016-03-12

C言語版がなかったので:

#include <stdlib.h>
#include <stdio.h>

int main()
{
  int nlz = 0, c = 0;
  do {
    nlz = c ? (nlz + 1) : 0;
    c = (rand() >> 3) & 1;  /* DIRTY HACK */
    printf("%s ", c ? "ズン" : "ドコ");
  } while (nlz < 4 || c);
  puts("キ・ヨ・シ!");
}

/* nlz == number of leading ZUN */

短くしたやつ

int n,c;main(){while(n<4||c){n=c?(n+1):0;puts((c=rand()&1)?"ズン":"ドコ");}puts("キ・ヨ・シ!");}

もう一歩(-5b)

int n,c;main(){for(;n<4||c;puts(c?"ズン":"ドコ"))n=c?n+1:0,c=rand()&1;puts("キ・ヨ・シ!");}

GCC 4.8.2とClang 3.3で実行可能(ただし各種警告は無視するものとする)。変数n,cは静的記憶域期間を持つため0初期化が保証される。rand()が返す下位1ビットで擬似乱数系列分布の質が悪いと、プログラムが終了しない可能性もある。

14
12
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
14
12