Advertisement
Syke

bingbong

Aug 17th, 2015
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
D 0.93 KB | None | 0 0
  1. module bingbong; private:
  2.  
  3. import std.range;
  4. import std.random;
  5. import std.stdio;
  6. import std.string;
  7. import std.conv;
  8. import std.uni;
  9.  
  10. enum formats = [
  11.     "*%s*",
  12.     "**%s**",
  13.     "***%s***",
  14.     "~~%s~~",
  15.     "__%s__",
  16.     "__*%s*__",
  17.     "__**%s**__",
  18.     "__***%s***__",
  19.     "`%s`",
  20.     null,
  21. ];
  22.  
  23. bool coinFlip()
  24. {
  25.     return uniform!"[]"( 1, 100 ) <= 50;
  26. }
  27.  
  28. ElementType!R sample( R )( R r ) if( isRandomAccessRange!R && hasLength!R )
  29. {
  30.     auto index = uniform( 0, r.length );
  31.     return r[index];
  32. }
  33.  
  34. void main()
  35. {
  36.     auto text = "?";
  37.     auto count = 100;
  38.  
  39.     string output;
  40.     auto i = 0u;
  41.     foreach( c; text.cycle )
  42.     {
  43.         if( i++ >= count * text.length )
  44.             break;
  45.  
  46.         auto fmt = formats.sample;
  47.         auto chr = coinFlip ? c.to!( string ).toUpper() : c.to!string;
  48.  
  49.         output ~= ( fmt is null ? chr : fmt.format( chr ) ) ~ ' ';
  50.     }
  51.  
  52.     output.writeln();
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement