# Find my other token (Cops)

Cops,

Choose two strings of code, one public and one secret. We will call them P and S. You will be writing a program using only repetitions of these strings.

For example: if you choose P=helloand S=world, valid programs would be hello, world, helloworld, worldhello, helloworldworldhello, hellohellohelloworld, etc. You are not allowed to add anything else to your code or modify these strings, so hello world, HelloWorld, heellowoorld and elloword would all be invalid programs.

### The program

Using only strings P and S, write a program which takes a list of 5 or more non-repeating positive integers, and returns them reordered such that the maximum of the list is in the center, the elements before it are in ascending order, and the elements after it are in descending order. You can output any list that meets these requirements. You may assume the list has an odd number of elements.

input: [1,2,3,4,5]
output: [1,2,5,4,3]

input: [7,6,5,4,3,2,1]
output: [2,4,6,7,5,3,1]

input: [1,3,5,7,9,2,4,6,8]
output: [1,2,3,7,9,8,6,5,4]


In your answer, specify which language is used, your exact P string, the bytecount of your S string, and how many of each P and S you used.

Do not show your actual code, and do not show your S string.

### Scoring

Your score is the combined length of your P and S strings in bytes. If your answer has not been cracked in a week, you may mark it as safe. Lowest scoring safe answer wins.

# R, 10 + 24 bytes, safe

x=scan();x


Try it online!

The 'P' string is used once; the 'S' string is 24-bytes long and used twice.

## Solution

We achieve the task by making every second element negative, and then sorting the reciprocals. In this way, the largest values (whose reciprocals are closest to zero) are sorted to the middle. After sorting, we need to undo the negatives and undo the reciprocals to get the original elements back, in their new sorted order.
Intuitively, we could do all this in one step: reciprocal -> every_2nd_negative -> sort -> reciprocal -> absolute_value; or in actual R code: x=abs(1/sort(1/x*c(-1,1))).
However, since the order of the initial array doesn't matter (we're going to rearrange it anyway), we can do the reciprocal only once in a first step (so we end up with rearranged reciprocals of the input values), and then repeat the entire step again. So: two rounds of: every_2nd_negative -> sort -> reciprocal -> absolute_value; or in actual R code: x=abs(1/sort(x*c(-1,1))).
This saves 2-bytes (at the expense of uselessly sorting & flipping the signs twice in the first step), hopefully making it impossible to find a solution as short that will work in only one step. Of course, we need to be certain that the R code is fully-golfed: so, the final secret string 'S' is: =abs(.5/sort(x*-.5:1));x.

Try it online!

• How many times do you use the p string? Only once? Commented Jan 19, 2022 at 19:06
• For now, I have only 26 bytes used once, the fact that S may be reused overwhelms me... Commented Jan 26, 2022 at 8:20
• Wow, I like the solution very much! Commented Jan 27, 2022 at 11:33
• Thankyou very much. It was fun to make, too! (And thanks very much for the bounty as well...!) Commented Jan 27, 2022 at 11:34
• @pajonk - Here's a chance to get your bountied-rep back, if you fancy learning a golf language... Commented Feb 14, 2022 at 13:21

# JavaScript (ES6), 66 + 39 bytes Cracked

Each string is used once.

f=a=>(g=a=>a+a?_([_(a,26393),...g(a)],29493784462):a)(_(a,942973))


Try it online!

## Solution

### Clue 1

The non-obfuscated code is:

f=a=>(g=a=>a+a?[a.pop(),...g(a)].reverse():a)(a.sort((a,b)=>b-a))

### Clue 2

The numbers encode the strings "pop", "reverse" and "sort" in base 32.

### Secret string

_=(a,x)=>a[x.toString(32)]((a,b)=>b-a);

• Cracked
– l4m2
Commented Jan 19, 2022 at 18:11

# Python 3, 25 + 22 Safe (Orginal solution)

def f(a):a.sort();return


Both strings are used once each. No list slicing used.

Solution:

def f(a):a.sort();return a+[a.pop() for z in a]

