Skip to content

Instantly share code, notes, and snippets.

@sphynx
sphynx / gist:4aab07d3e8417f790ea0
Created March 26, 2015 21:38
Solver for probabilistic coupons problem
import Data.Ratio
main :: IO ()
main = print $ result 5
result :: Integer -> Rational
result size = abs $ sum
[ fromIntegral mult * infTailSum size d
| (mult, d) <- coeffs size
]
@sphynx
sphynx / KnightTour.hs
Last active August 29, 2015 14:24
Knight Tour at Haskell Hoodlums
module Main where
import Data.Array
import Data.List
import Data.Ord
import Text.Printf
type Coord = (Int, Int)
type Size = (Int, Int)
;; Packages.
(require 'package)
(add-to-list 'package-archives
(cons "melpa-stable" "http://stable.melpa.org/packages/") t)
(package-initialize)
(add-to-list 'load-path "~/elisp") ;; for saving some custom code.
;; Save customizations in a separate file.
(setq custom-file (expand-file-name "custom.el" user-emacs-directory))
;; Packages.
(require 'package)
(add-to-list 'package-archives
(cons "melpa-stable" "http://stable.melpa.org/packages/") t)
(package-initialize)
(add-to-list 'load-path "~/elisp") ;; for saving some custom code.
;; Save customizations in a separate file.
(setq custom-file (expand-file-name "custom.el" user-emacs-directory))
@sphynx
sphynx / serial.c
Last active December 18, 2018 23:21
Example of functions inside global structures, emulating "Serial" from Arduino language.
#include <stdio.h>
#include <stdlib.h>
typedef void (*func) (const char *);
struct module {
func print;
func println;
};