Skip to content

Instantly share code, notes, and snippets.

View clementi's full-sized avatar
🎵
NP: Piano Sonata No. 1 in F-Sharp Minor, Op… (3:48/5:21)

Jeff Pratt clementi

🎵
NP: Piano Sonata No. 1 in F-Sharp Minor, Op… (3:48/5:21)
View GitHub Profile
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
head [ (a, b, c) | c <- [1..], b <- [1..c], let a = 1000 - b - c, a^2 + b^2 == c^2 ]
@clementi
clementi / euler-39.java
Created March 2, 2011 23:19
Project Euler Problem 39 Solution
public static void main(String[] args) {
int max = 0;
int bestP = 0;
for (int p = 1; p <= 1000; p++) {
int found = 0;
for (int a = 1; a <= p / 4; a++) {
for (int b = 1; b <= (p - a) / 2; b++) {
double c = Math.sqrt(a * a + b * b);
if (a + b + c == p)
found++;
@clementi
clementi / show-git-in-bash.sh
Created March 8, 2011 21:29 — forked from henrik/.bashrc
Show Git branch in the bash prompt
# http://henrik.nyh.se/2008/12/git-dirty-prompt
# http://www.simplisticcomplexity.com/2008/03/13/show-your-git-branch-name-in-your-prompt/
# username@Machine ~/dev/dir[master]$ # clean working directory
# username@Machine ~/dev/dir[master*]$ # dirty working directory
function parse_git_dirty {
[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "*"
}
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/[\1$(parse_git_dirty)]/"
@clementi
clementi / euler-39.py
Created March 9, 2011 02:45
Project Euler Problem 39 Solution
import itertools
class PythagoreanTriple(object):
def __init__(self, a, b, c):
self._a = a
self._b = b
self._c = c
def __hash__(self):
return hash(self._a) * hash(self._b) - hash(self._c)
def __eq__(self, other):
@clementi
clementi / euler-30.py
Created March 23, 2011 02:34
Project Euler Problem #30 Solution
def digits(n):
result = []
while n > 0:
result = [n % 10] + result
n /= 10
if not result:
return [0]
return result
@clementi
clementi / euler-34.py
Created March 23, 2011 03:37
Project Euler Problem #34 Solution
def digits(n):
result = []
while n > 0:
result = [n % 10] + result
n /= 10
if not result:
return [0]
return result
def factorial(n):
@clementi
clementi / simplewebserver.py
Created April 15, 2011 22:06
A simple web server.
#!/usr/bin/env python
import sys
import BaseHTTPServer
from SimpleHTTPServer import SimpleHTTPRequestHandler
HandlerClass = SimpleHTTPRequestHandler
ServerClass = BaseHTTPServer.HTTPServer
Protocol = "HTTP/1.0"
@clementi
clementi / jquery.stringify.js
Created May 3, 2011 17:24
jQuery Stringify
/**
* jQuery.stringify (https://gist.github.com/953765)
*
* converted stringify() to jQuery plugin.
* serializes a simple object to a JSON formatted string.
* uses browser's native JSON.stringify() if it exists.
* Note: stringify() is different from jQuery.serialize() which URLEncodes form elements
*
* UPDATES:
* Added a fix to skip over Object.prototype members added by the prototype.js library
@clementi
clementi / FermatPrimalityTester.scala
Created May 19, 2011 03:00
Fermat Primality Tester
import scala.util.Random
import scala.collection.immutable._
import scala.math._
class FermatPrimalityTester(rounds: Int) {
private val this.rounds = rounds
private val random = new Random
def isPrime(subject: Int): Boolean = {
return this.getRandomIntegers(subject)