Skip to content

Instantly share code, notes, and snippets.

View quantumelixir's full-sized avatar

Angel System quantumelixir

View GitHub Profile
@quantumelixir
quantumelixir / latex-challenge.tex
Created August 5, 2010 16:47
Latex Equation Challenge
\documentclass[12pt]{article}
\usepackage{fullpage}
\usepackage[fleqn]{amsmath}
\begin{document}
\begin{abstract}
\begin{center}
Equation Challenge
\end{center}
@quantumelixir
quantumelixir / spiral.go
Created January 14, 2011 19:25
Prints a clockwise spiral of numbers 1, 2, 3, ...
package main
import "fmt"
func main() {
size := 7
grid := make([][]int, size)
for k := 0; k < size; k++ {
@quantumelixir
quantumelixir / golomb.py
Created January 15, 2011 10:19
Finds the n-th golomb number
import bisect
import timeit
#Finds the Nth golumb number from the
#sequence x(n) using a binary search
def findNthGolumb(n, x, upto) :
pos = bisect.bisect(x, n, 1, upto)
return pos - 1
#Creates the sequence x(n) where x(n) is k
@quantumelixir
quantumelixir / quines.py
Created January 15, 2011 10:24
Some quines I made in Python
#Quine1
e=r'''print "e=r''"+"'"+e+"''"+"'\n"+e'''
print "e=r''"+"'"+e+"''"+"'\n"+e
#Quine2
x='%s=%s;print x%%("x",chr(39)+x+chr(39))';print x%("x",chr(39)+x+chr(39))
#Quine3
y="%"
z='y="%s"\nz=%s\nprint z%s(y,repr(z),y)'
@quantumelixir
quantumelixir / partitions.py
Created January 15, 2011 10:34
Compare two methods of computing partitions using Python's "yield" construct
#!/usr/bin/env python
def partitions(n, curtot = 0, cur = []) :
if curtot == n :
yield cur
t = cur[-1] if cur else 1
for i in xrange(t, n - curtot + 1) :
@quantumelixir
quantumelixir / list_all_paths.py
Created January 15, 2011 10:39
Compare two methods of listing all paths between two nodes in a graph
#!/usr/bin/env python
import timeit
graph = {'A': ['B', 'C'],
'B': ['C', 'D'],
'C': ['D'],
'D': ['C'],
'E': ['F'],
'F': ['C']}
@quantumelixir
quantumelixir / factorial.c
Created January 15, 2011 14:23
Compute factorial of a given number using two different methods (uses GMP)
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <time.h>
#include <gmp.h>
long int NAIVE = 30;
typedef unsigned long int ulong;
@quantumelixir
quantumelixir / cpuid.s
Created January 15, 2011 14:18
CPUID in GNU Assembly
.section .data
output:
.ascii "The processor Vendor ID is: "
vendor_id:
.ascii "xxxxYYYYzzzz\n"
.section .bss
.section .text
@quantumelixir
quantumelixir / gemv.c
Created January 15, 2011 14:26
Matrix-Vector multiplication optimization and benchmarking
/*
* y += A*x
*
* Matrix-Vector multiplication optimization experiment
* TODO: Benchmark against the following:
* eigen2: ourselves, with the default options (SSE2 vectorization enabled).
* eigen2_novec: ourselves but with Eigen's explicit vectorization disabled. However, gcc's auto-vectorization was enabled.
* INTEL_MKL: The Intel Math Kernel Library, which includes a BLAS/LAPACK (11.0). Closed-source.
* ACML: The AMD's core math library, which includes a BLAS/LAPACK (4.2.0). Closed-source.
@quantumelixir
quantumelixir / testblas.c
Created January 15, 2011 14:32
Demonstrate how to use cblas
#include <stdio.h>
#include <cblas.h>
double m[] = {
3, 1, 3,
1, 5, 9,
2, 6, 5
};
double x[] = {