Skip to content

Instantly share code, notes, and snippets.

@motokiee
Created October 7, 2015 05:15
Show Gist options
  • Save motokiee/1590c9b8a4006c6c5090 to your computer and use it in GitHub Desktop.
Save motokiee/1590c9b8a4006c6c5090 to your computer and use it in GitHub Desktop.
コラッツ列とか #CodePiece
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