Skip to content

Instantly share code, notes, and snippets.

View quephird's full-sized avatar

danielle quephird

View GitHub Profile
OK... so for my DoDonPascii game I can generate waves of baddies, each with different sprites
and attack patterns. But now, I want to be able to associate potential powerups with certain
waves of baddies. One of the common idioms/cliches in shmups is having to wait for the red
planes to come out; if you shoot them all then a powerup is dropped. If even one escapes,
the opportunity is gone and you have to wait for the next wave of red planes to come out.
Here are the rules that I think I want to try to enforce:
* The powerup is _only_ associated with a specific wave when comes out.
* The powerup _only_ becomes available when all of the baddies in that wave are destroyed.
@quephird
quephird / bndm.clj
Last active August 29, 2015 14:13
A really rough first cut of a string searching function using the so-called BNDM algorithm
(defn bndm [pattern string]
"Searches for the pattern in the string using the BNDM algorithm;
it returns a list of the indices where there is a match."
(let [uniq-letters (set pattern)
indexed-letters (map-indexed vector pattern)
bitmasks (into {}
(for [c uniq-letters]
[c (reduce + (map (fn [[idx c']] (if (= c c') (bit-shift-left 1 idx) 0)) indexed-letters))]))]
(loop [d 0 idx 0 acc []]
(cond
@quephird
quephird / Complex.purs
Created March 29, 2015 03:50
Just a dopey implementation of a Complex type in PureScript
module Data.Complex where
data Complex = Complex Number Number
instance showComplex :: Show Complex where
show (Complex x y) = show x ++ " + " ++ show y ++ "i"
instance eqComplex :: Eq Complex where
(==) (Complex x y) (Complex x' y') = (x == x') && (y == y')
(/=) (Complex x y) (Complex x' y') = (x /= x') || (y /= y')
@quephird
quephird / Mabes.hs
Created April 7, 2015 23:52
Solution to Alej's exercise
{- |
Fill in the Blank: Meet Mabes - the other Maybe type.
This exercise is all about defining common abstraction over Mabes, e.g.:
* Functor
* Applicative
* Monad
* Alternative
@quephird
quephird / writeFirstWords.hs
Created April 12, 2015 03:17
Using the supplied interactWith function, write another function that writes the first word of each line to another file.
interactWith :: (String -> String) -> FilePath -> FilePath -> IO ()
interactWith f inputFile outputFile = do
input <- readFile inputFile
writeFile outputFile (f input)
writeFirstWords inputFile outputFile = interactWith firstWords inputFile outputFile where
firstWord "" = ""
firstWord line = head $ words line
firstWords file = unlines $ map firstWord $ lines file
@quephird
quephird / TransposeFile.hs
Last active August 29, 2015 14:19
Using the supplied interactWith function, write another function that transposes the file contents of the input and writes it to another file.
interactWith :: (String -> String) -> FilePath -> FilePath -> IO ()
interactWith f inputFile outputFile = do
input <- readFile inputFile
writeFile outputFile (f input)
transpose = unlines . transpose' . lines where
transpose' ss | all ((==) "") ss = []
transpose' ss = map head nonEmptySs : (transpose' $ map tail nonEmptySs) where
nonEmptySs = filter ((/=) "") ss
splitWith :: (a -> Bool) -> [a] -> [[a]]
splitWith p l
| null l = []
| null xs = splitWith p $ tail xs'
| otherwise = xs : splitWith p xs' where
(xs, xs') = break p l
╭ ◜ ◝ ͡ ◝ ͡ ◜ ◝ ╮
(fill in here)
╰ ͜ ╯
O
o
°
〃∩ ∧_∧ 💕
⊂⌒( ´・ω・)💕
`ヽ_っ_/ ̄ ̄ ̄/
    \/___/
@quephird
quephird / aaarrrggghhh.elm
Last active August 29, 2015 14:24
This is a rewrite of the example chapter 2 of Elm by Example that is compatible with Elm 0.15 and 2.1.0 of the core libraries.
module Fibonacci where
import List exposing ((::), head, map2, reverse, tail)
import Maybe exposing (andThen)
fibonacci : Int -> List Int
fibonacci n =
let fibonacci' n acc =
if n <= 2
then acc
@quephird
quephird / Pi.purs
Last active September 3, 2015 22:39
Solution to exercise in PureScript by Example book to estimate pi
module Pi where
import Control.Monad.Eff (Eff(..), forE)
import Control.Monad.Eff.Random (RANDOM(..), random)
import Control.Monad.ST (ST(..), modifySTRef, newSTRef, readSTRef)
import Data.Array ((:), filter, length)
import Data.Int (toNumber)
import Data.Tuple (Tuple(..))
import Prelude (($), (<=), (+), (*), (/), bind, return, unit)