Skip to content

Instantly share code, notes, and snippets.

View timjb's full-sized avatar

Tim Baumann timjb

View GitHub Profile
@timjb
timjb / BKTree.hs
Created December 8, 2011 21:55 — forked from anonymous/BKTree.hs
module Data.BKTree (
BKTree,
MetricSpace(..),
empty,
null,
size,
singleton,
insert,
query,
@timjb
timjb / CDeclarations.hs
Created January 4, 2012 14:08
Trying to understand C declarations
import Data.Maybe (maybe)
import Data.List (intercalate)
data CType = CInt
| CDouble
| CChar
| CVoid
| CPointer CType
| CArray CType (Maybe Int)
| CFun CType [CType]
-- Exercise 2-2 d) in "Introduction to Algorithms" (3rd edition)
module Main where
import Test.QuickCheck
import Data.List (sort)
split :: [a] -> ([a], [a])
split as = splitAt (length as `div` 2) as
-- Chapter 4.1 in "Introduction to Algorithms" (3rd edition)
-- Linear algorithm (Exercise 4.1-5)
{-# LANGUAGE BangPatterns #-}
module Main where
import Data.List (inits, tails, maximumBy)
import Data.Function (on)
import Test.QuickCheck
-- usage: runhaskell PrintRepo.hs | pandoc -fjson -thtml --standalone
module Main where
import Control.Monad (liftM, forM)
import Data.Monoid (mconcat, mempty, mappend)
import System.FilePath (FilePath, splitDirectories, takeExtension, (</>))
import System.Posix.Directory (getWorkingDirectory)
import System.Directory (doesDirectoryExist, getDirectoryContents)
import qualified Text.Pandoc as P
@timjb
timjb / ghc-install-ubuntu-src.sh
Created February 4, 2012 12:24 — forked from binarybana/ghc-install-ubuntu-src.sh
How to install GHC 7.4.1 in Ubuntu from source
#Install prerequisites
sudo aptitude install ghc darcs
#Get GHC 7.4.1 source and cabal-install HEAD
wget http://www.haskell.org/ghc/dist/7.4.1/ghc-7.4.1-src.tar.bz2
darcs get --lazy http://darcs.haskell.org/cabal/
tar xjf ghc-7.4.1-src.tar.bz2
cd ghc-7.4.1
./configure --prefix=$HOME/src/ghc
time make -j9 #Only took me about 19 minutes on recent quad core xeon
@timjb
timjb / count-compare-operations.js
Created March 23, 2012 13:03
Informatik-Unterricht: Zählen der Vergleichsoperationen beim Sortieren eines Arrays
// $ node count-compare-operations.js > abc.txt
// $ R
// > plot(read.table("abc.txt"))
function generate_ints(n) {
var arr = [];
while (n--) {
arr.push(Math.floor(Math.random()*1000));
}
return arr;
var kandidat = 0.8; // Wahrscheinlichkeit, dass Kandidat die richtige Antwort weiß
var experte = 0.7; // Wahrscheinlichkeit, dass Experte die richtige Antwort weiß
function chanceKandidatGewinnt () {
var n = 10000;
var gewinnt = 0;
for (var i = 0; i < n; i++) {
var k = 0, e = 0;
while (true) {
if (Math.random() < kandidat) { k++; }
-- http://mysliceofpizza.blogspot.de/2012/04/puzzle.html
colorsRow :: Int -> Int
colorsRow 0 = 0
colorsRow 1 = 1
colorsRow n = 1 + colorsRow (n `div` 2)
-- colorsRow = (+1) . floor . logBase 2 . fromIntegral
-- | Computes the number of colors needed to colorize an n*n field
-- such that every subrectangle has at least one color that appears
#!/bin/bash
while ping -c1 google.com > /dev/null; do
echo "reachable"
sleep 1
done