Skip to content

Instantly share code, notes, and snippets.

View ryanthames's full-sized avatar

Ryan Thames ryanthames

  • Spring Solutions
  • Fort Worth, Texas
View GitHub Profile
max = 2000000
primes = []
def isPrime(n):
x = abs(int(n))
if x < 2:
return False
if n == 2:
return True
if not x & 1:
row1 = [8, 2, 22, 97, 38, 15, 0, 40, 0, 75, 4, 5, 7, 78, 52, 12, 50, 77, 91, 8]
row2 = [49, 49, 99, 40, 17, 81, 18, 57, 60, 87, 17, 40, 98, 43, 69, 48, 4, 56, 62, 0]
row3 = [81, 49, 31, 73, 55, 79, 14, 29, 93, 71, 40, 67, 53, 88, 30, 3, 49, 13, 36, 65]
row4 = [52, 70, 95, 23, 4, 60, 11, 42, 69, 24, 68, 56, 1, 32, 56, 71, 37, 2, 36, 91]
row5 = [22, 31, 16, 71, 51, 67, 63, 89, 41, 92, 36, 54, 22, 40, 40, 28, 66, 33, 13, 80]
row6 = [24, 47, 32, 60, 99, 3, 45, 2, 44, 75, 33, 53, 78, 36, 84, 20, 35, 17, 12, 50]
row7 = [32, 98, 81, 28, 64, 23, 67, 10, 26, 38, 40, 67, 59, 54, 70, 66, 18, 38, 64, 70]
row8 = [67, 26, 20, 68, 2, 62, 12, 20, 95, 63, 94, 39, 63, 8, 40, 91, 66, 49, 94, 21]
row9 = [24, 55, 58, 5, 66, 73, 99, 26, 97, 17, 78, 78, 96, 83, 14, 88, 34, 89, 63, 72]
row10 = [21, 36, 23, 9, 75, 0, 76, 44, 20, 45, 35, 14, 0, 61, 33, 97, 34, 31, 33, 95]
from datetime import datetime
criteria = 500
#start at 66 since we know there's no way that 55 has 500 divisors
triangle_num = 66
increment = 11
found = False
# Python implementation of the karate chop code kata.
# I don't remember if this actually works, I'm just dumping a bunch of old code
# on here so I don't lose it.
import unittest
def chop(target, list):
# binary search implementation
l = 0
h = len(list) - 1
#Python implementation of Euclid's algorithm
import sys
args = sys.argv[1:]
if not args:
print "usage: euclid num1 num2"
sys.exit(1)
if len(args) < 2:
@ryanthames
ryanthames / search_and_replace.py
Created April 7, 2013 15:50
From python cookbook 2nd edition
# From python cookbook 2nd edition
import os, sys
nargs = len(sys.argv)
if not 3 <= nargs <= 5:
print "usage: %s search_text replace_txt [infile [outfile]]" % \
os.path.basename(sys.argv[0])
else:
stext = sys.argv[1]
@ryanthames
ryanthames / sicp-1-3.ss
Created April 7, 2013 15:53
SICP problem 1.3
(define (square x)
(* x x))
;Value: square
(square 5)
;Value: 25
(define (sum-of-squares x y)
(+ (square x) (square y)))
;Value: sum-of-squares
@ryanthames
ryanthames / sicp_section-1-7.ss
Created April 7, 2013 15:54
Exercises from section 1.7 of SICP
#lang scheme
(define (abs x)
(cond ((< x 0) (- x))
(else x)))
(define (square x) (* x x))
(define (good-enough? guess x)
(< (abs (- (square guess) x)) 0.001))
@ryanthames
ryanthames / LokirsDraugrResurrection.psc
Created April 7, 2013 16:00
Papyrus script from the Skyrim Creation Kit tutorial
ScriptName LokirsDraugrResurrection Extends Actor
{Resurrects the two dead Draugr in Lokir's tomb.}
Spell property reanimateSpell Auto
Event OnActivate(ObjectReference akActionRef)
; Cast a Reanimate spell on the Draugr
reanimateSpell.Cast(Self, Self)
EndEvent