Skip to content

Instantly share code, notes, and snippets.

@Myoga1012
Last active January 30, 2023 09:08
Show Gist options
  • Save Myoga1012/21bb04c4731674956c3f to your computer and use it in GitHub Desktop.
Save Myoga1012/21bb04c4731674956c3f to your computer and use it in GitHub Desktop.
ひらがなをランダムに生成して、5・7・5の俳句を作成するプログラムですっ!
// Auther : Myoga Screw-bright
// Twitter : https://twitter.com/Myoga1012
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" )
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment