Skip to content

Instantly share code, notes, and snippets.

View dradtke's full-sized avatar

Damien Radtke dradtke

View GitHub Profile
@dradtke
dradtke / hello.lisp
Created February 16, 2012 02:08
A simple hello world program using clisp and cl-gtk2. Quicklisp is used for dependency resolution.
; {{{ Load up GTK+
(LOAD '/opt/lisp/quicklisp/setup.lisp)
(ql:quickload "cffi")
(ql:quickload "trivial-garbage")
(ql:quickload "iterate")
(ql:quickload "bordeaux-threads")
(ql:quickload "closer-mop")
(ql:quickload "cl-opengl")
(ql:quickload "cl-cairo2")
(asdf:operate 'asdf:load-op :cl-gtk2-gtk)
-- | BruteQueens.hs
-- | --------------
-- | A brute-force Haskell solution for the generic NxN queens puzzle.
-- | Exactly the same as Queens.hs, though much less efficient.
import System.Environment
type Queen = (Int,Int)
main :: IO ()
@dradtke
dradtke / gist:2051679
Created March 16, 2012 18:27
Partial Haskell solution for Minimum Scalar Product
{-
- Problem URL: http://code.google.com/codejam/contest/32016/dashboard#s=p0
-
- solve takes as input a list of strings for a particular case
- and returns a string representation of its solution.
-}
solve :: [String] -> String
solve input = show $ minimum options
where (l1:l2:l3:_) = input
@dradtke
dradtke / reverse-words.hs
Created March 27, 2012 20:05
Haskell Solution for Reverse Words (Google Code Jam)
data Unsolved = Unsolved { unsolvedNumber :: Int, input :: String }
data Solved = Solved { solvedNumber :: Int, answer :: String }
instance Show Solved where
show (Solved n ans) = "Case #" ++ (show n) ++ ": " ++ ans
main :: IO ()
main = do
input <- fmap lines getContents
let input' = tail input
@dradtke
dradtke / store-credit.hs
Created March 27, 2012 22:12
Haskell Solution for Store Credit (Google Code Jam)
type Input = [String]
data Unsolved = Unsolved { unsolvedNumber :: Int, input :: Input }
data Solved = Solved { solvedNumber :: Int, answer :: String }
data Item = Item { index :: Int, price :: Int }
instance Show Solved where
show (Solved n ans) = "Case #" ++ (show n) ++ ": " ++ ans
@dradtke
dradtke / store-credit2.hs
Created April 4, 2012 14:34
Alternate solution for store credit
import Data.List
type Input = [String]
data Unsolved = Unsolved { unsolvedNumber :: Int, input :: Input }
data Solved = Solved { solvedNumber :: Int, answer :: String }
data Item = Item { index :: Int, price :: Int }
instance Show Solved where
@dradtke
dradtke / Makefile
Created April 25, 2012 22:35
Hello World example for Allegro.
CC := gcc
CFLAGS := -g -Wall
LIBS := -lallegro
SOURCES := $(shell find src/ -type f -name "*.c")
OBJECTS := $(SOURCES:.c=.o)
TARGET := game
all: $(SOURCES) $(TARGET)
$(TARGET): $(OBJECTS)
// src/main.c
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <libspotify/api.h>
#define DEBUG 1
extern const uint8_t g_appkey[];
extern const size_t g_appkey_size;
@dradtke
dradtke / gist:3137051
Created July 18, 2012 15:46
Spot Makefile
CC := clang
PKGS := libspotify alsa
CFLAGS := -g -Wall `pkg-config --cflags $(PKGS)`
LIBS := `pkg-config --libs $(PKGS)` -lpthread
TARGET := spot
SOURCES := $(shell find src/ -type f -name *.c)
OBJECTS := $(patsubst src/%,build/%,$(SOURCES:.c=.o))
DEPS := $(OBJECTS:.o=.deps)
@dradtke
dradtke / permutations.hs
Created August 24, 2012 19:51
Haskell solution for CodeChef - Ambiguous Permutations
import Control.Monad
import Data.List
import Data.Maybe
import System.Exit
main = do
-- get the number for this case, and exit if it's equal to 0
n <- liftM read getLine :: IO (Int)
when (n == 0) exitSuccess