Brilliant numbers: Difference between revisions

→‎{{header|Haskell}}: Added a draft solution in Haskell
m (C++ - increase limit to 10^17)
(→‎{{header|Haskell}}: Added a draft solution in Haskell)
Line 437:
First >= 10,000,000,000,000 is 34,896,253,010 in the series: 10,000,000,000,073
</pre>
 
=={{header|Haskell}}==
<lang haskell>import Control.Monad (join)
import Data.Bifunctor (bimap)
import Data.List (intercalate, transpose)
import Data.List.Split (chunksOf, splitWhen)
import Data.Numbers.Primes (primeFactors)
import Text.Printf (printf)
 
-------------------- BRILLIANT NUMBERS -------------------
 
isBrilliant :: (Integral a, Show a) => a -> Bool
isBrilliant n = case primeFactors n of
[a, b] ->
n == (a * b)
&& length (show a) == length (show b)
_ -> False
 
--------------------------- TEST -------------------------
main = do
let brilliants = filter isBrilliant [1 ..]
indexedBrilliants = zip [1 ..] brilliants
putStrLn $
table " " $
chunksOf 10 $
show
<$> take 100 brilliants
 
putStrLn "(index, brilliant)"
mapM_ print $
fmap (fst . head) $
take 6 $
splitWhen
(uncurry (<) . join bimap (length . show . snd))
$ zip indexedBrilliants (tail indexedBrilliants)
 
----------------------- DISPLAY ------------------------
 
table :: String -> [[String]] -> String
table gap rows =
let ws = maximum . fmap length <$> transpose rows
pw = printf . flip intercalate ["%", "s"] . show
in unlines $ intercalate gap . zipWith pw ws <$> rows</lang>
{{Out}}
<pre> 4 6 9 10 14 15 21 25 35 49
121 143 169 187 209 221 247 253 289 299
319 323 341 361 377 391 403 407 437 451
473 481 493 517 527 529 533 551 559 583
589 611 629 649 667 671 689 697 703 713
731 737 767 779 781 793 799 803 817 841
851 869 871 893 899 901 913 923 943 949
961 979 989 1003 1007 1027 1037 1067 1073 1079
1081 1121 1139 1147 1157 1159 1189 1207 1219 1241
1247 1261 1271 1273 1333 1343 1349 1357 1363 1369
 
(index, brilliant)
(1,4)
(4,10)
(11,121)
(74,1003)
(242,10201)
(2505,100013)</pre>
 
 
=={{header|J}}==
9,655

edits