Colorful numbers: Difference between revisions

no edit summary
No edit summary
Line 34:
''Colorful numbers have no real number theory application. They are more a recreational math puzzle than a useful tool.''
 
=={{header|Haskell}}==
<lang haskell>import Data.List ( nub )
import Data.List.Split ( divvy )
import Data.Char ( digitToInt )
 
isColourful :: Integer -> Bool
isColourful n
|n >= 0 && n <= 10 = True
|n > 10 && n < 100 = ((length s) == (length $ nub s)) &&
(not $ any (\c -> elem c "01") s)
|n >= 100 = ((length s) == (length $ nub s)) && (not $ any (\c -> elem c "01") s)
&& ((length products) == (length $ nub products))
where
s :: String
s = show n
products :: [Int]
products = map (\p -> (digitToInt $ head p) * (digitToInt $ last p))
$ divvy 2 1 s
 
solution1 :: [Integer]
solution1 = filter isColourful [0 .. 100]
 
solution2 :: Integer
solution2 = head $ filter isColourful [98765432, 98765431 ..]</lang>
{{out}}
<pre>[0,1,2,3,4,5,6,7,8,9,10,23,24,25,26,27,28,29,32,34,35,36,37,38,39,42,43,45,46,47,48,49,52,53,54,56,57,58,59,62,63,64,65,67,68,69,72,73,74,75,76,78,79,82,83,84,85,86,87,89,92,93,94,95,96,97,98](solution1)
98765432(solution2)</pre>
 
=={{header|J}}==
2

edits