Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,14 @@
import Data.Char (digitToInt)
import Data.Set (member, insert, empty)
isHappy :: Integer -> Bool
isHappy = p empty
where
p _ 1 = True
p s n
| n `member` s = False
| otherwise = p (insert n s) (f n)
f = sum . fmap ((^ 2) . toInteger . digitToInt) . show
main :: IO ()
main = mapM_ print $ take 8 $ filter isHappy [1 ..]

View file

@ -0,0 +1,19 @@
import Data.Array (Array, (!), listArray)
happy :: Int -> Bool
happy x
| xx <= 150 = seen ! xx
| otherwise = happy xx
where
xx = dsum x
seen :: Array Int Bool
seen =
listArray (1, 150) $ True : False : False : False : (happy <$> [5 .. 150])
dsum n
| n < 10 = n * n
| otherwise =
let (q, r) = n `divMod` 10
in r * r + dsum q
main :: IO ()
main = print $ sum $ take 10000 $ filter happy [1 ..]