業界トップクラスの求人数を誇る転職エージェントPR

リクルートグループのコネクションを活かした非公開求人も充実、他にはない好条件の求人と出会える

13
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

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ビットで擬似乱数系列分布の質が悪いと、プログラムが終了しない可能性もある。

13
11
1

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

Qiita Conference 2025 will be held!: 4/23(wed) - 4/25(Fri)

Qiita Conference is the largest tech conference in Qiita!

Keynote Speaker

ymrl、Masanobu Naruse, Takeshi Kano, Junichi Ito, uhyo, Hiroshi Tokumaru, MinoDriven, Minorun, Hiroyuki Sakuraba, tenntenn, drken, konifar

View event details
13
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?