10
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ズンドコキヨシ with jq

Last updated at Posted at 2016-03-17

概要

jqコマンドでズンドコキヨシです。

参考: http://qiita.com/y__sama/items/7c451dfd706f9b36729d

コード

zndk.jq
def zndkkyc:
  ["ズン", "ドコ"] as $zndk |
  def _zndkkyc(seed):
    def nextseed(x): (x * 9301 + 49297) % 233280;
    def rand(seed): seed / (233280 + 1);
    def sample(seed):
      . as $in | . | nth(rand(seed) * 10 | floor % ($in | length));

    if .[-5:] != ["ズン", "ズン", "ズン", "ズン", "ドコ"] then
      nextseed(seed) as $seed | . + ([$zndk | sample($seed)]) | _zndkkyc($seed)
    else
      . + ["キ・ヨ・シ!"]
    end;

  [] | _zndkkyc(100);
zndkkyc | join("")

randが無いので線形合同法でやりました。

実行と結果

$ jq -r -n -f zndk.jq
ドコドコズンズンズンドコズンズンズンドコドコズンズンドコドコドコズンズンドコドコドコズンドコドコズンドコズンドコドコズンドコズンズンズンズンドコキ・ヨ・シ!
10
10
0

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
10
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?