Created
June 23, 2018 14:39
-
-
Save takaya1992/0415fe58fc79686f70b7913cee5c4006 to your computer and use it in GitHub Desktop.
「チ・キ・ン・南・蛮」をランダムに表示し「チキン南蛮」が完成した終了するプログラム
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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