Try it online!

# Python 3, 25 + 16 Cracked!

def f(a):a.sort();return


Both strings are used once each

Try it online!

• Welcome to Code Golf! Nice first answer. Commented Jan 24, 2022 at 2:17
• @taRadvylfsriksushilani thanks, just stumbled across the Code Golf SE. I imagine I'll be procrastinating here a lot now... Commented Jan 24, 2022 at 2:19
• Cracked
– l4m2
Commented Jan 24, 2022 at 16:57
• @l4m2 shorter than my intended solution. My intended solution also does not use list slicing. I'll add as an alternative Commented Jan 24, 2022 at 18:29
• You can get 46 bytes by removing the space after .pop() lol Commented Feb 3, 2022 at 2:51

This is old enough to be safe but I'm leaving it open, because that's more fun anyway

Not too hard ;). I give you some helper functions here and you have to define the body of f in terms of them.

x#(y:z)|y>x=y:(x#z)
x#z=x:z
(x!y)(z:w)=z#y!x\$w
((x:y)!(z:w))_|x<z=z:x:w?y|1>0=x:z:w?y
x?(y:z)=y:x?z
x?_=x
f=


It's 1 of each string. Which makes this pretty much just a fill in the blank challenge. Unfortunately it's kind of hard to make something which repeats segments in Haskell. But hopefully this should at least be a fun puzzle.

# Javascript, 27+32 bytes, safe (link to solution)

