This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define DIM 9 | |
#define BLANK 0 | |
#define SPACE " " | |
#define LINE "|" | |
#define NEW_ROW "-------------------------------------" | |
#define GRID_FULL std::make_pair(9, 9) | |
// Prints the Soduko grid | |
void print_grid(int grid[DIM][DIM]) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Returns a boolean which indicates whether any assigned entry | |
// in the specified row matches the given number. | |
bool used_in_row(int grid[DIM][DIM], int row, int num) | |
{ | |
for (int col = 0; col < DIM; col++) | |
if (grid[row][col] == num) | |
{ | |
return true; | |
} | |
return false; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Takes a partially filled-in grid and attempts to assign values to | |
// all unassigned locations in such a way to meet the requirements | |
// for Sudoku solution (non-duplication across rows, columns, and boxes) | |
bool solve_soduko(int grid[DIM][DIM]) | |
{ | |
// If the Soduko grid has been filled, we are done | |
if (GRID_FULL == get_unassigned_location(grid)) | |
{ | |
return true; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int main() | |
{ | |
cout << "********************************\n\n\tSudoku Solver\n\n********************************" << endl << endl; | |
int grid[DIM][DIM] = { { 0, 9, 0, 0, 0, 0, 8, 5, 3 }, | |
{ 0, 0, 0, 8, 0, 0, 0, 0, 4 }, | |
{ 0, 0, 8, 2, 0, 3, 0, 6, 9 }, | |
{ 5, 7, 4, 0, 0, 2, 0, 0, 0 }, | |
{ 0, 0, 0, 0, 0, 0, 0, 0, 0 }, | |
{ 0, 0, 0, 9, 0, 0, 6, 3, 7 }, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import matplotlib.pyplot as plt | |
import numpy as np | |
def scatterplot(x_data, y_data, x_label="", y_label="", title="", color = "r", yscale_log=False): | |
# Create the plot object | |
_, ax = plt.subplots() | |
# Plot the data, set the size (s), color and transparency (alpha) | |
# of the points |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import matplotlib.pyplot as plt | |
import numpy as np | |
def scatterplot(x_data, y_data, x_label="", y_label="", title="", color = "r", yscale_log=False): | |
# Create the plot object | |
_, ax = plt.subplots() | |
# Plot the data, set the size (s), color and transparency (alpha) | |
# of the points |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def lineplot(x_data, y_data, x_label="", y_label="", title=""): | |
# Create the plot object | |
_, ax = plt.subplots() | |
# Plot the best fit line, set the linewidth (lw), color and | |
# transparency (alpha) of the line | |
ax.plot(x_data, y_data, lw = 2, color = '#539caf', alpha = 1) | |
# Label the axes and provide a title | |
ax.set_title(title) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def histogram(data, n_bins, cumulative=False, x_label = "", y_label = "", title = ""): | |
_, ax = plt.subplots() | |
ax.hist(data, n_bins = n_bins, cumulative = cumulative, color = '#539caf') | |
ax.set_ylabel(y_label) | |
ax.set_xlabel(x_label) | |
ax.set_title(title) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Overlay 2 histograms to compare them | |
def overlaid_histogram(data1, data2, n_bins = 0, data1_name="", data1_color="#539caf", data2_name="", data2_color="#7663b0", x_label="", y_label="", title=""): | |
# Set the bounds for the bins so that the two distributions are fairly compared | |
max_nbins = 10 | |
data_range = [min(min(data1), min(data2)), max(max(data1), max(data2))] | |
binwidth = (data_range[1] - data_range[0]) / max_nbins | |
if n_bins == 0 | |
bins = np.arange(data_range[0], data_range[1] + binwidth, binwidth) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def barplot(x_data, y_data, error_data, x_label="", y_label="", title=""): | |
_, ax = plt.subplots() | |
# Draw bars, position them in the center of the tick mark on the x-axis | |
ax.bar(x_data, y_data, color = '#539caf', align = 'center') | |
# Draw error bars to show standard deviation, set ls to 'none' | |
# to remove line between points | |
ax.errorbar(x_data, y_data, yerr = error_data, color = '#297083', ls = 'none', lw = 2, capthick = 2) | |
ax.set_ylabel(y_label) | |
ax.set_xlabel(x_label) | |
ax.set_title(title) |
OlderNewer