LoginSignup
3
4

More than 5 years have passed since last update.

ズンドコキヨシ with D 供養

Posted at

三番煎じです

ズンドコキヨシ with D by @kotet
ズンドコキヨシ with D by @cedretaber

コードゴルフ(目標:Twitterでpaiza_run可能)の残骸

※下記のコードは、見やすいように改行とインデントをつけてます。

D言語にパターンマッチがほしいよ編

見やすくて気に入ったけど
非推奨のmatchまで使うも縮まらず

D
import std.stdio,std.random,std.regex;
void main(){
  string s;
  while(!match(s,"(.ン){4}ド.$"))
    s~=dice(1,1)?"ドコ":"ズン";
  writeln(s,"キ・ヨ・シ!");
}

あと4文字が縮まらないよ編

必要最小限の標準ライブラリでやってみた
Twitterには貼れるけど、paiza_runまでは縮められず

D
//#paiza_run d:  ←コレガハイラナイ
import std.stdio,std.random;
void main(){
  dstring s;
  while(s[$>9?$-10:$..$]!="ズンズンズンズンドコ")
    s~=dice(1,1)?"ドコ":"ズン";
  writeln(s,"キ・ヨ・シ!");
}

番外編(UFCSしたいマン)

untilを見つけるまで、無限レンジを適当な所で切っていたよ
なかなかきれいに書けたけど文字数

D
import std.stdio,std.random,std.range,std.algorithm;
void main(){
  auto s=[0,0,0,0,1];
  writeln(
    generate!(()=>dice(1,1))
      .until(s)
      .chain(s)
      .map!`a?"ドコ":"ズン"`
      .join,
    "キ・ヨ・シ!"
  );
}

まとめ

こーどごるふを めざしたけど むしろ わんらいなーに ちかづいたよ
ふぉぼすが ぜんぶはいる import std みたいなのほしいよ(小並感)

3
4
8

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
3
4