This file contains 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
def aud = [200, 100, 50, 20, 10, 5] | |
def usd = [25, 10, 5, 1] | |
def hkd = [1000, 500, 200, 100, 50, 20, 10] | |
def change(denoms, amount) { | |
if (denoms.empty) return [] | |
def denom = denoms.head() | |
[denom] * (amount / denom) + change(denoms.tail(), amount % denom) | |
} |
This file contains 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
percentageBreakdown :: (RealFrac b) => [Integer] -> [b] | |
percentageBreakdown xs = pb xs 1 | |
pb :: (RealFrac b) => [Integer] -> b -> [b] | |
pb [] _ = [] | |
pb [0] _ = [0] | |
pb (x:xs) remaining = [proportion] ++ pb xs (remaining - proportion) where | |
total = sum (x:xs) | |
proportion = fracRound (fromInteger x / fromInteger total * remaining) 2 |
This file contains 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
// Fun exercise with @marsbomber, his solution at https://gist.github.com/4291868 | |
List<BigDecimal> percentageBreakdown(List<Integer> input) { | |
return pb(input, 1.0000) | |
} | |
List<BigDecimal> pb(List<Integer> input, BigDecimal remaining) { | |
if (input.empty) return [] | |
def head = input.head() | |
if (head == 0) return [0] + pb(input.tail(), remaining) |
This file contains 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
import Data.List | |
denomComparator d1 d2 | |
| d1 > d2 = LT | |
| d1 < d2 = GT | |
| d1 == d2 = EQ | |
denomComparator _ _ = EQ | |
coin :: [Int] -> Int -> [Int] | |
coin ds n = coin' ds n [] |
This file contains 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
[user] | |
name = Tommy Yim Li | |
email = tommy.li@firefire.co | |
[color] | |
ui = true | |
diff = auto | |
status = auto | |
branch = auto | |
[branch] | |
autosetuprebase = always |
This file contains 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
-- Tommy Li (tommyli@me.com) | |
-- 2010-12-08 | |
-- This is a Haskell version of Guy Steele's "String Split" in Fortress | |
-- His talk was presented at YOW Australia (Melbourne) 2010 conference | |
-- I saw a tweet someone did it in Python (https://gist.github.com/724905) so I decided to try it in Haskell | |
data WordState = Chunk String | Segment String [String] String | |
deriving Show |