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 random | |
import turtle | |
# 1. Hello World! | |
# This is designed as a first introduction to the language. | |
# One print statement and done! | |
def print_hello_world(): | |
print "Hello, World!" |
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
# Generator for all pythagorean triples s.t. r < bound | |
def pyth_triples(bound): | |
for r in range(2, bound): | |
for s in range(1, r): | |
yield [r*r - s*s, 2*r*s, r*r + s*s] | |
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 collections | |
def next_div(n): | |
for i in xrange(2, n): | |
if (n % i == 0): | |
return i | |
return n | |
# d | n, d is prime |
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 itertools | |
def prime_gen(): | |
yield 2 | |
curr = 3 | |
seen = [2] | |
while (True): | |
yield curr |
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
#!/usr/bin/python | |
# For more information: http://www.cut-the-knot.org/Probability/LightBulbs.shtml | |
# To implement your own strategy, simply implement a Prisoner | |
# class which has a single method visit_room() which returns boolean | |
# according to the answer provided to the warden. | |
# Global variables n (number of prisoners for simulation) and | |
# lightbulb (the lightbulb where True is on and False is off) |
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 Lang = DEmpty | DEps | DChar String | DCat Lang Lang | DAlt Lang Lang | DRep Lang | |
stringOfLang l = case l of | |
DEmpty -> "DEmpty" | |
DEps -> "DEps" | |
DChar x -> "DChar (" ++ x ++ ")" | |
DCat lx ly -> "DCat (" ++ (stringOfLang lx) ++ ", " ++ (stringOfLang ly) ++ ")" | |
DAlt lx ly -> "DAlt (" ++ (stringOfLang lx) ++ ", " ++ (stringOfLang ly) ++ ")" | |
DRep lx -> "DRep (" ++ (stringOfLang lx) ++ ")" |
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
let comp = fun f -> (fun g -> (fun x -> f (g x)));; | |
let doublesquare = comp (fun x -> x + x) (fun y -> y * y);; | |
print_int (doublesquare 5); print_newline ();; | |
(* expect 50 *) |
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
#!/bin/bash | |
cat << EOF > ./ternary.c | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <time.h> | |
int main(int argc, char *argv[]) { | |
int a, b, c, d, e, f, g; |
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 Data.Function.Memoize | |
-- SLOW | |
fib :: Int -> Integer | |
fib 0 = 0 | |
fib 1 = 1 | |
fib n = fib (n - 1) + fib (n - 2) | |
-- Memoized / FAST | |
fib' :: Int -> Integer |
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
#! /bin/bash | |
cat << EOF > ./RandAscii.hs | |
module Main (main) where | |
import Control.Monad | |
import System.Random | |
import qualified Data.Char as Char |
OlderNewer