Skip to content

Instantly share code, notes, and snippets.

@adacola
Last active August 29, 2015 14:11
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 adacola/ce886c0abb08e571b337 to your computer and use it in GitHub Desktop.
Save adacola/ce886c0abb08e571b337 to your computer and use it in GitHub Desktop.
今日も1日がんばるぞい! http://qiita.com/giiko_/items/8c3442e8e7a83cc0b91a のネタをF#で
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"
@adacola
Copy link
Author

adacola commented Dec 17, 2014

実行結果の例

> main();;
ぞいも1日がんぞいぞい!
今日もぞいぞいぞいばるぞい!
ぞいもぞい日がんばるぞい!
ぞいもぞい日がんばるぞい!
ぞいもぞい日がんぞいぞい!
今日も1日がんぞいぞい!
今日も1日がんばるぞい!
がんばるまで 7 回でした
20 zoi
val it : unit = ()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment