4
\$\begingroup\$

Task

Your task is to output a single integer, with one restriction: its digits must be a permutation of [1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6].

For example, you could output 653443653152432, 413265345463352, or any of the other 15-digit integers whose digits are a permutation of the list.

Rules

  • Your code must terminate in a reasonable amount of time (do not just enumerate every integer until you get to 122333344455566).

  • If your language doesn't support 15-digit integers, or if there is no meaningful distinction between strings and integers in your language, you may output a string.

  • This is , shortest answer in bytes wins.

\$\endgroup\$
  • 1
    \$\begingroup\$ What's to stop me simply outputting 653443653152432? \$\endgroup\$ – caird coinheringaahing Oct 22 '17 at 19:52
  • 2
    \$\begingroup\$ Because you could do it in fewer bytes than just writing out the integer. \$\endgroup\$ – Ethan Ward Oct 22 '17 at 19:54
  • \$\begingroup\$ Would be more interesting if we had to a random one of all the permutations, with equal chance for each. \$\endgroup\$ – Adám Oct 22 '17 at 20:00
  • 10
    \$\begingroup\$ I suspect that you found some short expression that gives a number with the right digits before posting this. I'd suggest against such puzzles. It's more about finding the expression you had in mind that golfing code, and once someone has the expression, probably everyone can copy it into other languages. \$\endgroup\$ – xnor Oct 22 '17 at 20:21
  • 6
    \$\begingroup\$ @xnor I personally think that this challenge is underrated. If I did my math correctly, there are 378,378,000 possible outcomes. Even if the OP found a terse expression for one of them, it is quite possible that a shorter one exists for another permutation. \$\endgroup\$ – Arnauld Oct 23 '17 at 0:38

17 Answers 17

12
\$\begingroup\$

JavaScript (ES7), 13 12 bytes

let f =

_=>266**6+19

console.log(f())

This computes: 2666 + 19 = 354233654641216 + 19 = 354233654641235

There are two triples (a, b, c) with 0 < a < 1000, 0 < b < 10, 0 < c < 100 and ab + c satisfying the condition.

The following snippet finds them almost instantly.

for(a = 1; a < 1000; a++) {
  for(b = 1; b < 10; b++) {
    for(c = 1; c < 100; c++) {
      if((r = a**b + c + '').match(/^[1-6]+$/) && [...r].sort().join`` == '122333344455566') {
        console.log(a + '**' + b + ' + ' + c + ' = ' + r);
      }
    }
  }
}

|improve this answer|||||
\$\endgroup\$
5
\$\begingroup\$

Brain-Flak, 65 bytes

(((((((((((((((((((()()()){}){}){}){}())()))()))))())))())))()))

Try it online!

This is 64 bytes of source code and +1 for the -A flag. This simply pushes the ASCII values of each digit in a row. For reference, pushing the number 122333344455566 would take 238 bytes:

(((((((((((((((((((((((((((((((((((((((((((((((((()()()){}){}){})()){}{}){({}[()])}{}){}){}())){}{})){}{}){}())){}{})()){}{})){}{}){}())){}{}){}())){}{}){}())()){}{})()){}{})){}{})()){}{})()){}{})){}{}){}())){}{}){}())){}{})){}{}){}()){})

Try it online!

|improve this answer|||||
\$\endgroup\$
3
\$\begingroup\$

V, 12, 10 bytes

2¬26¬35a13

Try it online!

This generates the range [2, 6] twice, then the range [3, 5], and then appends 13.

Outputs:

234562345634513
|improve this answer|||||
\$\endgroup\$
2
\$\begingroup\$

Turing machine, 132 122 bytes

...and 11 10 8 7 states, including halt.

0 _ x r A
0 x y r A
0 y z r A
0 z _ r C
0 * * l 0
A _ 6 r B
A * * r A
B _ 2 r C
C * 3 r D
D _ 4 r E
D 2 1 l halt
E _ 5 l 0

Here is a Turing machine simulator that understands this syntax. You should paste the code, clear the "Initial input" field, press Reset, then press Run.

How it works

Outputs 313456234562345 by looping to write 62345 three times and then writing 31 on top of the initial 62.


-10 bytes thanks to @Leo

|improve this answer|||||
\$\endgroup\$
1
\$\begingroup\$

Jelly, 9 8 bytes

“|BS½GA’

Try it online!

Simply a base-250 compressed version of the number 122333344455566

Saved 1 byte thanks to @Mr. Xcoder

|improve this answer|||||
\$\endgroup\$
  • \$\begingroup\$ 8 bytes: “|BS½GA’ \$\endgroup\$ – Mr. Xcoder Oct 22 '17 at 20:00
  • \$\begingroup\$ @Mr.Xcoder why didn't I try that one first? :P Thanks \$\endgroup\$ – caird coinheringaahing Oct 22 '17 at 20:02
