Skip to content

Instantly share code, notes, and snippets.

View jcchurch's full-sized avatar

James Church jcchurch

View GitHub Profile

Random Restart Hill Climbing

Random Restart Hill Climbing for N Queens (N=20) found a solution in 60 seconds.

[ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Q ~ ~ ~ ~ ~ ~ ~
  ~ ~ ~ ~ ~ ~ ~ Q ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
  ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Q ~ ~ ~ ~ ~ ~
  ~ ~ ~ ~ ~ ~ Q ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
  Q ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~

~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Q ~

// ==UserScript==
// @name Set the editor mode
// @namespace
// @description Set the Plain Text Mode within Moddle
// @include http://courses.cs.westga.edu/*
// @version 0.1
// @grant none
// ==/UserScript==
//
// This script will change the default Plain Text editor format
import turtle
"""
Solve the maze in Python 3!
In part 2a of the final, you will be completing a maze.
Your goal is to direct the red turtle (named "tot") to the
green square at the end of the maze. You are not allowed to
cross into the blue portion of the maze.
@jcchurch
jcchurch / turtleFlowers.py
Last active October 13, 2024 03:20
This Python script (for Python 3) demonstrates how to draw flowers at random places, colors, and sizes around the screen using the turtle library built into Python 3.
import turtle
import random
import math
def drawPolygon(myTurtle, sides, length):
angle = 360 / sides
for side in range(sides):
myTurtle.forward(length)
myTurtle.left(angle)
# Greet the user
print("This program will compute the sum and average of odd numbers.")
print("Enter values at the prompt. To stop, enter 0.")
# The average is computed by the total of odd numbers
# divided by the count of odd numbers. We need variables
# to store the total and the count.
# Set total and count to zero
total = 0
@jcchurch
jcchurch / aardvark.c
Created August 7, 2014 19:17
A unix shell that I wrote in C during my senior year at UT Martin. Wow, this is 10 years old.
/*
*
* The Aardvark Shell
* By James Church
*
* It is better to kiss an avocado than to get in a fight with an aardvark.
*
* Released under the OH-PLEASE-DONT-LET-MY-SOFTWARE-DIE-AT-THE-CRUEL-HANDS-OF-SLASHDOT Licence
* 2004-11-25
*
@jcchurch
jcchurch / linreg.py
Last active December 31, 2015 04:39
Simple Linear Regression in Python using the vanilla language features.
def simple(x, y):
assert len(x) == len(y)
xavg = sum(x) / float(len(x))
yavg = sum(y) / float(len(y))
xdiff = [ xi - xavg for xi in x ]
ydiff = [ yi - yavg for yi in y ]
xy = [ xdiff[i] * ydiff[i] for i in range(len(x)) ]
xx = [ xdiff[i] * xdiff[i] for i in range(len(x)) ]
gradient = sum(xy) / sum(xx)
intercept = yavg - gradient * xavg
class Tree:
def __init__(self, x=0, l=None, r=None):
self.x = x
self.l = l
self.r = r
def visibleCountRecursive(root, maxthusfar):
visible = 0
visibleLeft = 0
visibleRight = 0
import java.util.*;
import java.lang.*;
public class Taunting {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
while (scan.hasNextInt()) {
double thisx = 0;
double thisy = 0;
@jcchurch
jcchurch / rps.c
Last active December 24, 2015 00:19
Attempts to solve Rock, Paper, or Scissors? https://icpcarchive.ecs.baylor.edu/external/40/4065.pdf in C with as few characters as possible.
#include <stdio.h>
int main(){int t,n,p,a,b;scanf("%d\n",&t);for(;t>0;t--){p=0;scanf("%d\n",&n);for(;n>0;n--){scanf("%c %c\n",&a,&b);if(b-a>0||b-a==-3)p++;else if(b-a<0)p--;}if(p==0)printf("TIE\n");else printf("Player %d\n",p>0?1:2);}}