Skip to content

Instantly share code, notes, and snippets.

@Nia-TN1012
Forked from Myoga1012/Haiku.fs
Last active January 30, 2023 09:09
Show Gist options
  • Save Nia-TN1012/13e3e7117b95f46d181906b1281aab97 to your computer and use it in GitHub Desktop.
Save Nia-TN1012/13e3e7117b95f46d181906b1281aab97 to your computer and use it in GitHub Desktop.
ひらがなをランダムに生成して、5・7・5の俳句を作成するプログラムです。
// Auther : Nia Tomonaka
// Twitter : https://twitter.com/nia_tn1012
open System // RandomクラスとString.Joinメソッドで必要です。
let rnd = Random()
// 0x3041(ぁ)~0x3093(ん)までのUnicodeのひらがなの句をランダムに生成します。
let phrase n = [for i in 1..n -> char( rnd.Next( 0x3041, 0x3094 ) )]
// 5・7・5の俳句を作成して出力します。
[phrase(5); phrase(7); phrase(5)] |> Seq.iter( fun phr -> String.Join( "", phr ) |> printfn "%s" )
// Haiku.fs
// Copyright (c) 2014-2023 Nia T.N. Tech Lab. / Chronoir.net.
// This software is released under the MIT License.
// http://opensource.org/licenses/mit-license.php
open System;( [5; 7; 5], Random() ) |> fun a -> a |> fst |> Seq.map( fun n -> [for i in 1..n -> char( snd(a).Next( 0x3041, 0x3094 ) )] ) |> Seq.iter( fun c -> String.Join( "", c ) |> printfn "%s" )
open System
let r=Random()
let p n=[for i in 1..n->char(r.Next(0x3041,0x3094))]
[p(5);p(7);p(5)]|>Seq.iter(fun c->String.Join("",c)|>printfn"%s")
// 148 bytes
@Nia-TN1012
Copy link
Author

GitHubのアカウント統合のため、Myoga1012→Nia-TN1012に移行しました。

旧URL: https://gist.github.com/Myoga1012/21bb04c4731674956c3f

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