<commit_before>package dice

import (
	"fmt"
	"math/rand"
	"regexp"
	"strconv"
	"sort"
)

type StdRoller struct{}

var stdPattern = regexp.MustCompile(`([0-9]+)d([0-9]+)((kh|dl|kl|dh)([0-9]+))?([+-][0-9]+)?($|\s)`)

func (StdRoller) Pattern() *regexp.Regexp { return stdPattern }

type StdResult struct {
	basicRollResult
	Rolls []int
	Dropped []int
	Total int
}

func (r StdResult) String() string {
	return fmt.Sprintf("%d %v (%v)", r.Total, r.Rolls, r.Dropped)
}

func (StdRoller) Roll(matches []string) (RollResult, error) {
	fmt.Println( matches )

	dice, err := strconv.ParseInt(matches[1], 10, 0)
	if err != nil {
		return nil, err
	}

	sides, err := strconv.ParseInt(matches[2], 10, 0)
	if err != nil {
		return nil, err
	}

	keep := ""
	num := 0
	if matches[4] != "" {
		number, err := strconv.ParseInt(matches[5], 10, 0)
		if err != nil {
			return nil, err
		}
		num = int(number)
		keep = matches[4]
	}
	
	result := StdResult{
		basicRollResult: basicRollResult{matches[0]},
		Rolls:           make([]int, dice),
		Dropped:		 nil,
		Total:           0,
	}

	if matches[6] != "" {
		bonus, err := strconv.ParseInt(matches[6], 10, 0)
		if err != nil {
			return nil, err
		}
		result.Total += int(bonus)
	}

	for i := 0; i < len(result.Rolls); i++ {
		roll := rand.Intn(int(sides)) + 1
		result.Rolls[i] = roll
	}

	sort.Ints( result.Rolls )
	size := len( result.Rolls )
	
	if keep == "kh" {
		result.Dropped = result.Rolls[:size-num]
		result.Rolls = result.Rolls[size-num:]
	}
	if keep == "dl" {
		result.Dropped = result.Rolls[:num]
		result.Rolls = result.Rolls[num+1:]
	}
	if keep == "kl" {
		result.Dropped = result.Rolls[num+1:]
		result.Rolls = result.Rolls[:num]
	}
	if keep == "dh" {
		result.Dropped = result.Rolls[size-num:]
		result.Rolls = result.Rolls[:size-num]
	}
	
	for i := 0; i < len(result.Rolls); i++ {
		result.Total += result.Rolls[i]
	}

	return result, nil
}

func init() {
	addRollHandler(StdRoller{})
}<commit_msg>reformatted<commit_after>package dice

import (
	"fmt"
	"math/rand"
	"regexp"
	"sort"
	"strconv"
)

type StdRoller struct{}

var stdPattern = regexp.MustCompile(`([0-9]+)d([0-9]+)((k|d|kh|dl|kl|dh)([0-9]+))?([+-][0-9]+)?($|\s)`)

func (StdRoller) Pattern() *regexp.Regexp { return stdPattern }

type StdResult struct {
	basicRollResult
	Rolls   []int
	Dropped []int
	Total   int
}

func (r StdResult) String() string {
	return fmt.Sprintf("%d %v (%v)", r.Total, r.Rolls, r.Dropped)
}

func (StdRoller) Roll(matches []string) (RollResult, error) {
	dice, err := strconv.ParseInt(matches[1], 10, 0)
	if err != nil {
		return nil, err
	}

	sides, err := strconv.ParseInt(matches[2], 10, 0)
	if err != nil {
		return nil, err
	}

	keep := ""
	num := 0
	if matches[4] != "" {
		number, err := strconv.ParseInt(matches[5], 10, 0)
		if err != nil {
			return nil, err
		}
		num = int(number)
		keep = matches[4]
	}

	result := StdResult{
		basicRollResult: basicRollResult{matches[0]},
		Rolls:           make([]int, dice),
		Dropped:         nil,
		Total:           0,
	}

	if matches[6] != "" {
		bonus, err := strconv.ParseInt(matches[6], 10, 0)
		if err != nil {
			return nil, err
		}
		result.Total += int(bonus)
	}

	for i := 0; i < len(result.Rolls); i++ {
		roll := rand.Intn(int(sides)) + 1
		result.Rolls[i] = roll
	}

	sort.Ints(result.Rolls)
	size := len(result.Rolls)

	switch keep {
	case "k":
		fallthrough
	case "kh":
		result.Dropped = result.Rolls[:size-num]
		result.Rolls = result.Rolls[size-num:]
	case "d":
		fallthrough
	case "dl":
		result.Dropped = result.Rolls[:num]
		result.Rolls = result.Rolls[num+1:]
	case "kl":
		result.Dropped = result.Rolls[num+1:]
		result.Rolls = result.Rolls[:num]
	case "dh":
		result.Dropped = result.Rolls[size-num:]
		result.Rolls = result.Rolls[:size-num]
	}

	for i := 0; i < len(result.Rolls); i++ {
		result.Total += result.Rolls[i]
	}

	return result, nil
}

func init() {
	addRollHandler(StdRoller{})
}
{'fraction_non_alphanumeric': 0.18686094069529652, 'fraction_numerical': 0.01789366053169734, 'mean_word_length': 3.4065315315315314, 'pattern_counts': {'":': 6, '<': 7, '<?xml version=': 0, '>': 3, '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': '541331', 'n_tokens_mistral': 1743, 'n_tokens_neox': 1614, 'n_words': 352}