Skip to content

Instantly share code, notes, and snippets.

View LOZORD's full-sized avatar
💭
i'm chillin

Leo Rudberg LOZORD

💭
i'm chillin
View GitHub Profile
@LOZORD
LOZORD / factory_test.js
Created February 4, 2016 19:25
Factory Example in ES6 (using Babel)
class Abstr {
constructor(f, o) {
this.f = f;
for (var key in o) {
this[key] = o[key];
}
}
run () {
this.f(this);
}
@LOZORD
LOZORD / day1.rb
Last active December 6, 2015 20:42
My solutions to adventofcode.com
flr = 0
cc = 1
basement_char = nil
File.open('parens.txt', 'r') do |file|
file.each_line do |line|
line.chars.each do |c|
if c == '('
flr += 1
elsif c == ')'
@LOZORD
LOZORD / maze-gen.hs
Last active November 28, 2015 05:16
A dividing-chamber maze generation program in Haskell
import Data.Matrix
import Data.List --(sortBy, intercalate, minimumBy, maximumBy, filter, nubBy)
import qualified Data.Vector as Vector -- hiding (Vector(++))
import System.Environment (getArgs)
import Data.Bits (xor, rotate, shift, complement)
data Cell = Empty | Wall deriving (Eq)
instance Show Cell where
show c = case c of
Empty -> " "
Wall -> "#"
@LOZORD
LOZORD / BusPolicy.java
Last active November 19, 2015 06:03
The programmatic representation of whether or not you are a Badger who takes WildHacks by storm.
// Whether Passenger p (you) can get on the bus at Time t
public boolean attemptToGetOnBus(Passenger p, Time t) throws HustleError {
if (!p.location().equal("CS Building")) {
return false; // what are you doing, kiddo?
} else if (!p.isRegisteredForWildHacks()) {
return false;
}
Time startTime = Time.earliestOf(LEO.arrival(), Time.FIVE_THIRTY);
@LOZORD
LOZORD / intro_to_haskell.markdown
Last active April 9, 2016 23:44
Introduction to Functional Programming with Haskell

Introduction to Functional Programming with Haskell

By Leo Rudberg, for the UPL Video Lecture Series

Preceding slideshow

Setup

First, let's make sure that you have ghc and ghci installed:

$ ghc --version && ghci
# ghci should boot up...
@LOZORD
LOZORD / powerset.hs
Created September 4, 2015 04:24
Powerset implementation in Haskell
import qualified Data.Set as Set
phi :: Set.Set a
phi = Set.empty
pset :: (Ord a) => Set.Set a -> Set.Set (Set.Set a)
pset set = if (Set.null set)
then Set.singleton phi
else
let head = Set.elemAt 0 set
@LOZORD
LOZORD / grid.java
Last active August 29, 2015 14:23
The Grid
import java.awt.Color;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.*;
import javax.imageio.ImageIO;
import java.lang.Math;
import java.lang.Number;
public class Grid
{
@LOZORD
LOZORD / trunc_prime.hs
Last active August 29, 2015 14:22
Project Euler 37
import Data.List (nub, unfoldr)
-- FIXME
primeItr :: Integer -> Integer -> Bool
primeItr n i
| (i * i) > n = True
| otherwise = if (n `mod` i) == 0
then False
else primeItr n (i + 1)
isPrime :: Integer -> Bool
isPrime n = primeItr n 2 -- 2-7 primes do not count (n > 10)
@LOZORD
LOZORD / ruby_tutorial.markdown
Last active August 29, 2015 14:21
UPLVLS: Learn to Program with Ruby!

UPLVLS: Learn to Program with Ruby!

Preceding slideshow here

Introduction

Go ahead and fire up a Ruby REPL. You can use irb if you want... Let's write the canonical first program, "Hello world!". In Ruby, it's very simple.

puts 'Hello world!'
@LOZORD
LOZORD / qsort.hs
Last active August 29, 2015 14:12
A quicksort implementation in Haskell
-- the middle integer item from a list
middle :: [Integer] -> Integer
middle list = list !! (fromIntegral midInd)
where midInd = length list `div` 2
-- the median of three integer values
-- thanks to Tony Jiang from HH Coding for the improved algo!
qMed3 :: Integer -> Integer -> Integer -> Integer
qMed3 a b c = min firstMax (max firstMin c)
where firstMax = max a b