Skip to content

Instantly share code, notes, and snippets.

View NicolasT's full-sized avatar

Nicolas Trangez NicolasT

View GitHub Profile
Stel s = 1 + 2 + 3 + 4 + 5 + ...
-3s = (1 - 4)s
= (1 + 2 + 3 + 4 + 5 + ...) - 2(2 + 4 + 6 + 8 + 10 + ...)
= 1 - 2 + 3 - 4 + 5 - ... [*1]
= 1 - (2 - 3 + 4 - 5 + ...)
= 1 - (1 - 2 + 3 - 4 + 5 - ...) - (1 - 1 + 1 - 1 + ...)
Lemma:
stel t = 1 - 1 + 1 - 1 + 1 - ...
#include <glib.h>
gint main(gint argc, gchar **argv) {
guint64 i = 0;
i = (1 << 35) - 1;
g_print("S: %llu\n", i);
return 0;
SENTINEL = chr(ord('$'))
def rotations(s):
for i in xrange(len(s)):
yield '%s%s' % (s[i:], s[:i])
def bwt(s):
if SENTINEL in s:
raise ValueError('Input can\'t contain chr(%d)' % ord(SENTINEL))
import Control.Arrow
import Data.List
replace_fizzbuzz n = if n `mod` 15 /= 0 then Left n else Right "fizzbuzz"
replace_fizz n = if n `mod` 3 /= 0 then Left n else Right "fizz"
replace_buzz n = if n `mod` 5 /= 0 then Left n else Right "buzz"
fizzbuzz = replace_fizzbuzz >>> (replace_fizz ||| Right) >>>
(replace_fizzbuzz ||| Right) >>> (show ||| returnA)
# Callable arrow implementation
# Arrow type class functions
class arr(object):
'''Arrow type constructor'''
def __init__(self, fun):
self.fun = fun
def __rshift__(self, other):
'''>> combinator implementation'''
# Similar to >>^ in Haskell
# class Person:
# def __init__(self, first_name, last_name, age):
# self.first_name = first_name
# self.last_name = last_name
# self.age = age
Person = lambda first_name, last_name, age: \
lambda: (first_name, last_name, age)
first_name = lambda person: person()[0]
-- Assumptions:
-- Every query returns only one integer
-- The DB connection is somewhere global (should be hidden using a State
-- transformer in a real implementation)
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
module Transaction
(
Transaction
f :: Monad m => m Int -> m Bool
f a = do
b <- a
return $ b == 0
main :: IO ()
main = do
dump $ Just 10
dump $ Just 0
dump Nothing
f :: Monad m => m Int -> m Bool
f a = do
b <- a
return $ b == 0
f' :: Functor f => f Int -> f Bool
f' = fmap helper
where
helper = (== 0)
(def triangle
[[75]
[95 64]
[17 47 82]
[18 35 87 10]
[20 4 82 47 65]
[19 1 23 75 3 34]
[88 2 77 73 7 63 67]
[99 65 4 28 6 16 70 92]
[41 41 26 56 83 40 80 70 33]