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
package com.thoughtworks.futureeither | |
import concurrent.{Await, Future} | |
import scala.concurrent.ExecutionContext.Implicits.global | |
import concurrent.duration.FiniteDuration | |
import java.util.concurrent.TimeUnit | |
class FutureEither[L, R](private val future: Future[Either[L, R]]) { | |
def flatMap[R2](block: R => FutureEither[L, R2]): FutureEither[L, R2] = { |
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 GroupSort ( | |
groupsort | |
) where | |
groupsort :: Ord a => [a] -> [a] | |
groupsort [] = [] | |
groupsort xs = let | |
groups = group xs | |
n = length xs | |
k = length groups |
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 Snippet where | |
import Data.List | |
compress :: String -> String | |
compress = (foldl1 (++)) . (foldl (\acc xs -> acc ++ [(show.length) xs, (head xs):[]]) []) . group | |
compressions :: String -> [String] | |
compressions x = let n = compress x in n:compressions 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
module PrimeFactorization where | |
import Data.List | |
primeFactorsOf :: Int -> [Int] | |
primeFactorsOf n = (nub . unfoldr (2 `factorOutOf`)) n | |
where k `factorOutOf` n | |
| n < 2 = Nothing | |
| n `mod` k == 0 = Just (k, n `div` k) | |
| otherwise = (k+1) `factorOutOf` 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
module Primes where | |
main :: IO () | |
main = print $ take 1000 primes | |
(√) :: Int -> Int | |
(√) = floor . sqrt . fromIntegral | |
primes :: [Int] | |
primes = 2 : sieve [3, 5..] |
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
package com.jnape.dynamiccollection; | |
import com.jnape.dynamiccollection.lambda.Function; | |
import com.jnape.dynamiccollection.list.CachingStream; | |
import com.jnape.dynamiccollection.list.DynamicList; | |
import com.jnape.dynamiccollection.list.Stream; | |
import static com.jnape.dynamiccollection.lambda.library.numeric.accumulator.Add.add; | |
import static com.jnape.dynamiccollection.list.NumericDynamicArrayList.numbers; |
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 Euler3 where | |
{- | |
The prime factors of 13195 are 5, 7, 13 and 29. | |
What is the largest prime factor of the number 600851475143 ? | |
-} | |
factorOf :: Int -> Int -> Bool | |
a `factorOf` b = rem b a == 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
module Euler2 where | |
{- | |
Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be: | |
1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ... | |
By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms. | |
-} |
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 Euler1 where | |
{- | |
If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. | |
Find the sum of all the multiples of 3 or 5 below 1000. | |
-} | |
import Data.List (nub) |
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 Example ( | |
(∆) | |
) where | |
unique :: (Eq a) => [a] -> [a] | |
unique [] = [] | |
unique (x:xs) = x:(unique (filter (/= x) xs)) | |
without :: (Eq a) => [a] -> [a] -> [a] | |
xs `without` ys = [ x | x <- xs, not (x `elem` ys)] |