Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View ambuc's full-sized avatar

James Adam Buckland ambuc

View GitHub Profile
@ambuc
ambuc / Isometric.hs
Created August 31, 2017 00:59
Isometric.hs
module Isometric
( Obj (..) , World , isometric , mark , render , seenFrom , solid
) where
import Codec.Picture (PixelRGBA8 (..), writePng, Image)
import Data.Monoid ((<>))
import Data.Function (on)
import Data.List (transpose, genericLength, sortBy)
import Data.Ord (comparing)
import Data.Matrix (Matrix, fromList, toList, transpose)
@ambuc
ambuc / irrev-cube.hs
Created August 24, 2017 22:49
Puzzle Pong - Irreversible Cube I
import Codec.Picture( PixelRGBA8( .. ), writePng, Image)
import Control.Arrow (first,second)
import Data.Function (on)
import Data.List (sort, nub, sortBy, groupBy, nubBy, delete, zip4, (\\), zipWith4)
import Data.List.Split (chunksOf)
import Data.Monoid ((<>))
import Data.Ord (comparing)
import Debug.Trace (trace)
import Graphics.Rasterific
import Graphics.Rasterific.Texture (uniformTexture)
@ambuc
ambuc / successive-rows.hs
Created July 15, 2017 20:58
Successive Rows of Horizontal, Straight Lines from Top to Bottom, and Vertical, Straight Lines from Left to Right, 1972
import Codec.Picture( PixelRGBA8( .. ), writePng )
import Graphics.Rasterific
import Graphics.Rasterific.Texture
import Graphics.Rasterific.Transformations
import Data.List
refl = transform $ applyTransformation
Transformation { _transformA = 0.0, _transformC = 1.0, _transformE = 0.0,
_transformB = 1.0, _transformD = 0.0, _transformF = 0.0
}
@ambuc
ambuc / crossword.hs
Last active May 28, 2017 05:28
Puzzle Pong - Generating All Possible 4x4 Crosswords
import qualified Control.Monad as N (forM)
import qualified Data.Maybe as B (isJust, isNothing, fromJust, catMaybes)
import qualified Data.Char as C (isAsciiLower)
import qualified Data.Function as F (on)
import qualified Data.List as L (all, nub, groupBy, intercalate)
import qualified Data.List.Split as L (chunksOf)
import qualified Data.Map.Strict as M (Map, insert, empty, unions, findWithDefault)
import qualified Language.Words as W (allStringWords)
type Box = Maybe Char
@ambuc
ambuc / graph.dot
Last active April 30, 2017 18:47
A Painting Puzzle
digraph G {
size = "4,4";
"[1,1,1,1]" -> "[1,1,2]" [label="1"];
"[1,1,2]" -> "[1,1,2]" [label="1/2"];
"[1,1,2]" -> "[1,3]" [label="1/3"];
"[1,1,2]" -> "[2,2]" [label="1/6"];
"[1,3]" -> "[1,3]" [label="1/2"];
"[1,3]" -> "[2,2]" [label="1/4"];
"[1,3]" -> "[4]" [label="1/4"];
"[2,2]" -> "[1,3]" [label="2/3"];
@ambuc
ambuc / tough_puzzle.hs
Created April 29, 2017 19:23
One Tough Puzzle
import Data.List
import Data.List.Split (chunksOf)
import Data.Char
data Suit = Club | Heart | Diamond | Spade deriving (Show, Read, Eq)
data Sex = Out | In deriving (Show, Read, Eq)
data Side = Side { suit :: Suit , sex :: Sex} deriving (Show, Read)
instance Eq Side where x == y = (suit x == suit y) && (sex x /= sex y)
data Piece = Piece { north :: Side , east :: Side
, south :: Side , west :: Side } deriving (Show, Read, Eq)
@ambuc
ambuc / oracle.hs
Created April 29, 2017 19:21
Aaronson Oracle
import Data.Map as M
import Data.Maybe
import Numeric
learn :: [Bool] -> Map [Bool] Double -> Map [Bool] Double
learn hist brain = Prelude.foldr learn' brain [3..5]
where learn' n = M.insertWithKey (const (+)) (take n hist) 1.0
guess :: Map [Bool] Double -> [Bool] -> Bool
guess brain hist = wAvg (Prelude.map guess' [2..4]) >= 0.5
" CUSTOM .VIMRC by JAMES BUCKLAND
" james.adam.buckland@gmail.com
" created June 01 2014
" :so %
"
"PLUGINS
call pathogen#infect() " enable pathogen extention handler
filetype plugin indent on " idk, something to do with plugins
set laststatus=2 " i'll be honest, i have no idea what this does. but it makes
# regular leader key
set -g prefix 'C-b'
bind-key 'C-b' send-prefix
set -g default-terminal "screen-256color"
set -sg escape-time 0 #Escape works without delay, important for Vim
#Star window and pane indexing at 1
set -g base-index 1
set -g pane-base-index 1
@ambuc
ambuc / LaTeX macros
Last active August 29, 2015 14:22
useful custom macros for typesetting vector calculus in LaTeX
%typeset \sgn as an upright operator name, like \sin. ex: \sgn(x)
\DeclareMathOperator{\sgn}{sgn}
%rename built-in command \v to \vaccent, to make room for...
\let\vaccent=\v
% ...\v, which typesets a bold, upright vector. ex: \v a
\renewcommand{\v}[1]{\ensuremath{\mathbf{#1}}}
% ... and \gv, which does the same for greek letters. ex: \gv\alpha