Skip to content

Instantly share code, notes, and snippets.

@satetsu888
Last active December 19, 2015 12:29
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 satetsu888/5955519 to your computer and use it in GitHub Desktop.
Save satetsu888/5955519 to your computer and use it in GitHub Desktop.
ボーリング嫌い
#!/usr/bin/perl
use strict;
use warnings;
my $input = $ARGV[0];
# temporary
# TODO 切り取る
print calc_game_score($input);
print tokenize_input($input);
sub calc_frame_score {
my ($input_frame, $frame_num) = @_;
my $currentframe = $input_frame->{$frame_num);
# 数字だけの時!!
if ($currentframe =~ qr/([0-9])/){
my @numbers = split //, $currentframe;
return $numbers[0] + $numbers[1];
}
# ストライクの時!!!
elsif($currentframe eq "X"){
return 10 + calc_frame_score($input_frame, $frame_num+1) + calc_frame_score($input_frame, $frame_num+2);
}
# スペアの時!!!!
elsif($currentframe =~ qr|/|){
}
}
sub calc_game_score {
my $input = shift;
my $frame_array = tokenize_input($input);
my $sum = 0;
for my $frame_num(1..12){
$sum += calc_frame_score($frame_array, $frame_num);
}
}
sub tokenize_input {
my $input = shift;
my @frame_array =();
my @characters = split //, $input;
my $frame;
for (@characters) {
if ($_ =~ qr|[0-9/]|) {
if ($frame) {
$frame .= $_;
push @frame_array, $frame;
$frame = undef;
}
$frame = $_;
}
elsif ($_ =~ /X/) {
push @frame_array, $_;
}
}
return \@frame_array;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment