5
\$\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\$
9
  • 1
    \$\begingroup\$ What's to stop me simply outputting 653443653152432? \$\endgroup\$ Oct 22, 2017 at 19:52
  • 2
    \$\begingroup\$ Because you could do it in fewer bytes than just writing out the integer. \$\endgroup\$
    – Ethan Ward
    Oct 22, 2017 at 19:54
  • 1
    \$\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, 2017 at 20:00
  • 11
    \$\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, 2017 at 20:21
  • 8
    \$\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, 2017 at 0:38

22 Answers 22

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);
      }
    }
  }
}

\$\endgroup\$
1
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!

\$\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
\$\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

\$\endgroup\$
0
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

\$\endgroup\$
2
  • \$\begingroup\$ 8 bytes: “|BS½GA’ \$\endgroup\$
    – Mr. Xcoder
    Oct 22, 2017 at 20:00
  • \$\begingroup\$ @Mr.Xcoder why didn't I try that one first? :P Thanks \$\endgroup\$ Oct 22, 2017 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!

\$\endgroup\$
1
\$\begingroup\$

brainfuck, 40 bytes

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

Try it online!

fairly boring solution

\$\endgroup\$
1
\$\begingroup\$

05AB1E, 7 bytes

•=["∊…Q

Try it online!

\$\endgroup\$
1
  • \$\begingroup\$ 1243ƶ would've been cool if there were 5 and 6 times a number. \$\endgroup\$ Oct 24, 2017 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.

\$\endgroup\$
1
\$\begingroup\$

Vyxal, 7 bytes

»Ċ¨?»²›

Try it Online!

Port of the second answer here
Explanation:

»Ċ¨?»   # Compressed integer 11972312
     ²  # Squared
      › # Increment

I was on my way to making a super short one but I had read the rules wrong :(

\$\endgroup\$
0
\$\begingroup\$

Python 2, 21 bytes

print 122333344455566

Try it online!

\$\endgroup\$
1
  • 3
    \$\begingroup\$ print 0x6f42f38a5b8e \$\endgroup\$ Oct 22, 2017 at 21:04
0
\$\begingroup\$

Jelly, 12 bytes

4967b5Ėẋ/€FḌ

Try it online!

could probably be shorter

\$\endgroup\$
0
\$\begingroup\$

Pyth, 9 bytes

."16U<³

Try it here!

Output:

223133344455566
\$\endgroup\$
0
\$\begingroup\$

Tcl, 89 bytes

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

Try it online!

\$\endgroup\$
0
\$\begingroup\$

Tcl, 20 bytes

puts 122333344455566

Try it online!

\$\endgroup\$
0
\$\begingroup\$

Befunge-98 (FBBI), 20 bytes

"ek,@122333344455566

Try it online!

Output is 665554443333221.

\$\endgroup\$
0
\$\begingroup\$

Groovy, 23 bytes

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

Outputs: 233456233456145

\$\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.

\$\endgroup\$
0
\$\begingroup\$

C++, 24 bytes

[]{return(57LL<<41)-31;}

Try it online!

Returns 57×241−31 = 125344325566433.

\$\endgroup\$
0
\$\begingroup\$

ARM T32 machine code, 8 bytes

20d5 f24e 6157 4770

Following the AAPCS, this is a function returning a 64-bit integer in r0 and r1. The number is 58967×232+213=253261336543445.

Disassembled:

20d5        movs    r0, #213
f24e 6157   movw    r1, #58967
4770        bx  lr
\$\endgroup\$
0
\$\begingroup\$

A0A0, 16 bytes

O122333344455566

O outputs the number after it. The number after it is a valid integer.

I don't really think it's possible to save bytes by using some arithmetic expression. When multiplying two numbers of n and m digits, the resulting length of the multiplication will be at most n + m. Doing such a multiplication requires at least n + m + 2 (ignoring the operand) bytes, at which point you might as well just write the result directly. Addition is even worse in terms of length. Considering multiplication, addition and subtraction are the only built-in operators I find it hard to believe this can be shortened. I'd love to be proven wrong, though.

\$\endgroup\$
0
\$\begingroup\$

x86 32-bit machine code, 9 bytes

6A 85 58 BA 4F C9 00 00 C3

Returns a 64-bit integer in EDX and EAX, as is standard. The value is 51536×232−123 = 221345434566533.

Try it online!

In assembly:

f:  push -123; pop eax
    mov edx, 51535
    ret

Some alternatives that also take 9 bytes:


B8 D8 AE B6 00 F7 E0 40 C3

Try it online!

f:  mov eax, 11972312
    mul eax
    inc eax
    ret

119723122+1 = 143336254625343


6A E1 58 0F B6 D4 B6 71 C3

Try it online!

f:  push -31; pop eax
    movzx edx, ah
    mov dh, 113
    ret

114×240−31 = 125344325566433

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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