<commit_before>package pathfinderpkg

import (
	"sort"
)

// cost to buy ability score
// 3 through 6 are not legal values
// and are extrapolations mirroring the
// top end of the scale for comparison
// only
func AbilityCost(ability int) (int, bool) {
	ability_cost := map[int]int{
		1:  -25,
		2:  -20,
		3:  -16,
		4:  -12,
		5:  -9,
		6:  -6,
		7:  -4,
		8:  -2,
		9:  -1,
		10: 0,
		11: 1,
		12: 2,
		13: 3,
		14: 5,
		15: 7,
		16: 10,
		17: 13,
		18: 17,
		19: 21,
		20: 26,
		21: 31,
		22: 37,
		23: 43,
		24: 50,
		25: 57,
		26: 65,
		27: 73,
		28: 82,
		29: 91,
		30: 101,
		31: 111,
		32: 122,
		33: 133,
		34: 145,
		35: 157,
		36: 170,
		37: 183,
		38: 197,
		39: 211,
		40: 226,
		41: 241,
		42: 257,
		43: 273,
		44: 290,
		45: 307,
	}
	value, ok := ability_cost[ability]
	return value, ok
}

// (define (cost-abilities ab)
//   (apply + (map ability->cost ab)))
func AbilityModifier(ability int) (int, bool) {
	ability_modifier := map[int]int{
		1:  -5,
		2:  -4,
		3:  -4,
		4:  -3,
		5:  -3,
		6:  -2,
		7:  -2,
		8:  -1,
		9:  -1,
		10: 0,
		11: 0,
		12: 1,
		13: 1,
		14: 2,
		15: 2,
		16: 3,
		17: 3,
		18: 4,
		19: 4,
		20: 5,
		21: 5,
		22: 6,
		23: 6,
		24: 7,
		25: 7,
		26: 8,
		27: 8,
		28: 9,
		29: 9,
		30: 10,
		31: 10,
		32: 11,
		33: 11,
		34: 12,
		35: 12,
		36: 13,
		37: 13,
		38: 14,
		39: 14,
		40: 15,
		41: 15,
		42: 16,
		43: 16,
		44: 17,
		45: 17,
	}
	value, ok := ability_modifier[ability]
	return value, ok
}

type Abilities []int
type MapFunc func(int) int
type ApplyFunc func(x, y int) int

// implement sort.Interface
func (ab Abilities) Len() int           { return len(ab) }
func (ab Abilities) Less(i, j int) bool { return ab[i] < ab[j] }
func (ab Abilities) Swap(i, j int)      { ab[i], ab[j] = ab[j], ab[i] }

// for chaining...i.e. chained calls like in functional paradigm
func (ab Abilities) Sortf() Abilities { sort.Sort(ab); return ab }

// apply a function to each ability returning the new Abilities
// with the result of the function call mapped to the position of the
// value passed to the function.  For example, when ab is {1, 2, 3}
// ab.Map(times2) returns a new Ability {2, 4, 6} and ab is unchanged
func (ab Abilities) Map(fn MapFunc) Abilities {
	result := make(Abilities, ab.Len())
	for i, v := range ab {
		result[i] = fn(v)
	}
	return result<commit_msg>Change AbilityCost and AbilityModifier from map to slice implementation<commit_after>package pathfinderpkg

import (
	"sort"
)

// cost to buy ability score
// 3 through 6 are not legal values
// and are extrapolations mirroring the
// top end of the scale for comparison
// only
func AbilityCost(ability int) (int, bool) {
	ability_cost := []int{
		-25,
		-20,
		-16,
		-12,
		-9,
		-6,
		-4,
		-2,
		-1,
		0,
		1,
		2,
		3,
		5,
		7,
		10,
		13,
		17,
		21,
		26,
		31,
		37,
		43,
		50,
		57,
		65,
		73,
		82,
		91,
		101,
		111,
		122,
		133,
		145,
		157,
		170,
		183,
		197,
		211,
		226,
		241,
		257,
		273,
		290,
		307,
	}
	if ability < 1 || ability > 45 {
		return 0, false
	} else {
		return ability_cost[ability-1], true
	}
}

// (define (cost-abilities ab)
//   (apply + (map ability->cost ab)))
func AbilityModifier(ability int) (int, bool) {
	ability_modifier := []int{
		-5,
		-4,
		-4,
		-3,
		-3,
		-2,
		-2,
		-1,
		-1,
		0,
		0,
		1,
		1,
		2,
		2,
		3,
		3,
		4,
		4,
		5,
		5,
		6,
		6,
		7,
		7,
		8,
		8,
		9,
		9,
		10,
		10,
		11,
		11,
		12,
		12,
		13,
		13,
		14,
		14,
		15,
		15,
		16,
		16,
		17,
		17,
	}
	if ability < 1 || ability > 45 {
		return 0, false
	} else {
		return ability_modifier[ability-1], true
	}
}

type Abilities []int
type MapFunc func(int) int
type ApplyFunc func(x, y int) int

// implement sort.Interface
func (ab Abilities) Len() int           { return len(ab) }
func (ab Abilities) Less(i, j int) bool { return ab[i] < ab[j] }
func (ab Abilities) Swap(i, j int)      { ab[i], ab[j] = ab[j], ab[i] }

// for chaining...i.e. chained calls like in functional paradigm
func (ab Abilities) Sortf() Abilities { sort.Sort(ab); return ab }

// apply a function to each ability returning the new Abilities
// with the result of the function call mapped to the position of the
// value passed to the function.  For example, when ab is {1, 2, 3}
// ab.Map(times2) returns a new Ability {2, 4, 6} and ab is unchanged
func (ab Abilities) Map(fn MapFunc) Abilities {
	result := make(Abilities, ab.Len())
	for i, v := range ab {
		result[i] = fn(v)
	}
	return result
{'fraction_non_alphanumeric': 0.1532912533814247, 'fraction_numerical': 0.11316501352569883, 'mean_word_length': 2.313666915608663, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '4596976', 'n_tokens_mistral': 2441, 'n_tokens_neox': 1955, 'n_words': 661}