Skip to content

Instantly share code, notes, and snippets.

@sinkuu
Last active August 29, 2015 14:06
Show Gist options
  • Save sinkuu/92d3c438383f65f7e369 to your computer and use it in GitHub Desktop.
Save sinkuu/92d3c438383f65f7e369 to your computer and use it in GitHub Desktop.
std.algorithm.cacheの使用例 http://qiita.com/giiko_/items/8c3442e8e7a83cc0b91a
import std.algorithm;
import std.random;
import std.range;
import std.stdio;
import std.string;
import std.typecons;
void main()
{
immutable dic = [["今日","ぞい"],["も"],["1","ぞい"],["日","ぞい"],["がん","ぞい"],["ばる","ぞい"],["ぞい!"]];
auto count = dic
.map!(w => w.randomSample(1).front).repeat.map!join
.cache
.tee!(writeln, No.pipeOnPop).until("今日も1日がんばるぞい!")
.walkLength + 1;
writefln("がんばるまで %s zoiでした", count);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment