Talk:Factors of an integer: Difference between revisions

Perhaps a narrower layout for readability of the 97 char Haskell line ?
(Perhaps a narrower layout for readability of the 97 char Haskell line ?)
Line 35:
"q" is a literate wrapper for "k" so I provided that to make it clearer what the code is doing
<lang K>q) f:{i:{y where x=y*x div y}[x ; 1+ til floor sqrt x]; distinct i,x div reverse i}</lang>
 
== Formatting very wide Haskell lines ==
 
Very nice final list comprehension example there. Thanks !
 
Perhaps [[Johan Tibell style|https://github.com/tibbe/haskell-style-guide]] or [[hindent|http://chrisdone.com/posts/hindent-5]] to bring the 97-character withing the 80 character Rosetta guidelines, and for ease of reading ? (PS maybe the Data.List import is not needed with current default builds of GHC ? Those functions all seem to be Prelude default)
 
<lang haskell>factors_o :: Integral a => a -> [a]
factors_o n =
ds ++
[ r
| (d, 0) <- [divMod n r]
, r <-
r :
[ d
| d > r ] ] ++
reverse (map (n `div`) ds)
where
r = floor (sqrt (fromIntegral n))
ds =
[ i
| i <- [1 .. r - 1]
, mod n i == 0 ]</lang>
9,655

edits