Skip to content

Instantly share code, notes, and snippets.

View quephird's full-sized avatar

danielle quephird

View GitHub Profile
@quephird
quephird / Sums.purs
Last active September 4, 2015 20:31
Solution to exercise 2 in section 8.7 in PureScript by Example
module Sums where
import Data.Array ((:), foldM, nub, sort)
import Data.Maybe (Maybe(..))
import Prelude (($), (+), (++), map)
-- Given an array of integers, compute the list of all
-- possible totals, using each integer at most once.
sums :: Array Int -> Maybe (Array Int)
@quephird
quephird / FilterM.purs
Created September 5, 2015 21:52
Solution to exercise 5 in section 8.7 in PureScript by Example
module FilterM where
import Prelude (Monad, ($), (<), (>), (/=), bind, return)
import Data.List (List(..))
import Data.Maybe (Maybe(..))
filterM' :: forall m a. (Monad m) => (a -> m Boolean) -> List a -> List a -> m (List a)
filterM' p acc Nil = return acc
filterM' p acc (Cons x xs) = do
@quephird
quephird / HelloGlsl.purs
Last active August 5, 2016 02:14
Trying to get a minimal example of GLSL in PureScript
module Example.HelloGlsl where
import Prelude (Unit(..)
,($)
,bind)
import Control.Monad.Eff (Eff(..))
import Control.Monad.Eff.Alert (Alert(..)
,alert)
import Control.Monad.Eff.Console (CONSOLE(..)
@quephird
quephird / Plot.purs
Last active September 17, 2015 23:16
Partial solution to third problem in first set of exercises in Chapter 9 of PureScript by Example
module Plot where
import Prelude (($), bind, return)
import Control.Monad.Eff (Eff(..))
import Data.List (List(..), toList)
import Data.Maybe (Maybe(..))
import Graphics.Canvas ( Canvas(..)
, Context2D(..)
, closePath
class Vehicle {
var color: String?
var maxSpeed = 80 {
willSet(s) {
print("Changing max speed from \(s)...")
}
didSet(s) {
print("to \(s)")
}
}
import Foundation
class Vehicle {
lazy var isWarmedUp: Bool = self.start()
var color: String?
var maxSpeed = 80 {
willSet(s) {
print("Changing max speed from \(s)...")
}
didSet(s) {
#version 3.7;
global_settings { assumed_gamma 1.0 }
#include "colors.inc"
#include "glass.inc"
#include "textures.inc"
// Random color generator with moving seed
#declare My_seed = seed(now * 100000);
@quephird
quephird / pe13.clj
Last active December 10, 2015 22:46
This is a solution for ProjectEuler #13 that avoids "cheating" by resorting to BigInteger.
(defn solution [big-string]
(->> big-string
(clojure.string/split-lines) ; Break string into individual numbers
(map reverse) ; Reverse the digits in each
(map (fn [n] (map #(Integer/parseInt (str %)) n))) ; Turn all characters into actual ints
(apply map +) ; Sum each column of digits
(reduce (fn [[digits carry] n] ; Fold over the partial sums,
[(conj digits (rem (+ n carry) 10)) ; adding the current sum modulo ten to the list of digits
(quot (+ n carry) 10)]) [() 0]) ; and taking the quotient over ten as the carry
((fn [[digits carry]] (str carry (apply str digits)))) ; Convert back to a single string, last carry at the front.
(ns ellipses
(:require [quil.core :as q :include-macros true]
[quil.middleware :as m]))
(defn setup []
(q/background 0)
(q/stroke-weight 0.25)
(q/no-fill)
(q/color-mode :hsb)
(q/no-loop))