Last active
August 29, 2015 14:11
-
-
Save adacola/ce886c0abb08e571b337 to your computer and use it in GitHub Desktop.
今日も1日がんばるぞい! http://qiita.com/giiko_/items/8c3442e8e7a83cc0b91a のネタをF#で
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
type Word = TrueZoi of string | FalseZoi | TrueOtherwise of string | |
let isTrue = function TrueZoi _ | TrueOtherwise _ -> true | FalseZoi -> false | |
let toString = function TrueZoi x | TrueOtherwise x -> x | FalseZoi -> "ぞい" | |
let countZoi = function TrueZoi _ | FalseZoi -> 1 | TrueOtherwise _ -> 0 | |
let dic = | |
[ | |
[|TrueOtherwise "今日"; FalseZoi|] | |
[|TrueOtherwise "も"|] | |
[|TrueOtherwise "1"; FalseZoi|] | |
[|TrueOtherwise "日"; FalseZoi|] | |
[|TrueOtherwise "がん"; FalseZoi|] | |
[|TrueOtherwise "ばる"; FalseZoi|] | |
[|TrueZoi "ぞい!"|] | |
] | |
let random = System.Random() | |
let allPhrase = | |
false |> Seq.unfold (function | |
| true -> None | |
| false -> | |
let phrase = dic |> List.map (fun p -> random.Next(p.Length) |> Array.get p) | |
let phraseString = phrase |> Seq.map toString |> String.concat "" | |
Some((phrase, phraseString), phrase |> List.forall isTrue)) | |
|> Seq.toList | |
let main() = | |
allPhrase |> List.iter (snd >> printfn "%s") | |
allPhrase |> List.length |> printfn "がんばるまで %d 回でした" | |
allPhrase |> List.sumBy (fst >> List.sumBy countZoi) |> printfn "%d zoi" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
実行結果の例