Skip to content

Instantly share code, notes, and snippets.

View jcchurch's full-sized avatar

James Church jcchurch

View GitHub Profile
@jcchurch
jcchurch / makeGraph.py
Created April 18, 2018 15:45
Generates the edge list for a randomly generated graph.
#!/usr/bin/env python3
import argparse
import random
def generateGraph(v, e, m):
print(v)
print(e)
matrix = [0] * (v*v)
num=int(input())
for i in range(num, -1, -1):
print(" "*i + "*"*((num-i)*2+1))
for i in range(1, num+1):
print(" "*i + "*"*((num-i)*2+1))
for i in range(num*2+1):
print("*"*(num*2+1))
for i in range(num, -1, -1):
print(" "*i + "*"*((num-i)*2+1))
for i in range(1, num+1):
Height: Width:
. 7 7 9 5 2 8 5 6 6 1 9 2 1 4 4 8 4 6 4 6 2 9 3 8 1 6 4 9 6
. . 7 4 6 1 5 6 8 3 8 9 9 1 8 6 6 5 3 1 5 3 7 3 4 2 8 5 6 3
7 . . . . . . 3 6 4 7 9 6 8 9 5 2 3 1 9 1 8 3 7 9 9 8 5 9 2
2 8 3 3 7 8 . 5 8 1 9 2 5 1 3 9 3 8 1 4 4 6 5 5 5 1 8 5 1 7
9 1 9 1 1 9 . . . 9 8 1 8 8 3 5 4 4 4 9 3 8 6 6 5 4 4 1 7 3
9 1 2 2 6 6 5 6 . . . . . 6 1 9 3 5 1 6 6 5 2 2 3 7 1 5 1 9
6 1 5 1 8 2 1 9 8 5 4 6 . 2 8 6 8 1 2 3 9 2 7 2 8 8 8 9 1 5
8 5 5 7 1 9 8 9 4 8 4 4 . . . . 9 9 3 8 4 6 8 6 6 1 2 2 2 8
8 6 3 1 6 6 5 8 9 3 9 4 5 7 7 . . . . . 1 2 3 4 4 6 3 8 4 1
@jcchurch
jcchurch / piConvergeVis.py
Created March 13, 2018 05:32
Demonstrates how random numbers can be used to converge upon pi.
"""
Suppose we create a 2 unit by 2 unit square.
Suppose we drop that square's center on the origin point
of a Cartesian graph.
The area of this square is 4.
Suppose we then create a 1 unit radius circle and drop
"""
pow is a function that computes $a^b$ in $O(lg b)$ time.
Here, I compute $3^0$ to $3^9$ and compare the results to Python's math.pow function.
"""
import math
@jcchurch
jcchurch / ulam.py
Last active January 24, 2018 16:37
Ulam Spiral in Python 3 in less than 280 characters. Small enough to tweet!
import tkinter as t
d=500
w=t.Canvas(t.Tk(),width=d,height=d)
w.pack()
x=d/2;y=x;v=1;z=0;c=2;r=1;p=[]
for i in range(2,d*200):
x+=v;y+=z
if r*2==c:z=v;v=0
if r==c:v=-z;z=0;c+=2;r=0
r+=1;t=1
@jcchurch
jcchurch / BubbleSort.mas
Last active October 22, 2016 22:44
BubbleSort in the MarieSim language.
// Bubble Sort
// By James Church
// 2016-10-20
//
// How this works:
// Scroll down the bottom of this file.
// You'll see 10 values that are randomly
// ordered. This is the input to the algorithm.
// These can be rearranged into any order.
//
public class MyFormatter {
public static void main(String[] args) {
System.out.println(String.format("%s", "Hi Chris")); // "Hi Chris"
System.out.println(String.format("%d", 42)); // "42"
System.out.println(String.format("%f", Math.PI)); // "3.141593"
System.out.println();
System.out.println(String.format("%4d", 2)); // " 4"
System.out.println(String.format("%04d", 2)); // "0004"
System.out.println();
System.out.println(String.format("%.3f", Math.PI)); // "3.142"
@jcchurch
jcchurch / today.py
Last active August 22, 2024 02:08
Adds line to let bash know that this is a python 3 script.
#!/usr/bin/env python3
import datetime
import argparse
import re
def createDate(stringDate):
if re.match("\d\d\d\d-\d\d-\d\d$", stringDate) is None:
raise ValueError("This is not in the correct date format. Use YYYY-MM-DD")
import re
import urllib.request
import urllib.parse
def downloadPage(domain, path):
filehandle = urllib.request.urlopen(domain + path)
page = filehandle.readlines()
return page
def getEntry(page, i):