This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module Data.BKTree ( | |
| BKTree, | |
| MetricSpace(..), | |
| empty, | |
| null, | |
| size, | |
| singleton, | |
| insert, | |
| query, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Data.Maybe (maybe) | |
| import Data.List (intercalate) | |
| data CType = CInt | |
| | CDouble | |
| | CChar | |
| | CVoid | |
| | CPointer CType | |
| | CArray CType (Maybe Int) | |
| | CFun CType [CType] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // $ 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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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++; } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| while ping -c1 google.com > /dev/null; do | |
| echo "reachable" | |
| sleep 1 | |
| done |