Skip to content

Instantly share code, notes, and snippets.

@maruks
maruks / heap.sml
Created January 30, 2015 12:14
leftist heap
signature Ordered =
sig
type T
val eq : T * T -> bool
val lt : T * T -> bool
val leq : T * T -> bool
end
(* HEAP *)
@maruks
maruks / heap.clj
Created January 30, 2015 12:15
leftist heap
(declare insert)
(declare find-min)
(declare delete-min)
(declare empty-heap)
(declare is-empty?)
(declare heap-seq)
(deftype LeftistHeap [^Integer rank ^Integer elem left right]
clojure.lang.IPersistentStack
(peek [this]
(ns sandbox.words
(:require [clojure.string :refer [blank? trim join]]))
(def split-at-chars #{\newline \space \tab})
(defn cut-single-line [text column-length]
(if (> (count text) column-length)
(let [line (drop-while (complement split-at-chars) (reverse text))
length (count line)]
(cond
@maruks
maruks / dojo2.erl
Created June 16, 2015 08:42
7 languages in 7 weeks: Erlang day 2
-module(dojo2).
-import(lists,[nth/2]).
-include_lib ("eunit/include/eunit.hrl").
-compile(export_all).
lookup(K,[{K,V}|_Tl]) ->
V;
lookup(K,[{_D,_V}|Tl]) ->
lookup(K, Tl);
lookup(_K,[]) ->
@maruks
maruks / dojo4.erl
Created July 21, 2015 22:17
July Hack Night
-module(dojo4).
-import(lists,[nth/2]).
-include_lib ("eunit/include/eunit.hrl").
-compile(export_all).
rand_list(Size) ->
lists:map(fun(X)-> random:uniform(100) end, lists:seq(1,Size)).
grid(Size) ->
lists:map(fun(X)-> rand_list(Size) end, lists:seq(1,Size)).
(ns dojo.core)
(def prices {:A 2.5
:B 3.0})
(def zones-map {"Asterix" :A
"Aldgate" :A
"Barbican" :B
"Balham" :B})
@maruks
maruks / Sudoku solver clojure
Created November 3, 2011 11:04
Sudoku solver
(ns sudoku.core
(:use clojure.set)
(:use [clojure.contrib.seq :only [find-first]]))
(defn select-row [vek i]
(let [start (- i (rem i 9))
end (+ start 9)]
(set (for [e (range start end)](vek e)))))
(defn select-column [vek i]
package dream;
import sleep.Sleeper;
public class Dream {
int num = 0;
public void dream(final Sleeper s) {
if (num++ < 10) {
Thread thread = new Thread(new Runnable() {
public void run() {
@maruks
maruks / core.clj
Created June 18, 2012 22:06
my code from code dojo 8
(ns code-dojo.core
(:use [code-dojo.core] [clojure.math.combinatorics] [clojure.java.io :only (reader)])
(:use [speclj.core]))
(def dictionary
(map #(.toLowerCase %)
(line-seq (reader "english_words.txt"))))
(defn same-length [len coll]
(filter #(= len (count %)) coll))
@maruks
maruks / load_theme.el
Created September 30, 2012 14:44
Load custom emacs 24 theme with no confirmation
(defun l0ad-theme (name)
(interactive
(list
(intern (completing-read "Load custom theme: "
(mapcar 'symbol-name (custom-available-themes))))))
((load-theme name t)))