Created
October 7, 2015 05:15
-
-
Save motokiee/1590c9b8a4006c6c5090 to your computer and use it in GitHub Desktop.
コラッツ列とか #CodePiece
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
quicksort :: (Ord a) => [a] -> [a] | |
quicksort [] = [] | |
quicksort (x:xs) = | |
let smallOrEqual = filter (<= x) xs | |
larger = filter (> x) xs | |
in quicksort smallOrEqual ++ [x] ++ quicksort larger | |
largestDivisible :: [Int] -> Bool | |
largestDivisible [] = False | |
largestDivisible (x:xs) | |
| (x `mod` 3829) == 0 = True | |
| otherwise = largestDivisible xs | |
largest2829 :: Integer | |
largest2829 = head (filter p [100000,99999..]) | |
where p x = (x `mod` 2829) == 0 | |
chain :: Integer -> [Integer] | |
chain 1 = [1] | |
chain n | |
| even n = n : chain (n `div` 2) | |
| odd n = n : chain (n * 3 + 1) | |
calcChain :: Int | |
calcChain = length (filter isLong (map chain [1..100])) | |
where isLong x = length x > 15 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment