Skip to content

Instantly share code, notes, and snippets.

@yuka1984
Last active March 12, 2016 17:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yuka1984/7cd941ca45165cc9edae to your computer and use it in GitHub Desktop.
Save yuka1984/7cd941ca45165cc9edae to your computer and use it in GitHub Desktop.
キヨシチェックをC#とReavtiveExtentionsで書いてみた。 ref: http://qiita.com/yu_ka1984/items/220dae1be549b9d25aee
using System;
using System.Linq;
using System.Reactive.Concurrency;
using System.Reactive.Linq;
namespace Zundoko
{
internal class Program
{
private const string Zun = "ズン";
private const string Doko = "ドコ";
private const string Kiyoshi = "キ・ヨ・シ! ((└(:3」┌)┘))";
private static void Main(string[] args)
{
var rm = new Random();
Observable
.Interval(TimeSpan.Zero, CurrentThreadScheduler.Instance)
.Select((x, y) => rm.Next()%2 == 0 ? Zun : Doko)
.Do(x => Console.Write($"{x} "))
.Buffer(5, 1)
.Where(x => x.SequenceEqual(new[] {Zun, Zun, Zun, Zun, Doko}))
.Subscribe(x =>
{
Console.WriteLine(Kiyoshi);
Console.Read();
Environment.Exit(0);
});
}
}
}
using System;
using System.Reactive.Disposables;
using System.Reactive.Linq;
using System.Threading;
using Reactive.Bindings.Extensions;
namespace Zundoko
{
internal class Program
{
private const string Zun = "ズン";
private const string Doko = "ドコ";
private const string Kiyoshi = "キ・ヨ・シ! ((└(:3」┌)┘))";
private static void Main(string[] args)
{
var ms = new ManualResetEventSlim();
var rm = new Random();
var disposable = new CompositeDisposable();
var zundokoRiver = Observable
.Interval(TimeSpan.Zero)
.Select((x, y) => rm.Next()%2 == 0 ? Zun : Doko)
.Publish()
;
zundokoRiver
.Do(x => Console.Write($"{x} "))
.Zip(
zundokoRiver.Skip(1)
, zundokoRiver.Skip(2)
, zundokoRiver.Skip(3)
, zundokoRiver.Skip(4)
, (one, two, three, four, five) => new {one, two, three, four, five})
.Where(x => x.one == Zun && x.two == Zun && x.three == Zun && x.four == Zun && x.five == Doko)
.Subscribe(x =>
{
Console.WriteLine(Kiyoshi);
disposable.Dispose();
ms.Set();
}).AddTo(disposable);
zundokoRiver.Connect();
ms.Reset();
ms.Wait();
Console.Read();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment