Created
June 24, 2014 16:19
-
-
Save kos59125/2f3417171a1230de4d6a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
open FsRandom | |
let search goal state = | |
// 入力から文字種を得る | |
let goalSize = String.length goal | |
let input = Seq.distinct goal |> Seq.toArray | |
let inputSize = Array.length input | |
use e = | |
Utility.chooseOne inputSize | |
|> Random.map (fun index -> input.[index]) | |
|> Seq.ofRandom <| state | |
|> fun s -> s.GetEnumerator () | |
let rec loop (buffer:System.Text.StringBuilder) = | |
if buffer.ToString () = goal then | |
() | |
else | |
e.MoveNext () |> ignore | |
let c = e.Current | |
printf "%c" c | |
if buffer.Length >= goalSize then | |
buffer.Remove (0, 1) |> ignore | |
loop (buffer.Append (c)) | |
loop (new System.Text.StringBuilder ()) | |
search "twitter" Utility.defaultState |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment