Skip to content

Instantly share code, notes, and snippets.

View md2perpe's full-sized avatar

Per Persson md2perpe

View GitHub Profile
We couldn’t find that file to show.
firstNonRep :: String -> Maybe Char
firstNonRep cs = fmap fst $ find (\(c, n) -> n == 1) $ foldl count [] cs
where
count [] c = [(c, 1)]
count (p@(c', n) : ps) c | c == c' = (c', n+1) : ps
| otherwise = p : count ps c
data Tree t = EmptyTree
| Node t (Tree t) (Tree t)
deriving Show
nivel :: Int -> Int
nivel n = nivel' n 0
where
nivel' 0 _ = 0
nivel' 1 x = x
nivel' n x = nivel' (n `div` 2) (x + 1)
@md2perpe
md2perpe / measurable.js
Created June 12, 2011 21:15 — forked from dachev/measurable.js
Is Measurable
// Recursive version
function isMeasurable(target, weights)
{
if (weights.length == 0)
return target == 0;
var first = weights.shift();
return
isMeasurable(target-first, weights) ||
@md2perpe
md2perpe / mvf.js
Created June 1, 2011 22:05 — forked from fogus/gist:1002886
Methods and fields in Javascript
var M = function() { };
M.prototype = {
m : function() { return 42 }
};
var inst = new M();
inst.f = function() { return 42 };
@md2perpe
md2perpe / gist:999471
Created May 30, 2011 21:09 — forked from GodsBoss/gist:960745
Access to protected base class members of a subclass via another subclass.
<?php
class Base
{
private $x;
public function getX()
{
return $this->x;
}