Last active
December 12, 2019 08:21
-
-
Save yasar11732/5c32906c38a5dcae174ee81557b1a408 to your computer and use it in GitHub Desktop.
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 Data.List | |
| fun1 :: [Integer] -> Integer | |
| fun1 = product . map (subtract 2) . filter even | |
| fun2' :: Integer -> Integer | |
| fun2' 1 = 0 | |
| fun2' n | even n = n + fun2' (n `div` 2) | |
| | otherwise = fun2' (3 * n + 1) | |
| collatzNext n | even n = n `div` 2 | |
| | otherwise = 3 * n + 1 | |
| fun2 :: Integer -> Integer | |
| fun2 = sum . filter even . takeWhile (>1) . iterate collatzNext | |
| xor' :: Bool -> Bool -> Bool | |
| xor' prev next | next = not prev | |
| | otherwise = prev | |
| xor :: [Bool] -> Bool | |
| xor n = foldl xor' False n | |
| map' :: (a -> b) -> [a] -> [b] | |
| map' f = foldr (\x y -> (f x):y) [] | |
| toBeCrossed n = sort $ filter (<= n) [i + j + 2*i*j | j <- [1..n], i <- [1..j]] | |
| remove [] _ = [] | |
| remove n [] = n | |
| remove (x:xs) (y:ys) | x < y = [x] ++ remove xs (y:ys) | |
| | x == y = remove xs (y:ys) | |
| | otherwise = remove (x:xs) (ys) | |
| sieveOfSundaram :: Integer -> [Integer] | |
| sieveOfSundaram n = let z = toBeCrossed n | |
| in map (\x -> 2*x + 1) . remove [1..n] $ z | |
| main = putStrLn "ok" |
yasar11732
commented
Dec 12, 2019
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment