Skip to content

Instantly share code, notes, and snippets.

View charlesreid1's full-sized avatar

Chaz Reid charlesreid1

View GitHub Profile
public class Polynomial {
public Polynomial add(Polynomial p) {
int degp = p.coeffs.length;
int degthis = this.coeffs.length;
int mindegree = Math.min(degp, degthis);
int maxdegree = Math.max(degp, degthis);
public class EscapeHelloWorld {
public static void main(String[] args) {
System.out.println("A well-formed Java program has");
System.out.println("a main method with { and }");
System.out.println("braces.\n");
System.out.println("A system.out.println statement");
System.out.println("has ( and ) and usually a");
System.out.println("String that starts and ends");
System.out.println("with a \" character.");
# Sort by total time, in descending order
cat profiler_output_nqueens.csv | sort -n -r
# Sort by time per call (third column in file), in descending order
# -d "," means use "," as a field (column) delimiter
# -f 3,4 means grab fields (columns) 3 and 4
cat profiler_output_nqueens.csv | cut -d "," -f 3,4 | sort -n -r
echo "----------"
echo "running command 1..."
time for i in {0..1000}; do true; done
echo "----------"
echo "running command 2..."
time for i in {0..1000}; do echo "hello world" >> file; done
echo "----------"
echo "running command 3..."
# Look ma, no modules!
# bottlenecks around 12, when the problem size starts to mushroom
board_size = 11
solutions = []
queens = []
occupied = board_size*[0,]
@charlesreid1
charlesreid1 / nqueens.pl
Last active March 20, 2017 08:42
Solving the N queens problem using Perl. Implementing a verb-based approach.
#!/usr/local/bin/perl
use Time::HiRes qw(time);
use strict;
use warnings;
my $start = time;
######################################
########## N Queens Puzzle ###########
#
#
@charlesreid1
charlesreid1 / NQueens.java
Last active October 1, 2021 22:50
Solving the N queens problem using Java. Implementing a verb-based approach utilizing fast built-in data structures.
import java.util.LinkedList;
import java.util.Arrays;
public class NQueens {
public static final int SIZE = 11;
///////////////////////////////////////////////////
// main
//
@charlesreid1
charlesreid1 / TSP.java
Last active March 28, 2017 00:26
Traveling Salesperson Problem with Guava. Implements a recursive backtracking solution to solve the TSP using a Guava Network (Graph). git.charlesreid1.com/charlesreid1/tsp
import java.util.Random;
import java.util.Set;
import java.util.Map;
import java.util.TreeMap;
import java.util.List;
import java.util.LinkedList;
import java.util.Arrays;
import com.google.common.graph.Network;
import com.google.common.graph.NetworkBuilder;
import com.google.common.graph.ImmutableNetwork;
import java.util.LinkedList;
public class ListTiming {
public static void main(String[] args) {
long startTime, endTime, diff;
// Time our list object
startTime = System.nanoTime();
testMyList();
import java.util.*;
// This class implements the Fisher-Yates Shuffle Algorithm.
//
// Author: Charles Reid
// Class: CSC 142
// Date: March 2017
public class FisherYates {
public static void main(String[] args) {