192 is such a number, together with its double (384) and triple (576) they contain each 1-9 digit exactly once. Find all the numbers have this property.
No input.
Output:
192 384 576
219 438 657
273 546 819
327 654 981
192 219 273 327∘.×⍳3
Just prints the numbers multiplied by 1, 2, and 3.
{∧/1↓⎕D∊⍕k←⍵×⍳3:⎕←k}¨⍳400
1246`{[27*1131-..2*\3*]' '*n}/
(thanks to Howard for 31->30); or for a non-hard-coded approach, 33 32 (thanks again to Howard) chars:
333,{[..2*\3*]' '*}%{.&0-,9>},n*
If the output doesn't have to be character-for-character identical to the text in the question (i.e. if that is a sample), we can shorten to 27 chars:
[4.)7 9]{[27*84+..2*\3*]}%`
333,{[..2*\3*n]' '*..&0-,10>*}/
.
\$\endgroup\$
Here's a program that's slightly shorter than the trivial (just print the numbers) solution:
333,{4,(;{1$*}%\;.''*$10,0-''*={.p}*;}/
(thanks Howard & Peter)
v1:
333,{3,{)}%{1$*}%\;.''*$9,{)}%''*={p}{;}if}/
Online test here.
{p}{;}if
into {.p}*;
.
\$\endgroup\$
3,{)}%
-> 4,0-
and same with 9,{)}%
.
\$\endgroup\$
4,(;
, which would be more useful if the token following were a positive integer.
\$\endgroup\$
Mar 28, 2013 at 9:55
4,1>
which fulfills the same.
\$\endgroup\$
for i in range(328):
if`set(`i`+`i*2`+`i*3`)-{'0'}`[45:]:print i,i*2,i*3
192 384 576
219 438 657
273 546 819
327 654 981
repr()
. It's the shortest way i could think of to concatenate the numbers
\$\endgroup\$
[(i,2*i,3*i)|i<-[0..333],9==length(nub$show$1002003*i)]
Or 65 characters if it is to be compiled and not just interpreted:
main=print[(i,2*i,3*i)|i<-[0..333],9==length(nub$show$1002003*i)]
length(nub$show$1002003*i)
. Also, the use of $
to apply print
is redundant.
\$\endgroup\$
(99..999).map{|n|s=[n,2*n,3*n]*" ";s=~/(\d).*\1|0/||puts(s)}
Sample run:
bash-4.2$ ruby -e '(99..999).map{|n|s=[n,2*n,3*n]*" ";s=~/(\d).*\1|0/||puts(s)}'
192 384 576
219 438 657
273 546 819
327 654 981
String.Format("{0}{1}{2}",a,a*2,a*3).Length ==9 && String.String.Format("{0}{1}{2}",a,a*2,a*3).Distinct()==9;
192 219 273 327
would do. \$\endgroup\$192384576*3 = 577153728
which contains some digits twice and others not at all. \$\endgroup\$192
is such a number; together with its double (384
) and triple (576
) they contain each1-9
digit exactly once.. The current form is a bit misleading \$\endgroup\$