Last active
March 12, 2016 17:09
-
-
Save yuka1984/7cd941ca45165cc9edae to your computer and use it in GitHub Desktop.
キヨシチェックをC#とReavtiveExtentionsで書いてみた。 ref: http://qiita.com/yu_ka1984/items/220dae1be549b9d25aee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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