<commit_before>package sudoku

import (
	"math/rand"
)

//Fill will find a random filling of the puzzle that is valid. If it cannot find one,
// it will return False and leave the grid as it found it. Generally you would only want to call this on
//grids that have more than one solution (e.g. a fully blank grid)
func (self *Grid) Fill() bool {

	solutions := self.nOrFewerSolutions(1)

	if len(solutions) != 0 {
		self.Load(solutions[0].DataString())
		return true
	}

	return false
}

func GenerateGrid(symmetry SymmetryType, symmetryPercentage float64) *Grid {
	grid := NewGrid()
	//Do a random fill of the grid
	grid.Fill()

	//Make sure symmetry percentage is within the legal range.
	if symmetryPercentage < 0.0 {
		symmetryPercentage = 0.0
	}
	if symmetryPercentage > 1.0 {<commit_msg>GoDoc for GenerateGrid and Grid.Fill<commit_after>package sudoku

import (
	"math/rand"
)

//Fill will find a random filling of the puzzle such that every cell is filled and no cells conflict with their neighbors. If it cannot find one,
// it will return false and leave the grid as it found it. Generally you would only want to call this on
//grids that have more than one solution (e.g. a fully blank grid). Fill provides a good starting point for generated puzzles.
func (self *Grid) Fill() bool {

	solutions := self.nOrFewerSolutions(1)

	if len(solutions) != 0 {
		self.Load(solutions[0].DataString())
		return true
	}

	return false
}

//GenerateGrid returns a new sudoku puzzle with a single unique solution and many of its cells unfilled--a
//puzzle that is appropriate (and hopefully fun) for humans to solve. GenerateGrid first finds a random
//full filling of the grid, then iteratively removes cells until just before the grid begins having
//multiple solutions. The result is a grid that has a single valid solution but many of its cells
//unfilled. symmetrty and symmetryType control the aesthetics of the generated grid. symmetryPercentage
//controls roughly what percentage of cells with have a filled partner across the provided plane of
//symmetry. SYMMETRY_VERTICAl, 0.7 give reasonable results that feel balanced but not perfectly symmetrical.
//GenerateGrid doesn't currently give any way to define the desired difficulty; the best option is to
//repeatedly generate puzzles until you find one that matches your desired difficulty. cmd/dokugen
//applies this technique.
func GenerateGrid(symmetry SymmetryType, symmetryPercentage float64) *Grid {
	grid := NewGrid()
	//Do a random fill of the grid
	grid.Fill()

	//Make sure symmetry percentage is within the legal range.
	if symmetryPercentage < 0.0 {
		symmetryPercentage = 0.0
	}
	if symmetryPercentage > 1.0 {
{'fraction_non_alphanumeric': 0.06982823002240478, 'fraction_numerical': 0.008961911874533234, 'mean_word_length': 4.045197740112994, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '44970', 'n_tokens_mistral': 767, 'n_tokens_neox': 731, 'n_words': 369}