Colorful numbers: Difference between revisions

Add Factor
m (→‎{{header|Julia}}: mark incomplete)
(Add Factor)
Line 33:
 
''Colorful numbers have no real number theory application. They are more a recreational math puzzle than a useful tool.''
 
=={{header|Factor}}==
{{works with|Factor|0.99 2021-06-02}}
<lang factor>USING: assocs grouping grouping.extras io kernel literals math
math.combinatorics math.ranges prettyprint project-euler.common
sequences sequences.extras sets ;
 
CONSTANT: digits $[ 2 9 [a..b] ]
 
: (colorful?) ( seq -- ? )
all-subseqs [ product ] map all-unique? ;
 
: colorful? ( n -- ? )
[ t ] [ number>digits (colorful?) ] if-zero ;
 
: table. ( seq cols -- )
[ "" pad-groups ] keep group simple-table. ;
 
: (oom-count) ( n -- count )
digits swap <k-permutations> [ (colorful?) ] count ;
 
: oom-count ( n -- count )
dup 1 = [ drop 10 ] [ (oom-count) ] if ;
 
"Colorful numbers under 100:" print
100 <iota> [ colorful? ] filter 10 table. nl
 
"Largest colorful number:" print
digits <permutations> [ (colorful?) ] find-last nip digits>number . nl
 
"Count of colorful numbers by number of digits:" print
8 [1..b] [ oom-count ] zip-with dup .
"Total: " write values sum .</lang>
{{out}}
<pre>
Colorful numbers under 100:
0 1 2 3 4 5 6 7 8 9
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
 
Largest colorful number:
98746253
 
Count of colorful numbers by number of digits:
{
{ 1 10 }
{ 2 56 }
{ 3 328 }
{ 4 1540 }
{ 5 5514 }
{ 6 13956 }
{ 7 21596 }
{ 8 14256 }
}
Total: 57256
</pre>
 
=={{header|Haskell}}==
1,808

edits