Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Haskell
Wiki community
Recent changes
Random page
HaskellWiki
Search
Search
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Euler problems/71 to 80
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Special pages
Page information
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== [http://projecteuler.net/index.php?section=view&id=74 Problem 74] == Determine the number of factorial chains that contain exactly sixty non-repeating terms. Solution: <haskell> import Data.List explode 0 = [] explode n = n `mod` 10 : explode (n `quot` 10) chain 2 = 1 chain 1 = 1 chain 145 = 1 chain 40585 = 1 chain 169 = 3 chain 363601 = 3 chain 1454 = 3 chain 871 = 2 chain 45361 = 2 chain 872 = 2 chain 45362 = 2 chain x = 1 + chain (sumFactDigits x) makeIncreas 1 minnum = [[a]|a<-[minnum..9]] makeIncreas digits minnum = [a:b|a<-[minnum ..9],b<-makeIncreas (digits-1) a] p74= sum[div p6 $countNum a| a<-tail$makeIncreas 6 1, let k=digitToN a, chain k==60 ] where p6=facts!! 6 sumFactDigits = foldl' (\a b -> a + facts !! b) 0 . explode factorial n = if n == 0 then 1 else n * factorial (n - 1) digitToN = foldl' (\a b -> 10*a + b) 0 .dropWhile (==0) facts = scanl (*) 1 [1..9] countNum xs=ys where ys=product$map (factorial.length)$group xs problem_74= length[k|k<-[1..9999],chain k==60]+p74 test = print $ [a|a<-tail$makeIncreas 6 0,let k=digitToN a,chain k==60] </haskell>
Summary:
Please note that all contributions to HaskellWiki are considered to be released under simple permissive license (see
HaskellWiki:Copyrights
for details). If you don't want your writing to be edited mercilessly and redistributed at will, then don't submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
DO NOT SUBMIT COPYRIGHTED WORK WITHOUT PERMISSION!
Cancel
Editing help
(opens in new window)
Toggle limited content width