Humble numbers: Difference between revisions

Content added Content deleted
m (added: where (Wikipedia) the 1st reference is from.)
(→‎{{header|Haskell}}: Added a first sketch in Haskell)
Line 656: Line 656:
693,065 have 70 digits
693,065 have 70 digits
</pre>
</pre>

=={{header|Haskell}}==
<lang haskell>import Data.Numbers.Primes (primeFactors)
import Control.Arrow ((&&&))
import Data.List (group)
import Data.Bool (bool)


----------------------HUMBLE NUMBERS-----------------------

humbles :: [Integer]
humbles = filter (all (< 8) . primeFactors) [1 ..]

---------------------------TEST----------------------------
main :: IO ()
main = do
putStrLn "First 50 Humble numbers:"
mapM_ (putStrLn . concat) $
chunksOf 10 $ (justifyRight 4 ' ' . show) <$> take 50 humbles
putStrLn "\nCount of humble numbers for each digit length 1-6:"
mapM_ print $ take 6 $ (head &&& length) <$> group (digitCount <$> humbles)

digitCount :: Integer -> Int
digitCount n =
let go x
| 10 > x = 1
| otherwise = succ (go (div x 10))
in go n

--------------------------DISPLAY--------------------------
chunksOf :: Int -> [a] -> [[a]]
chunksOf n xs =
foldr
(\(x, i) a -> bool (take n (drop i xs) : a) a (rem i n > 0))
[]
(zip xs [0 ..])

justifyRight :: Int -> a -> [a] -> [a]
justifyRight n c = (drop . length) <*> (replicate n c ++)</lang>
{{Out}}
<pre>First 50 Humble numbers:
1 2 3 4 5 6 7 8 9 10
12 14 15 16 18 20 21 24 25 27
28 30 32 35 36 40 42 45 48 49
50 54 56 60 63 64 70 72 75 80
81 84 90 96 98 100 105 108 112 120

Count of humble numbers for each digit length 1-6:
(1,9)
(2,36)
(3,95)
(4,197)
(5,356)
(6,579)</pre>



=={{header|Julia}}==
=={{header|Julia}}==