1
0
Fork 0

Compare commits

..

No commits in common. "baf8ad2559f1b2e4fbe0e0970351927ae74020f5" and "b0e3c4a87d7f7813bb2b01484cb4e6950071e1a2" have entirely different histories.

4 changed files with 2 additions and 88 deletions

View File

@ -1,47 +0,0 @@
import Control.Monad ()
import Debug.Trace (trace)
f' :: Integer -> Integer
f' n = f'' 0 n
where
f'' :: Integer -> Integer -> Integer
f'' i n'
| n' == 1 = t' i
| even n' = t $ f'' (i + 1) (n' `div` 2)
| odd n' = t $ f'' (i + 1) (3*n' + 1)
where t = trace ("i: " ++ show i ++ ", number: " ++ show n')
t' = t'' $ trace ("END: " ++ show n ++ ", length: " <> show i) $ t''
t'' = trace "\n#######################################################\n"
f :: Integer -> Integer
f n = s 0 n
where
s :: Integer -> Integer -> Integer
s i n
| n == 1 = i
| even n = s i' (n `div` 2)
| odd n = s i' (3*n + 1)
where i' = i + 1
main :: IO ()
main = print $ map f [2^361..]
-- collatz collect
-- generate the collatz sequence and return it
cc :: Integer -> [Integer]
cc n = cc' [] n
where
cc' :: [Integer] -> Integer -> [Integer]
cc' acc n
| n == 1 = 1:acc
| even n = cc' acc' (n `div` 2)
| odd n = cc' acc' (3*n + 1)
where acc' = acc <> [n]
primes :: [Integer]
primes = sieve [2..]
where
sieve (p:xs) = p : sieve [x|x <- xs, x `mod` p > 0]
isPrime k = (k > 1) && null [ x | x <- [2..k - 1], k `mod` x == 0]

View File

@ -13,9 +13,6 @@ main = print ans
ans :: Integer
ans = sum $ allNumbersUnder 1000
sum' :: Num a => [a] -> a
sum' = foldl (+) 0
isMultipleOf :: Integral a => a -> a -> Bool
isMultipleOf n x = x `rem` n == 0

View File

@ -14,31 +14,10 @@ main = print ans
ans = 42
limit = 2
points = [ (x,y)
| x <- [0..limit]
, y <- [0..limit]
]
limit = 20
points = [(x,y) | x <- [1..limit], y <- [1..limit]]
data Direction = Right | Down
move Right (x,y) = (x+1, y )
move Down (x,y) = (x , y+1)
-- solve :: (Int, Int) -> [[(Int, Int)]]
{-
λ> [(0,0)]
[(0,0)]
λ> [(0,0),(1,0),(2,0),(2,1),(2,2)]
[(0,0),(1,0),(2,0),(2,1),(2,2)]
λ> [ [(0,0),(1,0),(2,0),(2,1),(2,2)], [(0,0),(1,0),(1,1),(2,1),(2,2)]]
[[(0,0),(1,0),(2,0),(2,1),(2,2)],[(0,0),(1,0),(1,1),(2,1),(2,2)]]
λ>
-}
data Tree a
= Leaf a
| Branch (Tree a) (Tree a)
deriving (Show)

View File

@ -1,15 +0,0 @@
{-
https://projecteuler.net/problem=16
2^15 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26.
What is the sum of the digits of the number 2^1000?
-}
module Main where
main :: IO ()
main = print ans
ans :: Integer
ans = sum $ map (\c -> read [c] :: Integer) $ show (2^1000)