# Find all the numbers have this property, its double and its triple contain each digit from 1 to 9 exactly once

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

• The problem with golfing this kind of problems is that they don't need a real program. Just printing 192 219 273 327 would do. – Dr. belisarius Mar 28 '13 at 6:23
• 192384576*3 = 577153728 which contains some digits twice and others not at all. – Peter Taylor Mar 28 '13 at 7:42
• I think you should rephrase to question to something like: 192 is such a number; together with its double (384) and triple (576) they contain each 1-9 digit exactly once.. The current form is a bit misleading – Cristian Lupascu Mar 28 '13 at 8:10

## GolfScript (31 30 chars)

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*]}%

• You may save a char and omit the back tick – Howard Mar 28 '13 at 9:33
• And even shorten it to 31: 333,{[..2*\3*n]' '*..&0-,10>*}/. – Howard Mar 28 '13 at 9:40
• @Howard, my current understanding of the question is that it's a Kolmogorov-complexity one: reproduce the exact string. Your 31-char solution would add trailing spaces to the lines. If we remove the exact string restriction then there are certainly places that savings can be made. – Peter Taylor Mar 28 '13 at 9:44
• I didn't read that in the specification - only to somehow have the correct output format. You may be right, but the formulation simply doesn't read reproduce the exact string to me. – Howard Mar 28 '13 at 9:49
• Following your argument you must recall one of your first two solutions: one has a trailing newline and one hasn't ;-) – Howard Mar 28 '13 at 9:58

## APL (20)

192 219 273 327∘.×⍳3


Just prints the numbers multiplied by 1, 2, and 3.

## Without hardcoding (25)

{∧/1↓⎕D∊⍕k←⍵×⍳3:⎕←k}¨⍳400

• I don't know APL... can you take advantage of the fact that 192 and 273 can be rotated 1 to the right to obtain 219 and 327 respectively? – boothby Mar 30 '13 at 4:34
• odd... that holds for all numbers of both sequences – boothby Mar 30 '13 at 4:41
• @boothby: You're thinking like an APL programmer, but unfortunately, in this case that would be longer than just writing them out, especially since the rotation itself isn't constant. – marinus Apr 2 '13 at 8:27
• What do you mean the rotation isn't constant? – boothby Apr 2 '13 at 17:05

### GolfScript 44 39

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.

• In your case you can shorten {p}{;}if into {.p}*;. – Howard Mar 28 '13 at 9:43
• And two others: 3,{)}% -> 4,0- and same with 9,{)}%. – Howard Mar 28 '13 at 9:52
• Or 4,(;, which would be more useful if the token following were a positive integer. – Peter Taylor Mar 28 '13 at 9:55
• Or of course 4,1> which fulfills the same. – Howard Mar 28 '13 at 10:02

# Python: 8477 73 characters

for i in range(328):
ifset(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

• That's some fine golfing, my friend. I do not understand how python parses those backticks... – boothby Mar 30 '13 at 4:52
• @boothby Nobody ever uses them since they were a bad idea in the first place but all they do is call repr(). It's the shortest way i could think of to concatenate the numbers – jamylak Mar 30 '13 at 6:13
• Oh, backticks are a good idea and quite familiar. But... the way you've nested them is just evil. – boothby Mar 30 '13 at 6:21

[(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)]

• Save 1 by moving the parenthesis to length(nub$show$1002003*i). Also, the use of $ to apply print is redundant. – hammar Apr 6 '13 at 18:10 # Ruby: 7665 60 characters (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

• In this case \$_=[n,2*n,3*n]*" " is much shorter. – Howard Mar 28 '13 at 18:11
• Another one: put the no-zero part into the first regex: /(\d).*\1|0/. – Howard Mar 29 '13 at 7:41

### C#, 109 characters

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;

• Welcome to Programming Puzzles & Code Golf, @ZafarYousafi. Please note that code golf is a challenge of writing the shortest code possible. That means, here we write unindented and almost unreadable code and force the limits of the language syntax to shorten our codes as possible. – manatwork Apr 1 '13 at 11:59