Skip to content

Instantly share code, notes, and snippets.

if(Input.GetKey("w")){
xDisplacement = Mathf.Sin(Mathf.Deg2Rad * transform.eulerAngles.y);
zDisplacement = Mathf.Cos(Mathf.Deg2Rad * transform.eulerAngles.y);
displacement = Vector3(xDisplacement, 0, zDisplacement) * forwardSpeed * Time.deltaTime;
transform.position += displacement;
}
@5outh
5outh / thisisbrainfuck.b
Created July 17, 2012 04:50
hello, brainfuck
+++++ +++++ initialize counter (cell #0) to 10
[ use loop to set the next four cells to 70/100/30/10
> +++++ ++ add 7 to cell #1
> +++++ +++++ add 10 to cell #2
> +++ add 3 to cell #3
> + add 1 to cell #4
<<<< - decrement counter (cell #0)
]
> ++ . print 'H'
import Control.Applicative
import Control.Arrow
game = scanl1 (+) . getFrameScores . getFrames
where
getFrames xs = if length scores == 10 then scores
else (take 9 scores) ++ [concat $ drop 9 scores]
where
scores = parseScores xs
parseScores [] = []
@5outh
5outh / euler057.hs
Created August 3, 2012 17:13
Project Euler #57
data Fraction = Frac Integer Integer deriving Show -- Numerator Denominator
sqrtTwo = (map rep [0..] !!)
where
rep 0 = Frac 1 2
rep x = (Frac 1 1) |/| ( (Frac 2 1) |+| (sqrtTwo $ pred x))
answer = length . filter moreInDenom . roots
where
roots = map (\x -> simplify $ Frac 1 1 |+| sqrtTwo x) . enumFromTo 0
@5outh
5outh / tc04.hs
Created August 5, 2012 16:59
Code Golf
import Data.List
import System.Environment
f=concat.r
r []=[[]]
r s=(scanr(:)[]s):(r$init s)
g [a,b]=snd.maximum.map(\x->(length x,x))$intersect(f a)(f b)
main=getArgs>>= \z-> print.g$z
@5outh
5outh / tc04Comments.hs
Created August 5, 2012 17:33
Golf w/ comments
import Data.List -- gets us the function "intersect"
import System.Environment -- gets us the function "getArgs"
f=concat.r -- calls "r" on some input and flattens the results (concat)
{- The function "r" takes a list of elements and produces all of it's possible sublists.
Base case: If the input list is empty, return an empty list containing a single empty list. -}
r []=[[]] -- base case for "r"
r s= (scanr(:)[]s) {- recursively build substrings from the list "s"
@5outh
5outh / frac.hs
Created August 15, 2012 21:49
Fraction data type
data Fraction = Frac Integer Integer -- Numerator Denominator
instance Show Fraction where
show (Frac a b) = (show a) ++ " / " ++ (show b)
@5outh
5outh / numDemon.hs
Created August 15, 2012 21:55
numDenom
num :: Fraction -> Integer
num (Frac a _) = a
denom :: Fraction -> Integer
denom (Frac _ b) = b
@5outh
5outh / simplify.hs
Created August 15, 2012 21:58
Simplify
simplify :: Fraction -> Fraction
simplify (Frac a b) = Frac (a `quot` factor) (b `quot` factor)
where factor = gcd a b
@5outh
5outh / FracNum.hs
Created August 15, 2012 22:06
FracNum
instance Num Fraction where
(-) f f' = f + (negate f')
(+) (Frac a b) (Frac c d) = Frac num denom
where denom = lcm b d
num = a * (denom `quot` b) + c * (denom `quot` d)
(*) (Frac a b) (Frac c d) = Frac (a*c) (b*d)
negate (Frac a b) = Frac (-a) b
abs f = fmapF abs f
where fmapF f (Frac a b) = Frac (f a) (f b)
fromInteger x = Frac x 1