Skip to content

Instantly share code, notes, and snippets.

import re, sys # this file requires python 3
def parse(tokens):
stack = ([], None)
for t in tokens:
if t == '(':
stack = ([], stack)
elif t == ')':
(finished_list, stack) = stack
stack[0].append(finished_list)
elif not t.startswith(';;'):
with open('img.ppm', 'w') as outf:
outf.write('P6 256 256 255 ')
for i in xrange(256):
for j in xrange(256):
outf.write('%c%c%c' % (i ^ j, i ^ (255 - j), (i+j) % 256))
data IOOp
= EndProgram
| ReadLine (String -> IOOp)
| WriteLine String IOOp
runOp :: IOOp -> IO ()
runOp EndProgram = return ()
runOp (ReadLine f) = do
line <- getLine
{-# LANGUAGE DeriveFunctor #-}
import Control.Monad.Free
data MThing next
= MItem String next
| MEnd
deriving (Show, Functor)
doThing :: Free MThing ()
import Control.Monad (liftM)
import Data.IORef (IORef, newIORef, modifyIORef', readIORef)
import Data.Map (Map)
import qualified Data.Map as Map
import Control.Monad.Trans.Except (ExceptT, Except, except, runExcept, mapExcept, throwE)
import Control.Monad.IO.Class (liftIO)
data IVal
= IInt Int
def f(k, n):
'''
k indistinct bucket,
n (n > k) balls,
each bucket must have at least one ball,
how many ways are there to put n balls in k buckets?
'''
if k == 1:
# Only one way to put things in one bucket
return 1
mem = {}
def collatz_len(n):
if n < 2:
return 1
if n not in mem:
chain = 1 + collatz_len(n/2 if n%2 == 0 else 3*n + 1)
mem[n] = chain
return mem[n]
;;; rdarkmod-theme.el --- Theme
;; Copyright (C) 2016 , Jeremy M
;; Author: Jeremy M
;; Version: 0.1
;; Package-Requires: ((emacs "24"))
;; Created with ThemeCreator, https://github.com/mswift42/themecreator.
{-# LANGUAGE DeriveFunctor #-}
-- This needs the 'free' package installed in order to build
import Control.Monad (when)
import Control.Monad.Free (Free (..))
import System.IO (hFlush, stdout)
main :: IO ()
main = runIOOp exampleProgram
-- I have made minor changes to the file below to make it compile
-- with GHC 8.0
-----------------------------------------------------------------------------
-- Thih: Typing Haskell in Haskell, main program