Help us understand the problem. What is going on with this article?

ズンドコキヨシ with F#

More than 3 years have passed since last update.

まだズンドコキヨシタグに投稿されていない言語を探したら 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
どこずんずんずんずんずんどこキ・ヨ・シ!
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away