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
| // obj1 is much more human readable! | |
| var obj1 = { | |
| "a" : "value", | |
| "bc" : "value", | |
| "def" : "value" | |
| } | |
| var obj2 = { | |
| "a" : "value", |
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
| main=putStr$q++show q;q="main=putStr$q++show q;q=" |
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
| var reverse = function (a) { | |
| for (var i=0, arrayLen=a.length ; i<arrayLen/2; i+=1) { | |
| var temp = a[arrayLen-i-1]; | |
| a[arrayLen-i-1] = a[i]; | |
| a[i] = temp; | |
| } | |
| return a; | |
| }; |
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
| var isSublist = function(a,b) { | |
| var a_idx=0; | |
| for(var b_idx=0; b_idx<b.length; b_idx+=1) { | |
| if (a[a_idx]==b[b_idx]) { | |
| if (a_idx==a.length-1) { | |
| return true; | |
| } | |
| a_idx+=1 ; | |
| } | |
| } |
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
| isSublist :: (Eq a) => [a] -> [a] -> Bool | |
| isSublist [] _ = True | |
| isSublist _ [] = False | |
| isSublist (x:xs) ys = case dropWhile (/=x) ys of | |
| [] -> False | |
| (x:rest) -> isSublist xs rest |
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
| import Control.Monad.Fix | |
| ------------------------------------------------ | |
| -- fact | |
| -- fact is a fixpoint for lambda_fact | |
| fact n = if n == 0 then 1 else n * fact (n-1) | |
| lambda_fact = (\g n -> if n == 0 then 1 else n * g (n-1)) | |
| -- fixpoint combinator 'fix' "encode" recursion of fact |
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
| andThen f1 f2 = do f1 | |
| f2 | |
| --foo bar = (print "Executing foo") `andThen` (print bar) `andThen` (do return (length bar)) | |
| -- Container Thing | |
| data Thing a = Thing a deriving Show | |
| value :: Thing a -> a | |
| value (Thing x) = x |
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
| split_int :: Int -> Int -> [[Int]] | |
| split_int n set_num = split_int_helper n set_num 1 | |
| split_int_helper n 1 _ = [[n]] | |
| split_int_helper n set_num start_idx = do | |
| let last_idx = truncate $ (fromIntegral n)/(fromIntegral set_num) | |
| x <- [start_idx..last_idx] | |
| y <- split_int_helper (n-x) (set_num-1) x | |
| return (x: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
| repApply :: (a->a)->a->[a] | |
| repApply f x = x : repApply f (f x) | |
| newton :: Int -> [Double] | |
| newton n = repApply (\x -> (x+(fromIntegral n)/x)/2) 1 |
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
| var power_set_generator = function(set) { | |
| var _index=0, _set=set, _max_size= 1<<set.length; | |
| return Object.create(Object.prototype, { | |
| next : { value : function() { | |
| var result = [], n=_index,i=0; | |
| if (_index >= _max_size) return; | |
| for (; n; n>>=1, i+=1) if (n & 1) result.push(_set[i]); | |
| _index+=1; | |
| return result; | |
| }} |