Skip to content

Instantly share code, notes, and snippets.

View GeorgeSeif's full-sized avatar

George GeorgeSeif

View GitHub Profile
@GeorgeSeif
GeorgeSeif / sudoku_setup.cpp
Created December 26, 2017 17:12
Sudoku Grid Setup
#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])
{
@GeorgeSeif
GeorgeSeif / sudoku_rules.cpp
Last active December 26, 2017 17:22
Defines the rules of Sudoku
// 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;
@GeorgeSeif
GeorgeSeif / sudoku_bfs.cpp
Created December 26, 2017 17:26
Brute Force Search algorithm for solving Sudoku
// 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;
}
@GeorgeSeif
GeorgeSeif / sudoku_main.cpp
Created December 26, 2017 17:36
Main function for the Sudoku solver
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 },
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
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
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)
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)
# 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)
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)