<commit_before>package Bowling;

use strict;
use warnings;

our @EXPORT = qw(new roll score);

my @rolls;

sub new {
  return bless {rolls => []}, shift;
}

sub roll {
  push @{shift->{rolls}}, shift;
}

sub score {
  my $score = 0;
  my $pos = 0;
  @rolls = @{shift->{rolls}};

  for(1..10) {
    if(_strike($pos)) {
      $score += _score_strike($pos);
      $pos += 1;
    } elsif (_spare($pos)) {
      $score += _score_spare($pos);
      $pos += 2;
    } else {
      $score += _score_open_frame($pos);
      $pos += 2;
    }
  }
  return $score;
};

sub _score_open_frame {
  my $pos = shift;
  return _ball_one($pos) + _ball_two($pos);
};

sub _score_spare {
  my $pos = shift;
  return _ball_one($pos) + _ball_two($pos) + _bonus_ball_one($pos);
};

sub _score_strike {
  my $pos = shift;
  return _ball_one($pos) + _bonus_ball_one($pos) + _bonus_ball_two($pos);
};

sub _ball_one {
  my $pos = shift;
  return $rolls[$pos];
};

sub _ball_two {
  my $pos = shift;
  return $rolls[$pos+1];
};

sub _bonus_ball_one {
  my $pos = shift;
  return $rolls[$pos+2];
};

sub _bonus_ball_two {
  my $pos = shift;
  return $rolls[$pos+1];
};

sub _strike {
  my $pos = shift;
  if(10 == _ball_one($pos)) {
    return 1;
  } else {
    return 0;
  }
};

sub _spare {
  my $pos = shift;
  if (10 == _ball_one($pos) + _ball_two($pos) and 10 > _ball_one($pos)) {
    return 1;
  } else {
    return 0;
  }
};

1;
<commit_msg>remove those if-elses<commit_after>package Bowling;

use strict;
use warnings;

our @EXPORT = qw(new roll score);

my @rolls;

sub new {
  return bless {rolls => []}, shift;
}

sub roll {
  push @{shift->{rolls}}, shift;
}

sub score {
  my $score = 0;
  my $pos = 0;
  @rolls = @{shift->{rolls}};

  for(1..10) {
    if(_strike($pos)) {
      $score += _score_strike($pos);
      $pos += 1;
    } elsif (_spare($pos)) {
      $score += _score_spare($pos);
      $pos += 2;
    } else {
      $score += _score_open_frame($pos);
      $pos += 2;
    }
  }
  return $score;
};

sub _score_open_frame {
  my $pos = shift;
  return _ball_one($pos) + _ball_two($pos);
};

sub _score_spare {
  my $pos = shift;
  return _ball_one($pos) + _ball_two($pos) + _bonus_ball_one($pos);
};

sub _score_strike {
  my $pos = shift;
  return _ball_one($pos) + _bonus_ball_one($pos) + _bonus_ball_two($pos);
};

sub _ball_one {
  my $pos = shift;
  return $rolls[$pos];
};

sub _ball_two {
  my $pos = shift;
  return $rolls[$pos+1];
};

sub _bonus_ball_one {
  my $pos = shift;
  return $rolls[$pos+2];
};

sub _bonus_ball_two {
  my $pos = shift;
  return $rolls[$pos+1];
};

sub _strike {
  my $pos = shift;
  return (10 == _ball_one($pos));
};

sub _spare {
  my $pos = shift;
  return (10 == _ball_one($pos) + _ball_two($pos) and 10 > _ball_one($pos));
};

1;

{'fraction_non_alphanumeric': 0.18047016274864375, 'fraction_numerical': 0.014466546112115732, 'mean_word_length': 3.097777777777778, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7418415', 'n_tokens_mistral': 1206, 'n_tokens_neox': 1179, 'n_words': 267}