x=>x.sort((a,b)=>a-b).map(x


I decide to allow crack if a quite different solution comes, though it's now claimed safe

# Javascript, 27+36 bytes, cracked

x=>x.sort((a,b)=>a-b).map(e


# Javascript, 26+37 bytes, cracked

x=>x.sort((a,b)=>a-b).map(


Try it online!

• each used once.
– l4m2
Commented Jan 19, 2022 at 15:22
• I enjoyed solving it! and sorry for not notifying you of my post. Commented Jan 19, 2022 at 15:43
• @ThisFieldIsRequired Added one more fixed byte as limitation
– l4m2
Commented Jan 19, 2022 at 15:51
• Yes, might have a go another time. Enough code-golfing for today. Commented Jan 19, 2022 at 15:54
• Crack of the new version. Commented Jan 19, 2022 at 16:23

This is my first time doing a cops and robbers and I'm still a little confused so correct me if I did something wrong

## Python 3, 21+33 bytes - Cracked!

def f(i):m=len(i)//2;


Both strings are used once.

Attempt it online!

## Python 3, 20+36 bytes - Cracked!

def f(a):m=len(a)//2


Both strings are used once.

Attempt it online!

## Python 3, 21+43 bytes

def f(a):m=len(a)//2;


Both strings are used once.

Attempt it online!

• Something like this? This is my first time writing in Python... Commented Jan 22, 2022 at 23:15
• @DominicvanEssen That's shorter than what I had (and can still be shorter). Just a question, if it's not a solution that I had, it is shorter than 43 bytes, is it cracked? Commented Jan 23, 2022 at 0:15
• That's why I added all the #######s to make it up to 43 bytes. Commented Jan 23, 2022 at 8:21
• If your intended solution is very different, perhaps you can modify the 'P' string to invalidate my crack, as a second attempt (like i4m2 did)...? Commented Jan 23, 2022 at 8:23
• @jezza_99 oh, thats a fair self-restriction :o good luck ! Commented Feb 3, 2022 at 1:32

# Husk, 2 + 5 bytes, safe

øO


Try it online!

The 'P' string (above: 2 bytes) and the 'S' string (5 bytes) are used twice each.

Husk - like many golfing languages - has a short direct solution to the task: Ċ2S+↔O (6 bytes), and, annoyingly, the usually-fussy Husk interpreter is sufficiently lenient to allow this as a runnable program in combination with anything else on subsequent lines: try it here.
Thus, any 'S' string needs to be shorter than this (or, actually, this plus a newline character) to avoid being trivially-cracked.
Luckily, I don't think Husk has any easy way to implement 'execute this as Husk code' or similar, so I hope that brute-forcing the 5-byte solution should be difficult, at least within Husk itself...

## Solution

This is a variant of the 'fold across each value of the sorted data, alternately appending to the front or to the back of the output-so-far' approach.
This requires that the data is sorted in descending order, so that the first value added to the output is the largest, and then successively smaller values are added to the front & back. However, Husk's single-byte 'sort' command (O) sorts in ascending order.
So, instead of explicitly using a descending sort (which in Husk would be 'sort on greater than', or Ö>), we achieve the same thing by sorting reciprocals in two passes.
In the first pass, the data are sorted with the (modified) smallest element in the centre, but the results are the reciprocals of all the data. In this way, in the second pass, the data are re-sorted with the largest original element (now the smallest because it's the reciprocal) in the centre, and all the elements are re-reciprocal-ed to restore their original values.
The code for each pass is F~:↔\øO, and secret string 'S' is the first 5 bytes of this: F~:↔\.


O   # sort in ascending order,
F         # then fold over the values,
ø    # using an empty list as an intial result-so-far, by
~:       # prepending
\     # the reciprocal of each value
↔      # to the reverse of the result-so-far

Try it online!

• feel free to mark this as safe, and wow what a score it is Commented Feb 3, 2022 at 1:09
• the only idea I had on this was 4 characters followed by +. But i am not sure how to solve the rest in 4 bytes. Commented Feb 3, 2022 at 9:41
• @Razetime - Now marked 'safe' (with solution), and shorter answer posted... Commented Feb 4, 2022 at 15:18

# J, 1 + 9, cracked

~


Each string used once.

So, a 10 byte golf that ends in ~. Easy, easy.

• Cracked
– ovs
Commented Jan 19, 2022 at 21:13

# Husk, 1 + 5 bytes

↔


Try it online!

The 'P' string (above: 1 byte) is used once; the 'S' string (5 bytes) is used twice.

A better-scoring, different (...or is it...?) approach to my previous Husk answer.
Shorter should be easier-to-crack, possibly...

Note to Husk golfers and wannabee Husk golfers*: The week is now up without any crack yet, so I will offer a 100 rep bounty for the first crack of this, or 200 rep if it's the cracker's first Husk post.

*wannabee Husk golfers: Here are the docs and tutorial...

• You may want to add your bounty here: codegolf.meta.stackexchange.com/q/5243/55372 Commented Feb 24, 2022 at 10:55
• @pajonk - Thanks for the suggestion. Done. Commented Feb 24, 2022 at 12:58

# Bash, 1 + 29

'


Each string appears once. So, a 30 byte bash golf that begins or ends with a single quote.

To clarify, this doesn't have to be pure bash, but can include standard posix utils (awk, sed, grep, tr, etc, but no python or ruby or perl, etc). Input can be taken as one number per line, space-separated chars, comma-separated chars, or anything else reasonable.

• Cracked
– l4m2
Commented Jan 20, 2022 at 11:54

# Pip-xp, 11 + 4 bytes (cracked)

FiRSNalPBi&


The P-string (11 bytes) is used once; the S-string (4 bytes) is used twice.

Attempt This Online!

My original solution:

S-string R:l;, full program FiRSNalPBi&R:l;R:l;: Each time through the loop, reverse l in-place. After the loop, reverse l in-place one more time and autoprint it. The semicolon is an expression separator.

• Cracked! Commented Jan 26, 2022 at 15:46
• (and thankyou for introducing me to Pip!) Commented Jan 26, 2022 at 15:47

# Pip-xp, 8 + 7 bytes (cracked)

SN:a;R:a


The P-string (8 bytes) and the S-string (7 bytes) are used once each.

Attempt This Online!

Dominic van Essen's crack is quite clever and is also very different from my intended solution. I'm going to think if there's a way to reuse the same idea before I decide whether to reveal it.

• Cracked! Commented Jan 30, 2022 at 22:27