Positional Awareness

10

Positional Awareness

Your task is to generate a program that, for every permutation of its characters (which includes the original program), outputs the positions of every character relative to the original program.

If your program is

Derp

you must output

[0, 1, 2, 3]

(or some equivalent). This is because D is in the 0th position, e is in the 1st, r the 2nd, and p the 3rd.

Let's take another program which is the original program, but with its characters permuted:

epDr

You must output

[1, 3, 0, 2]

because e is in the 1st position of the original program, p is in the 3rd position, D the 0th, and r the 2nd.

If the original program has two repeating characters:

abcda -> [0, 1, 2, 3, 4]

Then for the permutation, the 0 and the 4 in the array must be in ascending order:

baadc -> [1, 0, 4, 3, 2] (0 first, then 4)

Rules:

  • Your program must contain at least two unique characters.
  • At most floor(n/2) characters are to be the same.

     aabb (acceptable)
     aaaabc (not acceptable, only floor(6/2) = 3 a's allowed)
    
  • Your program's output can be either an array (or something similar) containing all the characters' positions in order, or a string with any delimiter, so these are perfectly fine:

    [0, 1, 2, 3]
    0,1,2,3
    0 1 2 3
    

clismique

Posted 2016-12-21T05:29:26.353

Reputation: 6 600

7I don't believe this challenge allows for any non-trivial solution as virtually any answer in any language of length >= ~5 will not be a valid program for every permutation, let alone a program that solves the challenge at hand. – orlp – 2016-12-21T05:32:01.683

@orlp What if I reduce it to one permutation? This didn't come up in the sandbox at all, so I didn't realise the problem. I expected this challenge would be like the "Hyperprogramming" one (which was possible), but I guess I'm wrong. – clismique – 2016-12-21T05:35:09.583

1@Qwerp-Derp Almost nobody says anything on the sandbox. A while ago, I've posted a question after being in the sandbox for around a month (or so). And only when I've posted it, was when people pointed out mistakes and the downvotes rained. In my honest opinion, the sandbox is useless. – Ismael Miguel – 2016-12-21T10:33:46.080

1For once, I feel like in this challenge, a longer answer would be more impressive than a shorter one. – Wojowu – 2016-12-21T13:05:24.553

1@Wojowu I can make it [tag:code-bowling], if that's possible - the longest program wins. – clismique – 2016-12-21T14:02:10.303

1Would the program 12 in R be valid? It would simply print 12 and if permuted; 21. – Billywob – 2016-12-21T14:48:43.523

@JamesHolderness I think this might warrant a new question, perhaps with a different criterion than this one. I'll come up with something. – clismique – 2016-12-22T12:11:43.260

Answers

21

Actually, 2 bytes

10

Try it online!

This prints

0
1

while the (only) other permutation

01

prints

1
0

How it works

In Actually, consecutive digits are parsed separately, so 10 pushes 1 on the stack, then 0 on top of it.

When the program finishes, the stack is printed top to bottom, so it prints 0 first, then a linefeed, then 1.

The derranged program 01 does the same, in the opposite order.

Dennis

Posted 2016-12-21T05:29:26.353

Reputation: 196 637

1Other languages this works in; Seriously, 05ab1e, ///, 2sable. – Teal pelican – 2016-12-21T11:30:00.423

The spec says the numbers have to be separated. It does work in Seriously, but Actually is actually just Seriously 2.0. – Dennis – 2016-12-21T11:32:11.047

7

Jelly, 2 bytes

;J

Try it online!

Outputs: [0, 1]

Other permutation J; outputs: [1, 0]

How it works:

;J
;          Concats 0 with...
 J         [1...len(z)], here just [1]

J;
J          [1...len(z)], here just [1]
 ;         ...Concatted with 0

milk

Posted 2016-12-21T05:29:26.353

Reputation: 3 043