Skip to content

Instantly share code, notes, and snippets.

@takaya1992
Created June 23, 2018 14:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save takaya1992/0415fe58fc79686f70b7913cee5c4006 to your computer and use it in GitHub Desktop.
Save takaya1992/0415fe58fc79686f70b7913cee5c4006 to your computer and use it in GitHub Desktop.
「チ・キ・ン・南・蛮」をランダムに表示し「チキン南蛮」が完成した終了するプログラム
use strict;
use warnings;
use utf8;
use Encode qw/encode_utf8/;
use constant CHICKEN_NANBAN => 'チキン南蛮';
my @chars;
my @splited_chars = split //, CHICKEN_NANBAN;
my $length = scalar(@splited_chars);
my $count = 0;
while (join('', @chars) ne CHICKEN_NANBAN) {
my $char = $splited_chars[int(rand($length))];
p($char);
push(@chars, $char);
shift(@chars) if (scalar(@chars) > $length);
$count++;
}
pp('');
pp("----------------");
pp("$count 文字で「" . CHICKEN_NANBAN . "」が完成しました");
sub p { print encode_utf8(shift); }
sub pp { p(shift . "\n"); }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment