LoginSignup
3
2

More than 5 years have passed since last update.

ズンドコキヨシ with F#

Last updated at Posted at 2016-03-17

まだズンドコキヨシタグに投稿されていない言語を探したら F# が残ってたので、全くやったことなかったけど書いてみました

実装

open System

let z, d = "ずん", "どこ"
let r = new Random()
let allEqual = Array.forall2 (fun (x: string) (y: string) -> x.Equals(y))
let terminator = [|z; z; z; z; d|]

let zd ()= [|z; d|].[r.Next(0, 2)]

let rec zundoko (prev : string array) : unit =
    let msg = zd()

    printf "%s" msg

    let current = Array.append prev [|msg|]

    match current with
    | [|_|]
    | [|_; _|]
    | [|_; _; _|]
    | [|_; _; _; _|] ->
        zundoko current
    | [|_; _; _; _; _|] ->
        if (Array.forall2 (fun a b -> a.Equals(b)) current terminator) then
            printfn "キ・ヨ・シ!"
        else
            zundoko current.[1..4]
    | _ -> ()

zundoko [||]

0

実行と結果

fsharpi hoge.fsx
どこずんずんずんずんずんどこキ・ヨ・シ!
3
2
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2