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
sumDouble = sum . map (*2) | |
sumDouble = foldl (+) 0 . map (*2) -- without sum |
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 scala.math.Numeric.Implicits._ | |
def doubleSum[T](s: Seq[T])(implicit n: Numeric[T]) = s.map (n.fromInt(2) * _) reduce (_ + _) |
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
module Diamond where (diamond) | |
import Data.List | |
diamond :: Int -> String | |
diamond h = concat . intersperse "\n" $ diamondTop ++ diamondBottom | |
where rows n = map row [((n - x) `div` 2, x) | x <- [1..n], odd x] | |
diamondTop = rows h | |
diamondBottom = drop 1 . reverse $ diamondTop |
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
int main(){ | |
int inputInt,oddRslt; | |
char awsr; | |
int checkNum(int inputInt); | |
int printDmd(int inputInt); | |
int repeat(char awsr); | |
int again=1; | |
/*main loop, loops entire program, ends on exit */ | |
while(again != 0){ |
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
// Curried aka (Int -> String -> String) | |
var times = function (n) { | |
//closure property allows us to access n inside the inner function | |
return function (x) { | |
//code isn't executed until all parameters are passed | |
var array = []; | |
for (var i in n) { | |
array[i] = x; | |
} | |
return array.reduce(function(a, e) { return a + e; }); |
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 scala.collection.mutable.{ Map => MMap } | |
import scala.util.parsing.combinator._ | |
class Config(s: Seq[(String, Any)] = Seq()) { | |
val config = MMap[String, Any](s: _*) | |
def apply(x: String) = config(x) | |
} | |
class ConfigError(message: String) extends Exception(message) { | |
override def toString = "Config Error: " + message |
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
/* Use this as our base */ | |
(.:?) :: (FromJSON a) => Object -> Text -> Parser (Maybe a) | |
obj .:? key = case M.lookup key obj of | |
Nothing -> pure Nothing | |
Just v -> parseJSON v | |
/* I'll look into it tomorrow */ |
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 java.io.File | |
import scala.io.Source | |
object CoffeeImport extends App { | |
try { | |
val result = args.toList match { | |
case Nil => throw new Exception("Please provide a filename: coffee-import <filename>") | |
case file :: Nil => resolve(file) | |
} | |
print(result) |
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
-- JRo | |
nPizza p s t = ceiling $ (/ s) $ if t `elem` [11..23] then p * 2 else p | |
-- dumb tests runTests will tell you weather you pass or fail all tests, could do a fold and keep the state of which failed. | |
between12am11am = 2 == (nPizza 10 5 0) && 1 == nPizza 10 10 1 && 1 == nPizza 7 12 10 | |
between11am11pm = 4 == (nPizza 20 10 11) && 2 == (nPizza 7 12 15) | |
after11pm = 1 == nPizza 5 10 23 |
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
module SleepyTime where | |
-- Check out System.Proccess to avoid using the tmp file. | |
import System.Cmd | |
import System.Exit (ExitCode(..)) | |
-- Find something lighter weight for the filtering. | |
import Text.Regex.TDFA | |
main :: IO () | |
main = do |
OlderNewer