1
\$\begingroup\$

SOGL V0.12, 7 bytes

↓čvν□⅟“

Try it Here!
A simple compressed number.

Alternate 9 byte run-length version:

Ƨ≡+‰“7─◄H

Try it Here!

|improve this answer|||||
\$\endgroup\$
1
\$\begingroup\$

brainfuck, 40 bytes

+++++++[>+++++++<-]>.+..+....+...+...+..

Try it online!

fairly boring solution

|improve this answer|||||
\$\endgroup\$
1
\$\begingroup\$

05AB1E, 7 bytes

•=["∊…Q

Try it online!

|improve this answer|||||
\$\endgroup\$
  • \$\begingroup\$ 1243ƶ would've been cool if there were 5 and 6 times a number. \$\endgroup\$ – Magic Octopus Urn Oct 24 '17 at 16:30
1
\$\begingroup\$

Befunge-93, 16 14 or 12 bytes

The only native integer literals supported by Befunge are the numbers 0 to 9, so coming up with an efficient representation for larger values is actually quite a common problem. In this case, though, it's not just a matter of finding the most efficient representation for a number, but also choosing a target number whose best representation is the shortest of all possible targets.

After trying thousands of different combinations, the best I've been able to do so far is 14 bytes (12 to calculate the number, and then two more bytes to output it).

m&"7*:*::**+.@

Try it online!

If we allow extended ASCII characters, though, we can improve on the above solution by two bytes with:

eûãÃ"**:*+.@

This is using the Latin-1 encoding, which we unfortunately can't demonstrate on TIO, since it doesn't support 8-byte encodings for the Befunge interpreters.

Explanation

In the first answer, we start with the string "m&", which essentially pushes the values 109 and 38 onto the stack. Note that we save a byte by dropping the opening quote, since we can rely on Befunge's wrap-around playfield to have the one quote both open and close the string (this pushes a number of additional values onto the stack that we don't need, but we only care about the final two).

We then push an additional 7 onto the stack, and execute the sequence *:*::**+, which performs a set of arithmetic calculations with the stack values, essentially calculating the expression:

109+(38*7)^2^3 = 354233654641325

Finally we use the . instruction to output the result of the calculation, and then the @ instruction ends the program.

In the second answer, we start with the string "eûãÃ", which pushes the values 101, 251, 227 and 195. We then execute the sequence **:*+, which performs the required calculations on those values:

101+(251*227*195)^2 = 123443543565326

And again we finish with the instructions . and @ to output the result and exit.

Note that in both cases you need to be using an interpreter which supports 64-bit integers. Also note that the string wrapping trick won't work on Befunge-98 interpreters, since it relies on the interpreter ignoring instructions it doesn't recognise, but in Befunge-98 an invalid instruction will reflect.

|improve this answer|||||
\$\endgroup\$
0
\$\begingroup\$

Python 2, 21 bytes

print 122333344455566

Try it online!

|improve this answer|||||
\$\endgroup\$
  • 2
    \$\begingroup\$ print 0x6f42f38a5b8e \$\endgroup\$ – Erik the Outgolfer Oct 22 '17 at 21:04
0
\$\begingroup\$

Jelly, 12 bytes

4967b5Ėẋ/€FḌ

Try it online!

could probably be shorter

|improve this answer|||||
\$\endgroup\$
0
\$\begingroup\$

Pyth, 9 bytes

."16U<³

Try it here!

Output:

223133344455566
|improve this answer|||||
\$\endgroup\$
0
\$\begingroup\$

Tcl, 89 bytes

proc f a\ b {expr rand()>.5}
puts [join [lsort -command f [split 122333344455566 ""]] ""]

Try it online!

|improve this answer|||||
\$\endgroup\$
0
\$\begingroup\$

Tcl, 20 bytes

puts 122333344455566

Try it online!

|improve this answer|||||
\$\endgroup\$
0
\$\begingroup\$

Befunge-98 (FBBI), 20 bytes

"ek,@122333344455566

Try it online!

Output is 665554443333221.

|improve this answer|||||
\$\endgroup\$
0
\$\begingroup\$

Groovy, 23 bytes

{"233456"​​​​​*2+145​}​

Outputs: 233456233456145

|improve this answer|||||
\$\endgroup\$
0
\$\begingroup\$

APL (Dyalog Unicode), 14 bytes

⎕pp←30
37+266*6

Try it online!

Used @Arnauld's snippet, so credit goes to them.

|improve this answer|||||
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.