Skip to content

Instantly share code, notes, and snippets.

View gist:2289676
bubbleSort :: (Ord a) => [a] -> [a]
bubbleSort [] = []
bubbleSort [x] = [x]
bubbleSort (x:y:xs) = if sorted thisSort then thisSort else bubbleSort thisSort
where thisSort = (min x y) : bubbleSort ((max x y):xs)
sorted :: (Ord a) => [a] -> Bool
sorted [] = True
sorted [x] = True
sorted (x:y:xs) = if x <= y then sorted (y:xs) else False
View gist:2289678
puts "Hello world"
View gist:2289680
bubbleSort :: (Ord a) => [a] -> [a]
bubbleSort [] = []
bubbleSort [x] = [x]
bubbleSort (x:y:xs) = if sorted thisSort then thisSort else bubbleSort thisSort
where thisSort = (min x y) : bubbleSort ((max x y):xs)
sorted :: (Ord a) => [a] -> Bool
sorted [] = True
sorted [x] = True
sorted (x:y:xs) = if x <= y then sorted (y:xs) else False
View gist:2289711
import Data.List
insertionSort :: (Ord a) => [a] -> [a]
insertionSort = foldr insert []
View gist:2289792
quickSort :: (Ord a) => [a] -> [a]
quickSort [] = []
quickSort (x:xs) = quickSort smaller ++ [x] ++ quickSort larger
where smaller = filter (<=x) xs
larger = filter (>x) xs
@5outh
5outh / gist:3093214
Created Jul 11, 2012
99 Haskell Problems: Problem 13
View gist:3093214
data Count = Multiple Int Char
| Single Char
deriving (Eq, Show)
encodeDirect :: [Char] -> [Count]
encodeDirect = map toCount . foldr encode []
where
toCount (x, y) = case x of
1 -> Single y
_ -> Multiple x y
View gist:3094373
var target : Transform;
var distance = 10.0;
var xSpeed = 250.0;
var ySpeed = 120.0;
var zoomSpeed = 10;
var yMinLimit = -20;
var yMaxLimit = 80;
var zoomMinLimit = 10;
View gist:3094378
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 / gist:3094384
Created Jul 11, 2012
Move Character
View gist:3094384
#pragma strict
var forwardSpeed = 10;
var backwardSpeed = 8;
var sideSpeed = 10;
var xDisplacement:float;
var zDisplacement:float;
var displacement:Vector3;