This file contains hidden or 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
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. |
This file contains hidden or 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
(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 |
This file contains hidden or 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
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') |
This file contains hidden or 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
{- | | |
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 |
This file contains hidden or 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
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 |
This file contains hidden or 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
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 |
This file contains hidden or 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
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 |
This file contains hidden or 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
╭ ◜ ◝ ͡ ◝ ͡ ◜ ◝ ╮ | |
(fill in here) | |
╰ ͜ ╯ | |
O | |
o | |
° | |
〃∩ ∧_∧ 💕 | |
⊂⌒( ´・ω・)💕 | |
`ヽ_っ_/ ̄ ̄ ̄/ | |
\/___/ |
This file contains hidden or 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
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 |
This file contains hidden or 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
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) |