This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(';;'): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data IOOp | |
= EndProgram | |
| ReadLine (String -> IOOp) | |
| WriteLine String IOOp | |
runOp :: IOOp -> IO () | |
runOp EndProgram = return () | |
runOp (ReadLine f) = do | |
line <- getLine |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE DeriveFunctor #-} | |
import Control.Monad.Free | |
data MThing next | |
= MItem String next | |
| MEnd | |
deriving (Show, Functor) | |
doThing :: Free MThing () |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; 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. | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- I have made minor changes to the file below to make it compile | |
-- with GHC 8.0 | |
----------------------------------------------------------------------------- | |
-- Thih: Typing Haskell in Haskell, main program |