Cops: Make a regex - Make a snake

40

7

This is the cop's thread. The robber's thread is here.


Write a code that takes an input n and creates a n-by-n "snake matrix".

A snake matrix is a matrix that follows this pattern:

3-by-3:

1  2  3
6  5  4
7  8  9

and 4-by-4:

1   2   3   4
8   7   6   5
9   10  11  12
16  15  14  13

The exact output format is optional. You may for instance output [[1 2 3],[6 5 4],[7 8 9]], or something similar.

You must provide the language name, and a regex that fully matches your code. You can choose how detailed your regex should be. In the extreme, you can write a regex that matches every possible string, in which case it will be very easy to crack your code. You must also provide the output for n=4, so that robbers know the exact format you have opted for.

You may use one of the regex-flavors that are available on regex101.com, or the Ruby flavor.

  • PCRE (PHP)
  • Javascript
  • Python
  • Golang
  • Ruby

You must specify which one you are using.

Notes:

  • You must support any reasonably large n. You may assume it won't overflow the datatype or memory. If the default datatype is 8-bit signed integers, then you can assume n<=11, if it's unsigned 8-bit integers, then you can assume n<=15.
  • The robbers have to match the submission's output format, except leading/trailing spaces and newlines, since that might have been stripped away by the SE formatting.

Winning criterion:

The winner will be the uncracked submission with the shortest regex, measured in number of characters.

If your post has remained uncracked for 7 days, then you may post the intended solution and mark your submission as safe.

Stewie Griffin

Posted 2017-03-08T13:57:25.487

Reputation: 43 471

5Seed, length 1, .. – user41805 – 2017-03-08T16:04:55.983

1

Can I use one of the languages documented here? http://codegolf.stackexchange.com/questions/61804/create-a-programming-language-that-only-appears-to-be-unusable/62493

– None – 2017-03-08T16:09:46.333

@YiminRong I've seen Brian and Chuck used, but it also has an existing online interpreter. – mbomb007 – 2017-03-08T16:44:43.287

2@KritixiLithos Except you have to release your original program to become safe ;-) – ETHproductions – 2017-03-08T17:50:09.510

Trying first puzzle so bit confused. Do you mean write a code and then provide the regex which cracks your own code . And then, someone shows you what your code would look like (so your code is cracked). – Deepak Agarwal – 2017-03-08T19:32:53.123

3@DeepakAgarwal - Write your code to generate a snake, then provide a regex which matches it. The robber's solution must be in the same language and match the regex as well. So one strategy is to provide a restrictive regex, to make it hard on the robber, but not so restrictive that you give the solution! – None – 2017-03-08T19:48:12.567

@mbomb007 - All the languages there have an interpreter as required in the challenge. Just wondering if I can use them? – None – 2017-03-08T19:50:41.607

Yeah, you can use them. – mbomb007 – 2017-03-08T19:53:29.087

Please clarify what is "a code". Does a snippet that assume n is already declared and initialized (like this solution) count as valid? Do http://meta.codegolf.stackexchange.com/questions/2419/default-for-code-golf-program-function-or-snippet and http://meta.codegolf.stackexchange.com/questions/2447/default-for-code-golf-input-output-methods apply here? (these two meta questions are for [tag:code-golf] but here is not code-golf)

– kennytm – 2017-03-09T21:44:08.513

No, that submission doesn't take n as input, so it should not be a valid submission as far as I can tell. The two meta posts apply here too :) – Stewie Griffin – 2017-03-09T21:51:38.023

2

Is this meta consensus allowing unary I/O for sed, that has no data types, be valid for this challenge?

– seshoumara – 2017-03-10T14:42:12.333

What about ECMAScript regex? – Matthew Roh – 2017-03-12T15:35:47.930

@seshoumara, this consensus is OK, but make it very clear in your answer how you call the function/program, and what the output looks like. Please include the output for both n=3 and n=4, so that people can see how the format changes when there numbers increase.

– Stewie Griffin – 2017-03-13T10:08:33.020

@MatthewRoh, I think the 5 different options should be sufficient, unless you have some very convincing arguments for why I should add it to the list. – Stewie Griffin – 2017-03-13T10:11:33.820

There's some uncertainty over what "fully matches" means. Do we need to surround our regexes in ^$? – Brian McCutchon – 2017-03-13T17:29:22.300

Answers

9

05AB1E, Cracked by mbomb007

Hopefully fun to crack and not too obvious.

Regex (PCRE):

^\w*[+\-*\/%]*\w*.{0,2}$

Output n=4:

[[1, 2, 3, 4], [8, 7, 6, 5], [9, 10, 11, 12], [16, 15, 14, 13]]

Original solution

UXFXLNX*+NFR}ˆ

Emigna

Posted 2017-03-08T13:57:25.487

Reputation: 50 798

oooooomg - dude that's dope (compliment, of course) – Tilak Maddy – 2017-03-08T14:49:56.397

@mbomb007: Letters with accent does not match \w no. You can try yourself at regex101

– Emigna – 2017-03-08T16:47:36.457

1You could make your regex shorter by changing .{0,2} to .?.? – Aaron – 2017-03-08T17:13:29.327

1You can put the - in last position of the bracketed char class ([+*\/%-]) so you don't have to escape it. – Dada – 2017-03-08T21:19:55.010

@Dada: That does indeed work in PCRE. I'm not terribly concerned with shortening it right now as I'm pretty certain that it will be cracked. If it should hold though, I'll incorporate both yours and Aarons suggestions. Thanks :) – Emigna – 2017-03-08T21:25:59.510

Cracked. What was your original/intended solution? – mbomb007 – 2017-03-08T22:33:43.060

8

Python 2, length 62, cracked

Regex (PCRE)

^while ((?=\S)[1di\W]|an|eval|nput|nt|or|pr){55}s(?1){45}n...$

Sample output

   1    2    3    4
   8    7    6    5
   9   10   11   12
  16   15   14   13

Dennis

Posted 2017-03-08T13:57:25.487

Reputation: 196 637

Cracked – xsot – 2017-03-11T05:06:52.820

7

Jelly, length 6, cracked

Regex (PCRE)

^.{9}$

Sample output

 1  2  3  4
 8  7  6  5
 9 10 11 12
16 15 14 13

Dennis

Posted 2017-03-08T13:57:25.487

Reputation: 196 637

3This is forcing to golf really well in Jelly :D – Yytsi – 2017-03-08T14:58:54.610

1Any nine characters? You're feeling generous! :D – AdmBorkBork – 2017-03-08T15:46:53.167

1'Any nine' How many functions were there in Jelly? – Matthew Roh – 2017-03-08T16:54:15.027

I'm 99% certain that the last char has to be G to format the output properly. I'm close to solving the rest, but I just can't figure out how to reverse every other item in an array with Jelly... – ETHproductions – 2017-03-08T18:35:23.373

@ETHproductions: I was pretty certain I had it almost solved and I have a method of reversing every other item. My problem is I can't figure out how to bind everything together (I haven't tried the tutorial). I was expecting to see it solved by now though. Maybe it's harder than I think. – Emigna – 2017-03-08T20:03:59.803

Cracked; should be working now. – None – 2017-03-09T07:32:23.157

6

R, length 14 Cracked by plannapus

I hope I got this regex right. What I trying to say is 77 characters excluding <space>, #, ; and [. I tested it here

Regex

^[^ #;\[]{77}$

Sample output n= 4

1 2 3 4 
8 7 6 5 
9 10 11 12 
16 15 14 13  

MickyT

Posted 2017-03-08T13:57:25.487

Reputation: 11 735

I thought this would be easy but I'm having major trouble getting it to output those numbers like that (versus an array of some kind). Good work. – BLT – 2017-03-09T05:03:35.490

1@BLT Thanks, it was an interesting problem to try and make difficult. – MickyT – 2017-03-09T06:01:21.387

Cracked, though probably not the same code as yours. – plannapus – 2017-03-09T09:41:03.073

6

05AB1E, Cracked by Value Ink

Lets kick it up a notch :)
Hopefully a nice puzzle.

Regex (PCRE)

^\w*..\w*$

Output n=4

[[1, 2, 3, 4], [8, 7, 6, 5], [9, 10, 11, 12], [16, 15, 14, 13]]

Emigna

Posted 2017-03-08T13:57:25.487

Reputation: 50 798

Got it – Value Ink – 2017-03-10T20:57:29.640

6

><>, length 49, Cracked by Aaron

Regex (Javascript)

^.{7}\n.{12}\n\?.{6};[^v^]{27}(\n.{13}:&.{2}){2}$

Sample output (n=4)

1 2 3 4 
8 7 6 5 
9 10 11 12 
16 15 14 13 

Formatting is a bit weird, but checking for number length would have made it a lot longer. Might have gone a bit overboard on the regex, not sure!

Edit: Also I forgot to mention, I use the initial stack (-v flag) for input, not the usual fish input. Sorry!

Original Code:

<v1*2&:
 >:{:}=?v:1+
?^{r0}v;>&:&[r]{&:&2*+}::&:::&*@+@(
+:}=?v>n" "o&:&{1
0~{oa<^v?)*&::&:}

Aaron's is a lot simpler! The complexity of my original code is based around the idea of using n[r] every n-th number to flip that segment (row), then printing all numbers at once at the end

torcado

Posted 2017-03-08T13:57:25.487

Reputation: 550

1.. is shorter than .{2} ;) – Aaron – 2017-03-13T13:18:32.927

Doesn't matter, cracked it ! I obviously didn't follow your code too much, but it was an interesting challenge anyway. Please share your original code ! Also if you like, you could return the favour ;)

– Aaron – 2017-03-13T16:45:22.437

@Aaron nice job! also yeeah i'm not sure how i didn't notice that in the regex. oh well :) I'll see if i can crack yours – torcado – 2017-03-14T05:24:06.820

5

Ohm, cracked

Also my first Cops and Robbers challenge, so tell me if there are issues with this pattern (especially since this is a fairly unknown language).

Regex (PCRE)

^\S{6}\W{0,3}\w$

Output (n = 4)

[[1, 2, 3, 4], [8, 7, 6, 5], [9, 10, 11, 12], [16, 15, 14, 13]]

Nick Clifford

Posted 2017-03-08T13:57:25.487

Reputation: 1 184

1If anything it may be too easy. If you have .* in your regex, it could be anything. So if the language has comments, they could write any program followed by a comment. – mbomb007 – 2017-03-08T18:23:29.543

@mbomb007 Good point. – Nick Clifford – 2017-03-08T18:27:26.940

1Cracked :) – Emigna – 2017-03-09T12:46:41.123

@Emigna Well done! – Nick Clifford – 2017-03-09T12:51:07.363

5

Ruby [cracked]

First Cops and Robbers challenge. Hope I didn't make this too easy.

EDIT: replaced \g<1> with (?1) because they're evidently equivalent in PCRE.

Regex(PCRE)

^(\W?\W\w){4}..(?1){2}[(-=Z-~]*(?1){5}\w*(?1)(.)\2$

Output (n=4)

[[1, 2, 3, 4], [8, 7, 6, 5], [9, 10, 11, 12], [16, 15, 14, 13]]

(Returns an array of arrays. It's a lambda, BTW, but maybe that gives away too much?)

Value Ink

Posted 2017-03-08T13:57:25.487

Reputation: 10 608

Cracked http://codegolf.stackexchange.com/a/112640/32353

– kennytm – 2017-03-11T12:25:13.100

5

PHP, 221 Bytes (Cracked)

I hope it is difficult enough.

Regex (PCRE): 16 Bytes

^[^\s/\#6]{221}$

No space, No comments, no use of base64_decode. Have Fun.

Output

  1  2  3  4
  8  7  6  5
  9 10 11 12
 16 15 14 13

Original Code

$w=$argv[1];$s="";$r=range(1,$w**2);for($i=0;$i<$w;$i++)if($i%2)array_splice($r,$i*$w,$w,array_reverse(array_slice($r,$i*$w,$w)));foreach(($r)as$v)$s.=str_pad($v,$l=strlen(max($r))+1,"\x20",0);echo(chunk_split($s,$l*$w));

Jörg Hülsermann

Posted 2017-03-08T13:57:25.487

Reputation: 13 026

Please note that answers can use base64_decode because your regex does not disallow it. – CalculatorFeline – 2017-03-09T04:26:03.277

4@CalculatorFeline: the regex blocks 6, which might block base64_decode. – nneonneo – 2017-03-09T06:09:29.370

Cracked http://codegolf.stackexchange.com/a/112405/32353

– kennytm – 2017-03-09T13:11:02.733

Oops, missed that. But ^ so it doesn't matter. – CalculatorFeline – 2017-03-09T15:29:52.693

5

dc, Regex length 12   Cracked by seshoumara!

^[^# !]{59}$

This regular expression is simple enough that I don't think the flavor of regex matters -- it should work across the board. (Note the space after the # in the regex.)

I've tested all four flavors at regex101.com (PCRE/PHP, Javascript, Python, and Golang), as well as the Ruby version at rubular.com. The dc program matches the regex in all five regex versions.


The dc program takes its input on stdin and puts its output on stdout.

Sample output for input 4 (there's a trailing space at the end of each line):

1 2 3 4 
8 7 6 5 
9 10 11 12 
16 15 14 13 

Original code (added after being cracked)

This has been cracked by @seshoumara. Here's my intended code:

?sd[AP]s+0[dddld/2%rld%2*1+ldr-*+1+n2CP1+dld%0=+dvld>l]dslx

Explanation:

?sd      Input number and store it in register d.
[AP]s+   Macro that prints a newline. The macro is stored in register '+'.
0        Push 0 on the stack, initializing a loop.  (The top of the stack is the index variable.  It will go up to d^2-1.)
[        Start a macro definition.  (The macro will be stored in register l.)
ddd      Push 3 copies of the loop index variable on the stack, so they'll be available later. I'll call this number i.
ld/      Divide the last copy of i by d (integer division); this computes the row of the square that we're in (starting with row 0).
2%       Replace the row number with 0 if the row number is even, with 1 if the row number is odd.
r        Swap the top two items on the stack, so the top item is now the next to last copy of i, and the second item on the stack is the row number mod 2.
ld%      Compute i mod d; this goes from 0 to d-1. It is the column in the square that the next number will be placed in.  (The leftmost column is column 0.)
2*1+     Top of the stack is replaced with 2*(column number)+1.
ldr      Inserts d as the second item on the stack.
-        Computes d-2*(column number)-1.
*        The second item on the stack is the row number mod 2, so multiplying yields 0 if the row number is even, and d-2*(column number)-1 if the row number is odd.
+        Add to the remaining copy of i. The sum is i itself in even-numbered rows, and it's i+d-2*(column number)-1 in odd-numbered rows.

The sum at the top of the stack now is the next number we want to print:

  • It's easy to see that that's correct if the row number is even, since then the sum is just i.

  • For odd-numbered rows, notice that i = d*(i/d)+(i%d) = d * (row number) + column number. It follows that the sum i+d-2*(column number)-1 is d * (row number) + column number + d - 2*(column number)- 1 = d * (row number + 1) - column number - 1, which is the number we want to put in the indicated row and column to ensure that we're counting backwards in the odd-numbered rows.

Returning to the explanation now:

n        Print the desired number for the current row and column.
2CP      Print a space.  (2C, which is computed by dc as 20 + 12, is 32, the ASCII code for a space.)
1+       The original copy of i is at the top of the stack; add 1 to it.
dld%0=+  If (the incremented value of) i is a multiple of d, call the macro at register '+', which prints a newline.
dvld>l   If d > sqrt(i) (in other words, if i < d^2), then go back to the top of the loop by calling macro l again.
]dslx    End the macro definition, store the macro in register l, and execute it.

Mitchell Spector

Posted 2017-03-08T13:57:25.487

Reputation: 3 392

Are the chars # and omitted so that a shorter solution can't use comments to reach 59 bytes? If so, there's no need since in dc there are so many ways to add commands that don't change anything, for ex. repeating q commands at the end of the script. – seshoumara – 2017-03-09T07:12:14.907

@seshoumara It's meant to be a nod in that direction while still keeping the regex short. But you're right, of course. (This is my first cops-and-robbers entry, so I'm not sure how easy it is.) – Mitchell Spector – 2017-03-09T07:16:39.363

Cracked!. Getting to slightly more than 59 bytes was easy, but matching your limit or under was more difficult than I expected. As for the regex, the space was ok to omit, my bad, since one needs to print it, so I had to use something else. – seshoumara – 2017-03-10T06:46:51.777

@seshoumara Nice job! – Mitchell Spector – 2017-03-10T06:56:06.267

@seshoumara By the way, spaces are also useful in dc to separate two successive numerical constants, so prohibiting spaces requires a workaround if you need that functionality. However, printing a space is no big deal, because 32P is shorter than [ ]n anyway. – Mitchell Spector – 2017-03-10T07:05:32.750

You're right. This 'cops and robbers' challenge is something else, I never had more fun coding in dc like this time. It was also my first entry. If you wish, let's continue our script's discussion on bash, sed and dc chat room.

– seshoumara – 2017-03-10T07:14:28.620

5

QBasic, regex length 10 (cracked)

Regex

Should work in any regex flavor, but we'll call it Python flavor.

([A-Z]+.)+

NOTE: My solution uses unformatted QBasic; after formatting, the code doesn't match the regex due to added spaces. (But I can tell you that that's the only change that makes a difference. ([A-Z]+ ?. ?)+ still works on the formatted version.)

For testing purposes, I used QB64 with code formatting turned off (under Options > Code layout). If you don't want to download something, you can also run QBasic online at archive.org (but there you can't turn formatting off).

Sample output

 1  2  3  4 
 8  7  6  5 
 9  10  11  12 
 16  15  14  13 

DLosc

Posted 2017-03-08T13:57:25.487

Reputation: 21 213

So all symbols in the source must be preceded by a letter. – CalculatorFeline – 2017-03-09T15:31:08.437

@CalculatorFeline One or more letters. – mbomb007 – 2017-03-10T19:21:23.013

Well, my requirement is equivalent because \w+\W can be split into \w* and \w\W. (\w* is either null (trivial) or \w+ (easily snuck in with a symbol)) – CalculatorFeline – 2017-03-10T19:27:20.463

@CalculatorFeline There is nothing saying that the . can't be a word character. It could be a lowercase letter, or a digit. In fact, it could even be a capital letter, in the event that the last character of the program is one. – mbomb007 – 2017-03-10T21:25:51.707

Okay. Replace \W with .. Therefore, (\w+.)+ is equivalent to (\w*|\w.)+ is (\w+||\w.)+ is (\w+|\w.)+ is (\w|\w.)+ is (\w.?)+ and it's the same length but more efficient (one + vs two) – CalculatorFeline – 2017-03-11T16:44:18.460

1

Cracked http://codegolf.stackexchange.com/a/112653/32353

– kennytm – 2017-03-11T16:51:17.313

5

C# net46 (Cracked)

(http://ideone.com/ works)

Regex PCRE flavor length 58 tested at regex101

^sta((?![\d%bh\/]|==|if|(\[.*){4}|(i.*){6}).){142}urn....$

Only the method is regexed. Method returns a 2d int[,] array (int[4,4]) for an input n=4. If printed looks like this:

1 2 3 4 
8 7 6 5 
9 10 11 12 
16 15 14 13 

This is my first entry into anything like this, let me know if I did anything wrong. Not trying to win by regex length for sure, I'm just interested to see how well I did at preventing cracking :)

Original code:

static int[,]g(int n){int l,j,k=n-n,c,s;var _=new int[n,n];var d=n!=n;c=k;c++;s=k;for(l=k;l<n;l++){for(j=k;j<n;j++){_[l,d?n-j-c:j]=++s;}d=!d;}return _;}

EklipZ

Posted 2017-03-08T13:57:25.487

Reputation: 51

Cracked. http://codegolf.stackexchange.com/a/112636/32353

– kennytm – 2017-03-11T11:53:09.713

Well done, I should have tried to make the length more challenging at least... – EklipZ – 2017-03-11T20:53:41.353

5

Bash, regex length 38, cracked (@kennytm)

^sort -n <[1adegnopqrstx$\-*()|'; ]+$

Input:

n=4; <command>

Output:

1 2 3 4
8 7 6 5
9 10 11 12
16 15 14 13

Marcos M

Posted 2017-03-08T13:57:25.487

Reputation: 51

Cracked http://codegolf.stackexchange.com/a/112656/32353. This one is nice :D

– kennytm – 2017-03-11T18:01:56.437

Glad you enjoyed it @kennytm you've found exact solution as my original command! – Marcos M – 2017-03-13T12:11:04.867

5

Python 3, 55 bytes (Cracked)

PCRE / Python / Golang flavor.

def [triangles=(1,SNAKE)]{27}:print[]SNAKE(--:>or[]{48}

(Be reminded that Full match is required. Assume ^ and $ when testing.)

Sample output:

[1, 2, 3, 4]
[8, 7, 6, 5]
[9, 10, 11, 12]
[16, 15, 14, 13]

Original solution:

def r(N,S=1,A=1,K=range,E=list):print(E(K(S,S+N))[::A])or(S+N>N*N)or(r(N,S+N,-A,K,E))

Should have trimmed 4 bytes :p

kennytm

Posted 2017-03-08T13:57:25.487

Reputation: 6 847

It seems for me that you miss the ) in the second part of the regex – Jörg Hülsermann – 2017-03-10T20:19:47.623

@JörgHülsermann no nothing is missing, the regex is correct. – kennytm – 2017-03-10T20:25:25.763

1@JörgHülsermann The extra ( is inside a character class starting after print and ending before {48}. Took me a while to see it too. ;) (For that matter, the earlier pair of parentheses are also inside a character class.) – DLosc – 2017-03-10T22:39:46.080

@DLosc Now it is clear . Thank You – Jörg Hülsermann – 2017-03-10T23:03:44.840

Cracked – xsot – 2017-03-12T04:14:23.440

5

PHP

I hope this will be a fun one! :D

Output (n=4)

[[1,2,3,4],[8,7,6,5],[9,10,11,12],[16,15,14,13]]

Level 1: PCRE (length=17) (Cracked by Jörg Hülsermann)

^<[^'"\d{vV;<$]+$
  • No single or double quotes so... no strings!
  • No digits!
  • No { so... no anonymous functions!
  • No v so... no eval()!
  • No ; so... it must be a single statement!
  • No < so... no Heredoc nor multiple PHP blocks!
  • The big one! No $ so... good luck defining variables! >:D

@JörgHülsermann had an interesting approach, but it's not what I had in mind :). Therefore, I'm introducing a new level of difficulty (I promise I have the code that fits this and I'm not just messing with you):

Level 2: PCRE (length=23) (Cracked by Jörg Hülsermann)

^<[^'"\d{v;<$_~|&A-Z]+$
  • All the restrictions of Level 1
  • New on this level: none of these _~|&A-Z! :)

Have fun!


THE ORIGINAL SOLUTION

So, forbidding the $ meant the variables couldn't be accessed the regular way, but that doesn't mean they can't be used at all! You can still use extract()/compact() to import/export variables into the current scope. :)

$i = 1;
// can be written as
extract(['i' => 1])

echo $i;
// can be written as
echo compact('i')['i'];

However, there's a gotcha: compact('x')['x']++ wouldn't work because variables in PHP are passed by value... with one exception! Objects.

$x = (object) ['i' => 1];
// is
extract(['x' => (object) ['i' => 1]]);

// and
compact('x')['x']->i++;
// works just fine!

The rest is easy.

  • Numbers 0 and 1 are easily generated by converting false and true to int by prepending them with the + sign
  • Use and and or since & and | are forbidden
  • To work around the forbidden quotes, just use undefined constants, which are treated as strings
  • To suppress the notices generated by using undefined constants, just use @
  • The forbidden letter v can be generated by using chr(ord('u') + 1), which translates to @chr(ord(u) + true) using the above workarounds
  • The underscore is similar to the above: chr(ord('a') - 2) which translates to chr(ord(a) - true - true)
  • Calling functions which contain forbidden characters can be done by taking advantage of PHP's callable type, which can be a string containing the name of the function. So, you can concatenate undefined constants and single character strings generated by ord() to build the name of the function and invoke it like this: array_reverse() becomes (a.rray.chr(ord(a)-true-true).re.chr(ord(u)+true).erse)() (array is a language construct, that's why it's split into the undefined constants a and rray)
  • Take advantage of the fact that, when it comes to conditional and loop constructs, the curly brackets are optional if the construct applies just to the immediately following statement. This means you can do stuff like: if ($n = $argv[1] and $i = 0) while ($n > $i++ and do_some and other_stuff or exit)

The logic in human readable code would be:

if (
    $x = (object) [
        'result' => [],
        'i' => 0
    ]

    and

    define('n', $argv[1])

    and

    define('un', '_')

    and

    // create the initial set which we'll loop through
    define('segments', array_chunk(range(1, pow(n, 2)), n))
) while (
    // store each odd segment as-is and increment the "pointer"
    ($x->result[] = @segments[$x->i++])

    and

    // store each even segment reversed and increment the "pointer"
    ($x->result[] = @array_reverse(segments[$x->i++]))

    and

    // check if we need to break out of the loop
    n > $x->i

    or

    // exit and output the result if the above is false
    die(json_encode(
        // if n is odd, the above would have copied a NULL entry 
        // from the segments, so it needs to be filtered out
        array_filter($x->result)
    ))
)

And the unfriendly version that matches the regex:

<?php if (@extract([x=>(object)[s=>[],i=>+false]])and@define(n,compact(arg.chr(ord(u)+true))[arg.chr(ord(u)+true)][+true]?:+true)and@define(un,chr(ord(a)-true-true))and@define(s,(a.rray.un.chunk)(range(+true,pow(n,true+true)),n)))while((@compact(x)[x]->s[]=s[@compact(x)[x]->i++])and(@compact(x)[x]->s[]=(a.rray.un.re.chr(ord(u)+true).erse)(s[@compact(x)[x]->i++]))and(n>@compact(x)[x]->i)or(@die((json.un.encode)((a.rray.un.filter)(@compact(x)[x]->s)))))?>

Ionut Botizan

Posted 2017-03-08T13:57:25.487

Reputation: 71

@JörgHülsermann Since my regex was pretty long as it was and I don't expect it to have any chance to win, I just assumed that people won't get too hung up on such technicalities as the case sensitivity of the regex engine. Anyways, I edited my answer so the regex now includes a capital V. Have fun! :) – Ionut Botizan – 2017-03-10T21:18:38.683

Nice try to make people crazy. No single or double quotes so... no strings! The answer is heredoc Syntax. No ; so... it must be a single statement! ?><?php vice versa! The big one! No $ so... good luck defining variables! >:D Okay I can work with constants – Jörg Hülsermann – 2017-03-10T21:25:29.937

You want crazy?! I have updated the Regex to exclude the < character except at the very begining, thus no Heredoc and no multiple PHP code blocks! >:D Actually my solution doesn't uses any whitespace either, except after the opening <?php tag (It matches ^<\?php [^'"\d\s{vV;<$]+$). :) – Ionut Botizan – 2017-03-10T22:13:43.793

One other bit of info that might point you in the right direction: my script is executed like this: php ./snake.php 4 so I am somehow reading input from the command line. :) – Ionut Botizan – 2017-03-10T22:21:58.763

@JörgHülsermann Looks like you're having fun with this! :) I'm looking forward to see your take on this other approach: http://codegolf.stackexchange.com/a/112650/66648

– Ionut Botizan – 2017-03-11T15:36:20.603

1@JörgHülsermann It is actually the same code but I initially used a looser regular expression because I was curious of what other solutions could people come up with. I'll give it one more day (maybe someone would like to take a shot at it over the week-end) and I'l post my code and the explanations tomorrow night.

What I can tell you right now is that you were on the right path about using undefined constants as strings. Also, you were wrong about something in your solution. You can call (array_re.chr(ord(u)+true).erse)()! :) (...or at least you could when the _ was allowed) – Ionut Botizan – 2017-03-11T19:19:15.093

3@IonutBotizan You could keep the solution of Level 1 secret for now since it is cracked. It is still better for you to make Level 2 as a new post, it is easier for other people to check whether it is cracked or not. – kennytm – 2017-03-12T05:52:22.067

1

level 2 cracked https://regex101.com/r/XtVl9G/1 thank you for the hint. Now I am waiting for level 3 :-)

– Jörg Hülsermann – 2017-03-12T21:26:51.620

Maybe you want to add these alternatives http://php.net/manual/en/function.parse-str.php and http://php.net/manual/en/function.get-defined-vars.php . Your solution is very crazy :-)

– Jörg Hülsermann – 2017-03-13T21:21:53.027

4

JavaScript (Cracked)

First time doing a Cops and Robbers challenge, hopefully doing it right.

Regex (JavaScript)

^.*(\.\w+\(.*\)){4}$

Output

An array equal to:

[[1,2,3,4],[8,7,6,5],[9,10,11,12],[16,15,14,13]]

Tom

Posted 2017-03-08T13:57:25.487

Reputation: 3 078

You may want a $ on the end of the regex if the code itself ends at the end of the regex. Otherwise I could do e.g. x=>x.toString().toString().toString().toString() and then whatever I want after that. – ETHproductions – 2017-03-08T16:43:27.060

@ETHproductions Good point, thanks for the tip! – Tom – 2017-03-08T16:44:47.620

Cracked – ovs – 2017-03-08T16:46:40.493

1@ovs Wow, that was fast. Good job! – Tom – 2017-03-08T16:49:17.983

4@Tom The .* at the beginning would've made it really easy. It could be any program followed by a comment. Basically, don't include .* in your regex. – mbomb007 – 2017-03-08T17:22:05.227

4

Röda 0.12, length 19 (Cracked by @KritixiLithos)

PCRE:

^{(\|[^\/#\s]*){8}$

Sample output (n=4):

[1, 2, 3, 4][8, 7, 6, 5][9, 10, 11, 12][16, 15, 14, 13]

Original code:

{|n|seq(0,n-1+n%2)|push([{|i|seq(n*i+1,n*i+n)}(_)],[{|j|seq(n*j+n,n*j+1,step=-1)}(_)])|head(n)}

Try it online!

fergusq

Posted 2017-03-08T13:57:25.487

Reputation: 4 867

1

It's fair game as long as it predates this challenge and has an available (free) interpreter. The first time I tried MATL was when trying to crack a cop post. Don't be surprised if someone learns Röda just to crack this answer :)

– Stewie Griffin – 2017-03-09T09:41:44.403

I do hope the documentation is in English, not Finnish though :) – Stewie Griffin – 2017-03-09T09:44:06.043

@StewieGriffin There is some documentation available. Should I add a link to my answer or is is sufficiently easy to find from the Github page?

– fergusq – 2017-03-09T09:50:09.243

Cracked! :) – user41805 – 2017-03-11T09:39:56.860

4

Swift, regex 25 (Cracked)

Right, let's see if I've got the hang of this. This is my first cops and robbers post, so lemme know if I've messed up!

Regex

I used javascript flavour on regex101.com

^.{21}print[^/]{49}o.{7}$

Sample Output

[1, 2, 3, 4]
[8, 7, 6, 5]
[9, 10, 11, 12]
[16, 15, 14, 13]

Original Code

(0..<n).forEach{i in print((0..<n).map{i%2>0 ?(i+1)*n-$0 :i*n+$0+1},separator:",")}

James Webster

Posted 2017-03-08T13:57:25.487

Reputation: 2 809

Cracked http://codegolf.stackexchange.com/a/112401/32353

– kennytm – 2017-03-09T12:29:11.013

It appears this submission doesn't take n as an input, but requires a hard coded variable. If that's correct then I'm afraid this is not valid according to meta consensus.

– Stewie Griffin – 2017-03-09T21:54:55.673

Note: You may keep the post, since it's already been cracked :) – Stewie Griffin – 2017-03-09T22:06:49.573

@Stewie. Thanks for the info, there's a reason I've avoided these kinds of questions in the past! I think I understand the concept of "just a function" a bit better since this answer was cracked. I had assumed that it meant the body of a function, but I gather now it means a function variable? – James Webster – 2017-03-10T08:43:42.233

4

MATL, length 12 (safe)

Regex

Uses Python flavour:

(\w{3}\W){5}

Example output

For n=4:

 1  2  3  4
 8  7  6  5
 9 10 11 12
16 15 14 13

Solution

txU:GeG:oEq*S5M*TTx!

To see how this works, consider input n=4.

tx   % Implicit input n, duplicate, delete. So this does nothing
     % STACK: 4
U    % Square
     % STACK: 16
:    % Range
     % STACK: [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16]
Ge   % Reshape as an n-row array in column major order
     % STACK: [1  5  9 13;
               2  6 10 14;
               3  7 11 15;
               4  8 12 16]
G:   % Push range [1 2 ... n]
     % STACK: [1  5  9 13;
               2  6 10 14;
               3  7 11 15;
               4  8 12 16]
               [1 2 3 4]
o    % Modulo 2
     % STACK: [1  5  9 13;
               2  6 10 14;
               3  7 11 15;
               4  8 12 16]
              [1  0  1  0]
Eq   % Times 2, minus 1 (element-wise)
     % STACK: [1  5  9 13;
               2  6 10 14;
               3  7 11 15;
               4  8 12 16]
              [1 -1  1 -1]
*    % Multiply (element-wise with broadcast)
     % STACK: [1 -5  9 -13;
               2 -6 10 -14
               3 -7 11 -15
               4 -8 12 -16]
S    % Sort each column
     % STACK: [1 -8  9 -16;
               2 -7 10 -15;
               3 -6 11 -14;
               4 -5 12 -13]
5M   % Push [1 -1 1 -1] again
     % STACK: [1 -8  9 -16;
               2 -7 10 -15;
               3 -6 11 -14;
               4 -5 12 -13]
              [1 -1  1  -1]
*    % Multiply (element-wise with broadcast)
     % STACK: [1  8  9  16;
               2  7 10  15;
               3  6 11  14;
               4  5 12  13]
TTx  % Push [true true] and delete it. So this does nothing
!    % Transpose. Implicitly display
     % STACK: [ 1  2  3  4;
                8  7  6  5;
                9 10 11 12;
               16 15 14 13]

Luis Mendo

Posted 2017-03-08T13:57:25.487

Reputation: 87 464

4

C – regex of 42 characters in length – cracked

Javascript regex as used in regex101.

^[-h<=*c+m?{printf("\/a: %d\\',o);}]{137}$

Guessing this will be trivial...

> main 4
1   2   3   4
8   7   6   5
9   10  11  12
16  15  14  13
>

Output is tab-delimited with \n after each line.

My solution, here integers 0 - 2 were obtained via t-t, t/t, and t:

main(int t,char**a){int o=t-t,i=t/t,m,n,h=atoi(*(a+i));for(m=o;m<h;m++)for(n=o;n<h;n++)printf("%d%c",m*h+(m%t?h-n:n+i),n<h-i?'\t':'\n');}

user15259

Posted 2017-03-08T13:57:25.487

Reputation:

You can remove one r in your regex. – kennytm – 2017-03-09T17:49:35.730

@kennytm - thanks - missed that one – None – 2017-03-09T18:55:03.947

Cracked http://codegolf.stackexchange.com/a/112447/32353

– kennytm – 2017-03-09T19:39:51.070

4

PHP 7 (Safe)

Original Code

for($z=0,$q="";$z<($x=$argv[1])**2;){$w=($d=intdiv($z,$x))%2?($d+1)*$x-$z%$x:($z+1);for($f=0;$f<(log10($x**2)^0)-(log10($w)^0);$f++)$q.="\x20";$q.=++$z%$x?"$w\x20":"$w\n";}print(rtrim($q));

Second Try

Regex (PCRE): 29 Bytes

^[^A-Z#\/\s\>busy_heck]{189}$

No space, No comments, no use of base64_decode.

Many functions are not allowed! underscore

Output n=11

  1   2   3   4   5   6   7   8   9  10  11
 22  21  20  19  18  17  16  15  14  13  12
 23  24  25  26  27  28  29  30  31  32  33
 44  43  42  41  40  39  38  37  36  35  34
 45  46  47  48  49  50  51  52  53  54  55
 66  65  64  63  62  61  60  59  58  57  56
 67  68  69  70  71  72  73  74  75  76  77
 88  87  86  85  84  83  82  81  80  79  78
 89  90  91  92  93  94  95  96  97  98  99
110 109 108 107 106 105 104 103 102 101 100
111 112 113 114 115 116 117 118 119 120 121

Output n=4

 1  2  3  4
 8  7  6  5
 9 10 11 12
16 15 14 13

Output n=3

1 2 3
6 5 4
7 8 9

Jörg Hülsermann

Posted 2017-03-08T13:57:25.487

Reputation: 13 026

I believe your answer is now safe :) – Aaron – 2017-03-17T13:19:34.993

@Aaron I wonder me that is was not cracked. Original Code is added – Jörg Hülsermann – 2017-03-17T13:56:03.977

4

Jelly, length 14 cracked

cracked by Dennis

[^/P-`mvḊ-ṫ€]*

Python regex.

Added m back in again after I let it slip.

/ (reduce quick);
from P (product) to ` (monad from dyad quick);
m (modulo indexing);
v (eval dyad);
from (dequeue) to (tail); and
(for each quick)

For an input of 4 mine outputs:

 1  2  3  4
 8  7  6  5
 9 10 11 12
16 15 14 13

...because I formatted a list of lists as a grid with G.

Jonathan Allan

Posted 2017-03-08T13:57:25.487

Reputation: 67 804

Cracked. This was a fun one. – Dennis – 2017-03-10T02:53:24.853

4

Jelly, length 17 (safe)

[^/P-`mvÇ-ıḃ-ṫ€]*

Python regex.

Tightening the knot, this bans some more useful things, for your aid here are the banned bytes:

/PQRSTUVWXYZ[\]^_`mvÇÐÑ×ØÞßæçðñ÷øþĊċĖėĠġİıḃḄḅḊḋḌḍḞḟḢḣḤḥḲḳḶḷṀṁṂṃṄṅṆṇṖṗṘṙṚṛṠṡṢṣṪṫ€

just under a third of them!

For an input of 4 mine outputs:

 1  2  3  4
 8  7  6  5
 9 10 11 12
16 15 14 13

...because I formatted a list of lists as a grid with G.

A solution:

’:2o1
Ḃ¬aẋ@0
’r0;0ẋ$ẋ1Ŀ¬0¦;2ĿÆ¡œ?⁸²¤s⁸G

Try it online! / regex101

The main trick here is to index into a lexicographically sorted list of the permutations of the natural numbers up to n2 (using œ? to avoid building the list of length n2!), and to split the result into chunks of length n. The aforementioned index is found by forming its representation in the factorial number system which is formulaic since the "unsliced" snake is created by permuting elements in a prescribed manner (this may be readily converted to a number with Æ¡).

The solution I present uses Ŀ to reference previous links as monads (replacing Ñ and Ç), but multiple $ in a row could be employed instead to "inline" these helper functions. It also uses r since and R are banned.

’:2o1 - Link 1, periodic repetitions in the factorial base representation: n
’     - decrement n
 :2   - integer divide by 2
   o1 - or 1 (keep one period in the cases n=1 and n=2)

Ḃ¬aẋ@0 - Link 2, n zeros if n is even, else an empty list: n
Ḃ      - mod 2
 ¬     - not
   ẋ@0 - 0 repeated n times
  a    - and

’r0;0ẋ$ẋ1Ŀ¬0¦;2ĿÆ¡œ?⁸²¤s⁸G - Main link: n                    e.g. 6
’r0                        - inclusive range(n-1, 0)              [5,4,3,2,1,0]
    0ẋ$                    - 0 repeated n times                   [0,0,0,0,0,0]
   ;                       - concatenate (makes one "period")     [5,4,3,2,1,0,0,0,0,0,0,0]
        1Ŀ                 - call link 1 as a monad               2
       ẋ                   - repeat list                          [5,4,3,2,1,0,0,0,0,0,0,0,5,4,3,2,1,0,0,0,0,0,0,0]
           0¦              - apply to index 0 (rightmost index):
          ¬                -     not (make the last 0 a 1)        [5,4,3,2,1,0,0,0,0,0,0,0,5,4,3,2,1,0,0,0,0,0,0,1]
              2Ŀ           - call link 2 as a monad               [0,0,0,0,0,0]
             ;             - concatenate                          [5,4,3,2,1,0,0,0,0,0,0,0,5,4,3,2,1,0,0,0,0,0,0,1,0,0,0,0,0,0]
                Æ¡         - convert from factorial base          45461852049628918679695458739920
                      ¤    - nilad followed by link(s) as a nilad
                    ⁸      -     left argument, n                 6
                     ²     -     square                           36
                  œ?       - lexicographical permutation lookup   [1,2,3,4,5,6,12,11,10,9,8,7,13,14,15,16,17,18,24,23,22,21,20,19,25,26,27,28,29,30,36,35,34,33,32,31]
                       s⁸  - split into chunks of length n        [[1,2,3,4,5,6],[12,11,10,9,8,7],[13,14,15,16,17,18],[24,23,22,21,20,19],[25,26,27,28,29,30],[36,35,34,33,32,31]]
                         G - format as a grid

Jonathan Allan

Posted 2017-03-08T13:57:25.487

Reputation: 67 804

4

Powershell, 23 Bytes

Cracked By Matt

^.+?%.{42}%.{11}:.{35}$

Original Solution:

$n="$args";$script:r=0;$a=1..$n|%{$t=++$script:r..($script:r+=$n-1);if(!($_%2)){[Array]::Reverse($t)};,$t};$a|%{$_-join" "}

Takes input as argument and outputs to stdout

Hopefully this regex is OK, I don't expect this being too difficult to crack, as I haven't obfuscated much of it, and the regex gives a good few starting points to fill in the gaps, there's one thing in the first segment which is very uncommon in code golf though, which may catch someone out, I think a non-greedy match is required there to make this a bit tougher.

First cops challenge anyway.

1..4 | % { "----$_----" ; .\snake-cops.ps1 $_  }
----1----
1
----2----
1 2
4 3
----3----
1 2 3
6 5 4
7 8 9
----4----
1 2 3 4
8 7 6 5
9 10 11 12
16 15 14 13

colsw

Posted 2017-03-08T13:57:25.487

Reputation: 3 195

Cracked – Matt – 2017-03-10T20:13:28.173

What was your solution? – Matt – 2017-03-10T21:46:25.747

@Matt added, I figured it would be harder considering how many non-code-golf things I added, i.e. using [Array]::Reverse() instead of $array[9..0] and $script:r variables which are mostly needless. – colsw – 2017-03-10T21:50:04.447

4

Pip, regex length 3 (safe)

The solution is a full program that takes n as a command-line argument. It does not use any command-line flags.

Regex (any flavor)

\w+

Sample output

1 2 3 4 
8 7 6 5 
9 10 11 12 
16 15 14 13 

My solution

YENsXaPBsPOyY_MUyFi_MUENsXaIiBA1PsPUPODQENsXiXaPBsX_PBsMRVyEI1PsPUPODQENsXiXaPBsX_PBsMy

Try it online!

Strategy

Here's the code we would like to write:

Y \,a
F i ,a
 I i%2
  P i*a+_.s M RVy
 E
  P i*a+_.s M y

That is:

  • Store the numbers 1 through a in y
  • Loop over values of i from 0 through a-1
  • If i is odd, reverse y, add i*a to each element, concatenate a space to each element, and print
  • Otherwise, do the same thing, but without reversing first

Difficulties

A lot of commands and variables in Pip use letters, but some important ones don't:

  • Range and inclusive range (, and \,)
  • Most math operations (+, -, *, %, ++)
  • Assignment (:)
  • We can't have a loop or function body with more than one statement (that would need {})
  • We can't use parentheses to enforce precedence

How we get around those limitations:

  • ENumerate can be used in place of ,; we just need a string with the number of characters we want, and we need to extract the first element of each sublist in a structure like [[0 "H"] [1 "i"]].
  • We don't need to increment anything if we can solve the problem with For loops.
  • We can assign to the y variable with the Yank operator.
  • We can do math with strings: X is string multiplication, and PUsh (or PB "push-back") will concatenate a string to another string in-place. To take the length of a string, we can ENumerate it and extract the right number from the resulting list.
  • We can use functions as long as they can be written as single-expression lambda functions using _.

Specifics

The building blocks of our program:

Range

_MUENsXa

That's map-unpack(_, enumerate(repeat(space, a))) in pseudocode. Map-unpack is like Python's itertools.starmap: given a list of lists, it calls a function on the items of each sublist. _ returns its first argument, so _MU just gets the first item of each sublist. For example, if a = 3:

     sXa  "   "
   EN     [[0 " "] [1 " "] [2 " "]]
_MU       [0 1 2]

... which is the same as ,a.

Inclusive range

I'm not sure there's a way to do inclusive-range(1, a) in a single expression, but fortunately we only need it once, so we can construct it in the y variable in three steps.

YENsXaPBs

In pseudocode, yank(enumerate(repeat(space, a).push-back(space))):

   sXa     "   "
      PBs  "    "
 EN        [[0 " "] [1 " "] [2 " "] [3 " "]]
Y          Store that in y

Next POy pops the first item from y and discards it, leaving [[1 " "] [2 " "] [3 " "]].

Finally,

Y_MUy

That is, yank(map-unpack(_, y)): extract the first element of each sublist and yank the resulting list back into y. y is now [1 2 3].

Length

PODQENaPBs

In pseudocode, pop(dequeue(enumerate(a.push-back(space)))). The difficulty here is that enumerate only gives us numbers up to len(a)-1, but we want len(a). So we first push a space to a, lengthening it by one character, and then take len-1 of the new string.

      a     "xyz"
       PBs  "xyz "
    EN      [[0 "x"] [1 "y"] [2 "z"] [3 " "]]
  DQ        [3 " "]
PO          3

Math

Now that we have a way to take the length of strings, we can use strings to do multiplication and addition of numbers:

PODQENsXaXbPBs
PODQENsXaPBsXbPBs

The first does sXaXb to create a string of a*b spaces and then takes the length of it; the second does sXaPBsXb to push a string of b spaces to a string of a spaces and then takes the length of it.

The nice part is that all the operators we're using here (PU, PO, PB, DQ, EN, X) can be used with _ to form lambda expressions. So we can map mathematical transformations to the inclusive range we constructed earlier.

We also need to check i%2 inside the loop, but this is easily accomplished with bitwise AND: iBA1.

Put them together

The full code, with some added whitespace:

YENsXaPBs POy Y_MUy              Get \,a into y
F i _MUENsXa                     For i in ,a
 I iBA1                           If i%2=1
  P sPUPODQENsXiXaPBsX_PBs M RVy   Print sPUi*a+_ M RVy
 EI1                              Elseif 1 (using E would cause a parsing problem)
  P sPUPODQENsXiXaPBsX_PBs M y     Print sPUi*a+_ M y

DLosc

Posted 2017-03-08T13:57:25.487

Reputation: 21 213

Are we allowed to use flags such as -S? – Brian McCutchon – 2017-03-18T01:06:22.117

@BrianMcCutchon Good question: answer is no. (Since they're not part of the code subject to the regex, it seemed too loophole-ish to use them.) Edited to clarify. – DLosc – 2017-03-18T04:38:16.607

So far I have that a*b is _V_VRVENCGaRLbPU1, ,a is _MUENZGa, aJ" " is aJ_VRVk, and a@i is something like _V_VRVaZCGi, though I can't quite work out the precedence without parentheses yet. Also, a vague idea that I can get the permutations of a range (created as above, using the equivalent of ,(a*a)) and use that to select the correct permutation for each row. – Brian McCutchon – 2017-03-19T03:32:01.613

@BrianMcCutchon I can't comment on any specifics, of course, but I'm really enjoying the progress update. ^_^ – DLosc – 2017-03-19T05:37:42.153

I think it's safe now. How'd you do it? – Brian McCutchon – 2017-03-21T03:58:56.513

@BrianMcCutchon Added code and explanation. You were on the right track in a number of ways, and I didn't even think of using V. But yeah, most of my process was figuring out how to do stuff so that the precedence would work out. I lucked out that PU et al are higher precedence than EN and can be used in lambdas. – DLosc – 2017-03-21T19:31:27.093

@DLosc I had the opposite problem: I was trying to do stuff with yPU_MU... or similar (pushing the result of _MU... to y) and the fact that PU worked with lambdas was pretty annoying. – Brian McCutchon – 2017-03-21T21:26:46.163

My approach was to get a list of ranges of length 1n, 2n, ..., nn, reverse them, then use Z to trim them to the right size and _MU to get rid of the extra stuff added by Z. But the precedence was kind of a deal-breaker. Nice job, and a very detailed explanation. – Brian McCutchon – 2017-03-21T21:34:48.863

3

Mathematica, regex length 11, non-competing, cracked

PCRE flavour:

^[^]@]{49}$

The correct solution will be a function which takes an integer and returns the output as a nested list like:

{{1, 2, 3, 4}, {8, 7, 6, 5}, {9, 10, 11, 12}, {16, 15, 14, 13}}

Martin Ender

Posted 2017-03-08T13:57:25.487

Reputation: 184 808

Cracked http://codegolf.stackexchange.com/a/112863/32353.

– kennytm – 2017-03-14T13:21:12.907

@kennytm Oh, that's a neat solution. Quite different from what I had. I'll see if I post mine later or if I add a more restrictive regex. – Martin Ender – 2017-03-14T13:22:46.397

3

CJam, PCRE, length 8, cracked

^[a-~]*$

Example output for 4:

[[1 2 3 4] [8 7 6 5] [9 10 11 12] [16 15 14 13]]

Lynn

Posted 2017-03-08T13:57:25.487

Reputation: 55 648

Cracked. Nice idea. :) There seem to be quite a lot of approaches that work, I wonder what you had in mind. – Martin Ender – 2017-03-13T10:58:37.810

My answer actually satisfies a tighter regex — I’ll show it when that one gets cracked!

– Lynn – 2017-03-13T11:32:34.200

3

tinylisp, regex length 3 (cracked)

You can test tinylisp code at Try it online!

Regex (any flavor)

\S+

Time to go hardcore.

Output

The solution defines a function that takes a single integer argument and returns a list like this (for n=4):

((1 2 3 4) (8 7 6 5) (9 10 11 12) (16 15 14 13))

My original code uses the same basic idea Brian McCutchon came up with, building lists and eval'ing them. Here it is in one line:

(v(c(h(q(d)))(c(h(q(d')))(c(c(h(q(q)))(c(c()(c(q(arglist))(c(c(h(q(v)))(c(c(h(q(c)))(c(c(h(q(q)))(q(d)))(q(arglist))))()))())))()))()))))(d'(seq-args(c(h(q(start)))(c(h(q(stop)))(c(h(q(step)))())))))(d'(seq(c(c(h(q(accum)))seq-args)(q((i(e(v(h(q(start))))stop)(c(v(h(q(start))))accum)(seq(c(v(h(q(stop))))accum)start(s(v(h(q(stop))))step)step)))))))(d'(f'(c(c(h(q(index)))(c(h(q(size)))seq-args))(q((i(e(v(h(q(index))))size)()(c(seq()start(v(h(q(stop))))step)(f'(a(h(q(1)))index)size(a(v(h(q(stop))))size)(a(v(h(q(start))))size)(s(h(q(0)))step)))))))))(d'(f(q((size)(f'(h(q(0)))size(h(q(1)))size(h(q(1))))))))

I used the full construct-and-eval method once, to define a macro d' that makes definitions like d, but takes its arguments wrapped in a list: so instead of (d x 42), you can do (d'(x 42)). Then it was just a matter of rewriting any lists in the definitions that might need whitespace: (q(a b)) -> (c a(q(b))) -> (c(h(q(a)))(q(b))).

DLosc

Posted 2017-03-08T13:57:25.487

Reputation: 21 213

1Cracked. It wasn't easy. – Brian McCutchon – 2017-03-16T06:46:48.437

3

CJam, PCRE, length 9, cracked

^[a-z~]*$

Example output for 4:

[[1 2 3 4] [8 7 6 5] [9 10 11 12] [16 15 14 13]]

Now {|} are banned, too.

Lynn

Posted 2017-03-08T13:57:25.487

Reputation: 55 648

Cracked. – Martin Ender – 2017-03-13T13:25:58.593

Good job! My answer was basically the same, except it only used a bunch of me and mq to approximate the number, so it was like, extremely (~20k bytes) long. – Lynn – 2017-03-13T17:13:12.900

2

Python3, (PCRE) length 27 (Cracked!)

Regex: ^([^# 0]){115}.{6}(?1){24}$

My first Cops and Robbers submission.

Output format

4:
[1, 2, 3, 4]
[8, 7, 6, 5]
[9, 10, 11, 12]
[16, 15, 14, 13]

Original code: n=int(input());j=0;exec("print([int(i%n+1+(2*n-(2*(i%n)+1))*((((i/n)//1+1)/2)//1)+(2*(i%n)+1)*int(int(i/n)/2))for i in range(j,j+n)]);j+=n;"*n)

Yytsi

Posted 2017-03-08T13:57:25.487

Reputation: 3 582

Cracked in the most loophole-y way possible. – Value Ink – 2017-03-09T02:18:43.190

2

Python3, length 162 (Cracked!)

Regex: ^([^"' #]){24}"(?1){11}i%n(?1){4}2\*n-(?1){4}i%n(?1){10}i\/n(\)\/\/1)(?1){5}(?2)(?1){3}2\*\(i%n\)(?1){4}[int()2\/]{16}for i in range\(j,(?1){4}\]\)(?1){6}\"\*n\)$

Okay, I know, it's quite long. Fortunately, it won't be cracked in under a week... :'D.

I think I didn't make a mistake anywhere, that would allow loophole-y answers.

Output format

4:
[1, 2, 3, 4]
[8, 7, 6, 5]
[9, 10, 11, 12]
[16, 15, 14, 13]

Original code:n=int(input());j=0;exec("print([int(i%n+1+(2*n-(2*(i%n)+1))*((((i/n)//1+1)/2)//1)+(2*(i%n)+1)*int(int(i/n)/2))for i in range(j,j+n)]);j+=n;"*n)

Yytsi

Posted 2017-03-08T13:57:25.487

Reputation: 3 582

Cracked http://codegolf.stackexchange.com/a/112462/32353.

– kennytm – 2017-03-09T21:07:31.420

2

Actually, Python regex of length 193 (safe)

^[^\x00-\x08\x0d-\x13\x16-\x1d\x3f\xa6\xb6\xc1\xe9\xea\xfa\xff]{5}[\x00-\x08\x0d-\x13\x16-\x1d\x3f\xa6\xb6\xc1\xe9\xea\xfa\xff][^\x00-\x08\x0d-\x13\x16-\x1d\x3f\xa6\xb6\xc1\xe9\xea\xfa\xff]{6}$

This regex matches the CP437-encoded program source.

Output for n = 4:

[[1, 2, 3, 4], [8, 7, 6, 5], [9, 10, 11, 12], [16, 15, 14, 13]]

Here is a Python 3 program to help with testing:

import re
pattern = re.compile(rb'[^\x00-\x08\x0d-\x13\x16-\x1d\x3f\xa6\xb6\xc1\xe9\xea\xfa\xff]{5}[\x00-\x08\x0d-\x13\x16-\x1d\x3f\xa6\xb6\xc1\xe9\xea\xfa\xff][^\x00-\x08\x0d-\x13\x16-\x1d\x3f\xa6\xb6\xc1\xe9\xea\xfa\xff]{6}')
code = b'code here'
print(pattern.match(code) and True or False)

Try it online!


Actually, 12 bytes

;²R╡"?R"ß*♀ƒ

Try it online!

Explanation:

;²R╡"?R"ß*♀ƒ
;             duplicate input
 ²R           range(1, n**2+1)
   ╡          split into n-length chunks
    "?R"ß*    "?R"*n
          ♀ƒ  for each chunk: reverse if index is odd (R) else do nothing (?)

Mego

Posted 2017-03-08T13:57:25.487

Reputation: 32 998

2

Scala, length 40, Cracked

Regex (PCRE)

[\w\s]+[\w\(\):]+[\w\(\)<\-\s{=;+*%\.}]+

Output (n=4)

Vector(Vector(1, 2, 3, 4), Vector(8, 7, 6, 5), Vector(9, 10, 11, 12), Vector(13, 14, 15, 16))

Code

def x(y:Int)=for(u<-1 to y)yield{val q=for(z<-1 to y;r<- List(z+(y*(u-1))))yield r;if(u%2==1)q else q.reverse}

Ungolfed

def x(y:Int)=
  for(u<-1 to y)
      yield {
          val q=for(z<-1 to y;r<- List(z+(y*(u-1)))) yield r;
          if(u%2==1)
            q 
          else 
            q.reverse
      }

Soapy

Posted 2017-03-08T13:57:25.487

Reputation: 251

1Cracked! – math junkie – 2017-03-11T01:15:42.563

2

05AB1E, length 22 Cracked by Emigna

This is probably too easy.

Regex (PCRE)

^([E-Z0]*[ˆ>*}<]){7}$

Output

[[1, 2, 3, 4], [8, 7, 6, 5], [9, 10, 11, 12], [16, 15, 14, 13]]

Original Solution

UXL0KVXLˆXGXN>*LYKZL0KVNFR}<>ˆ

mbomb007

Posted 2017-03-08T13:57:25.487

Reputation: 21 944

Cracked – Emigna – 2017-03-10T09:37:34.840

Yup, it was definitely too easy. – mbomb007 – 2017-03-10T15:02:47.153

2

Jelly, length 12 - cracked

cracked by Dennis

^[^ḊḢṚUṖṪ]*$

Python regex (although I think all flavours are valid for this pattern).

That's right, none of those lovely array manipulation atoms!
No:

  • Ḋequeue;
  • Ḣead;
  • Ṛeversal;
  • Upend;
  • Ṗop; or
  • Ṫail;

For an input of 4 mine outputs:

 1  2  3  4
 8  7  6  5
 9 10 11 12
16 15 14 13

...because I formatted a list of lists as a grid with G.

Jonathan Allan

Posted 2017-03-08T13:57:25.487

Reputation: 67 804

you do need ^$ (not a crack) – CAD97 – 2017-03-09T19:54:48.997

Cracked. – Dennis – 2017-03-09T21:11:24.793

@CAD97 The challenge spec says it has to be a full match. – Dennis – 2017-03-09T21:12:02.893

@Dennis oh, right... but then why does anyone have the ^$ – CAD97 – 2017-03-09T21:13:46.500

@CAD97 Because that clarification from the OP postdates the oldest answers, and the newer ones probably just stuck with it. – Dennis – 2017-03-09T21:14:49.823

@Dennis So I didn't need them? Why does regex101 say "full match" when it matches 2 chars? – Jonathan Allan – 2017-03-09T21:17:56.893

1regex101 refers to the full match of the regex, i.e., the whole substring it matches. That doesn't make the rrgex a full match though. – Dennis – 2017-03-09T21:20:55.093

2

Jelly, length 13 cracked

cracked by ais523

[^ḊḢṚUmṖṪVv]*

Python regex (although I think all flavours are valid for this pattern).

An extension of my previously cracked entry:
I have banned modulo indexing, which I missed and Dennis cleverly used;
I have banned use of the two eval atoms, as they'd allow indirect usage of the banned atoms; and
I have removed the start and end match (^...$ since it is redundant since a full match is required).

No:

  • dequeue;
  • head;
  • reversal;
  • U upend;
  • m modulo indexing;
  • pop;
  • tail;
  • V eval; or
  • v dyadic eval

For an input of 4 mine outputs:

 1  2  3  4
 8  7  6  5
 9 10 11 12
16 15 14 13

...because I formatted a list of lists as a grid with G.

Jonathan Allan

Posted 2017-03-08T13:57:25.487

Reputation: 67 804

Cracked. – None – 2017-03-10T00:33:20.810

2

Jelly, length 13 cracked

cracked by Dennis (I forgot to keep m ... another incoming)

[^/P-`vḊ-ṫ€]*

Python regex (although I think all flavours are valid for this pattern).

Severely increased the banned characters from my previous submission:

/ (reduce quick);
from P (product) to ` (monad from dyad quick);
v (eval dyad);
from (dequeue) to (tail); and
(for each quick)

For an input of 4 mine outputs:

 1  2  3  4
 8  7  6  5
 9 10 11 12
16 15 14 13

...because I formatted a list of lists as a grid with G.

Jonathan Allan

Posted 2017-03-08T13:57:25.487

Reputation: 67 804

Cracked. – Dennis – 2017-03-10T01:46:07.837

2

Jelly, 15 bytes, Cracked

Jelly seems to be quite popular in this challenge. So let's require the use of a totally different algorithm. The regex, PCRE interpreted in Jelly's encoding:

[^œŒ]{12}
Çœ?²s

Several PCRE matchers, such as pcregrep and even perl itself, will treat input by default as "unknown 8-bit character set compatible with ASCII"; therefore, they handle Jelly's encoding just fine. (That said, I suspect you need to use perl here as many regex matchers dislike newlines in the middle of the regex. I can't just write it as \n as that's a byte longer.)

Result for an input of 4:

[[1, 2, 3, 4], [8, 7, 6, 5], [9, 10, 11, 12], [16, 15, 14, 13]]

Crack

This ended up being cracked due to a typo in the regex. I'll submit a fixed version.

user62131

Posted 2017-03-08T13:57:25.487

Reputation:

Cracked. – Dennis – 2017-03-10T02:26:46.427

2

tinylisp, regex length 10 (cracked)

You can test tinylisp code at Try it online!

Regex

Any flavor should work the same, we'll call it Python flavor.

[( )1c-s]+

Basically this boils down to, "Solve the problem without using the library." If that turns out to be too easy, I may post a more restrictive one.

Output

The solution is a function that takes a single integer argument and returns a list like this (for n=4):

((1 2 3 4) (8 7 6 5) (9 10 11 12) (16 15 14 13))

DLosc

Posted 2017-03-08T13:57:25.487

Reputation: 21 213

Cracked – kennytm – 2017-03-12T19:39:43.153

2

PHP (Cracked)

Output (n=4)

1       2       3       4
8       7       6       5
9       10      11      12
16      15      14      13

PCRE (length=31)

^.{4}[-"$%&*+:;=?{}a-zMZ]+.{4}$

Here's another take on this challenge, this time using a whitelist approach.

The notable forbidden characters are (), [], _, digits and most of the upper case letters.

Looking forward to see what you come up with!


THE ORIGINAL SOLUTION

This one was simpler. Since parenthesis were forbidden, you couldn't use function calls or language constructs like conditionals and loops which meant the infamous goto was the solution! >:D

  • The only number my solution requires is 1, which I defined as +true.
  • To format the output I used tab and newline characters, generated using bitwise operators on strings: "M" & "+" and "Z" & "*" Start by outputting 1
  • Then, I looped through each number and calculated the difference between each column and it's complement, which I multiplied by 0 for odd rows and 1 for even rows and then added to the original number at that position.

So, for n=4, 5 would originally be on the first column (1) on an odd row.

The difference is -2 * $column + $n + 1 = 3, which means 5 becomes 5 + $difference * $multiplier = 5 + 3 * 1 = 8. So, the first column of row number 2 becomes 8;

A human readable version of my solution is

<?=

$one = $i = 1;
$multiplier = $one - $one;
$n = $argv{$one};

loop:

++$i == $n * $n + $one && die;

$column = $i % $n ?: $n;
$difference = -$column - $column + $n + $one;

print "M"&"+";

$i % $n == $one && print "Z"&"*";

print $i + $difference * $multiplier;

// if not at the end of the row, leave as is
// else convert 0 to 1 and 1 to 0 to apply (or not) the above difference
$multiplier = $i % $n ? $multiplier : -$multiplier + $one;

goto loop

?>

My solution that matches the regex was: <?= $t=$i=+true;$f=$s=$t-$t;$n=$argv{$t};a:++$i==$n*$n+$t&&die;$b=$i%$n?:$n;$m=-$b-$b+$n+$t;print"M"&"+";$i%$n==$t&&print"Z"&"*";print$i+$m*$s;$s=$i%$n?$s:-$t*$s+$t;goto a?>

Ionut Botizan

Posted 2017-03-08T13:57:25.487

Reputation: 71

Cracked http://codegolf.stackexchange.com/questions/112300/robbers-crack-the-regex-make-a-snake/112676#112676 Oh my God. I hate the idea with the goto.

– Jörg Hülsermann – 2017-03-12T03:25:07.250

1

Go, length 17 cracked

Regex, PCRE:

^[^+-<]+.[^+-<]+$

Translated roughly, you can use neither of these characters, except once:

+ , - . / 0 1 2 3 4 5 6 7 8 9 : ; <

The regex matches the full program from package main to func main() which reads from stdin like so: echo 4 | go run snake.go

Output:

[[1 2 3 4] [8 7 6 5] [9 10 11 12] [16 15 14 13]]

Kristoffer Sall-Storgaard

Posted 2017-03-08T13:57:25.487

Reputation: 489

Cracked http://codegolf.stackexchange.com/a/112589/32353

– kennytm – 2017-03-10T18:02:44.997

@kennytm nicely done! – Kristoffer Sall-Storgaard – 2017-03-11T09:03:19.390

1

QBasic, regex length 10 (cracked)

A (hopefully more challenging) variation on my first submission.

Regex

Same as before. Should work in any regex flavor, but we'll call it Python flavor.

([A-Z]+.)+

My solution uses unformatted QBasic; after formatting, the code doesn't match the regex due to added spaces. (But ([A-Z]+ ?. ?)+ still works on the formatted version.)

This time, I'm requiring that a crack work at archive.org, which allows a bit less flexibility in syntax than QB64 does. ;)

Sample output

|1 |2 |3 |4 |
|8 |7 |6 |5 |
|9 |10|11|12|
|16|15|14|13|

(I've used the ASCII pipe character | here, but the similar-looking box-drawing character --code point 179 in the code page that QBasic uses--works just as well and makes the chart look a lot nicer. You can insert it in your code by holding down Alt and typing 179 on the numpad. </funfacts>)


My original solution, prettified (to get the regex to match, replace \n * with :):

CLS

DIM SEP AS STRING
READ SEP
INPUT SIZE
NEGONE=NOT ZERO
ONE=ZERO-NEGONE
THREE=ONE+ONE+ONE
TEN=THREE*THREE+ONE

CLS
FIELDWIDTH=ONE
TMP=SIZE*SIZE
DO
  FIELDWIDTH=FIELDWIDTH+ONE
  TMP=TMP\TEN
LOOP WHILE TMP

FROMVAL=ONE
TOVAL=SIZE
DIRECTION=ONE

FOR ROW=ONE TO SIZE
  COL=ONE
  FOR VALUE=FROMVAL TO TOVAL STEP DIRECTION
    LOCATE ROW,COL
    PRINT VALUE
    LOCATE ROW,COL
    PRINT SEP
    COL=COL+FIELDWIDTH
  NEXT
  LOCATE ROW,COL
  PRINT SEP
  TMP=FROMVAL+SIZE
  FROMVAL=TOVAL+SIZE
  TOVAL=TMP
  DIRECTION=ZERO-DIRECTION
NEXT

DATA|

DLosc

Posted 2017-03-08T13:57:25.487

Reputation: 21 213

It's PCRE. That's also the regex used in most langs. – Matthew Roh – 2017-03-12T15:34:26.750

Cracked http://codegolf.stackexchange.com/a/112889/32353

– kennytm – 2017-03-14T16:17:33.403

1

Racket Intermediate Student with Lambda, regex length 36 20 22, Cracked by kennytm

Produces a function that takes n as input and returns the answer as a list of lists.

Regex (JS)

^((?![nla][peo]|-).)*$

Output

(list (list 1 2 3 4) (list 8 7 6 5) (list 9 10 11 12) (list 16 15 14 13))

Brian McCutchon

Posted 2017-03-08T13:57:25.487

Reputation: 503

Cracked. – kennytm – 2017-03-13T17:35:49.887

1

Racket Intermediate Student with Lambda, regex length 27 22 10 (Cracked)

You can run Racket ISL with Lambda at Try it online!.

Produces a function that takes n as input and returns the answer as a list of lists. The basic idea is that only one-character words are allowed, possibly prefixed with con. Also, besides the con exception, every other character must be non-word. Now let's see if any con robber can crack it!

Regex (JS)

(con|.\W)+

Output

(list (list 1 2 3 4) (list 8 7 6 5) (list 9 10 11 12) (list 16 15 14 13))

Edit 3/14

I've golfed the regex down quite a bit, making it more restrictive in the process. The basic idea of the solution is the same, but since the regex is not equivalent to the previous, I'll count my 7 days starting now. Also, until told otherwise, I'll assume that the answer's requirement for a full match means that ^ and $ on the regex are implied.

Original solution

(λ (n) (((((λ(f) ((λ (x) (x x)) (λ (x) (f (λ (y)((x x)y)))))) (λ (q) (λ(n) (λ(c) (λ(r) (cond [(< c 0)r][(= 1 1) (((q n) (- c 1))(cons(cond [(= 0((((λ (f) ((λ (x) (x x)) (λ (x) (f (λ (y)((x x)y)))))) (λ (r) (λ(a)(λ (b) (cond [(< a b)a][(= 1 1)((r(- a b)) b)])))))c)2))((((((λ (f) ((λ (x) (x x)) (λ (x) (f (λ (y)((x x)y)))))) (λ (r)(λ (s) (λ(e) (λ(t) (λ(a) (cond [(>= (* t s) (* t e)) a][(= 1 1)((((r s) (- e t)) t) (cons(- e t)a))])))))))(+ 1(* c n))) (+ 1(* c n)n)) 1) '())][(= 1 1) ((((((λ (f) ((λ (x) (x x)) (λ (x) (f (λ (y)((x x)y)))))) (λ (r) (λ(s) (λ(e) (λ(t) (λ(a) (cond [(>= (* t s) (* t e)) a][(= 1 1)((((r s) (- e t)) t) (cons(- e t)a))]))))))) (+ (* c n)n))(* c n))-1) '())]) r))]))))))n) (- n 1)) '()) )

Try it online! (Note that the TIO code is slightly different because I've wrapped the solution in (... 4) to call it.)

I picked ISL with Lambda over standard Racket on this and my other answer because I wanted to have short regexes and minimize loopholes. To do it, I started with this:

(define Y
  (λ (f)
     ((λ (x) (x x))
      (λ (x) (f (λ (y) ((x x) y)))))))

(define % (Y (λ (r) (λ (a) (λ (b)
  (cond [(< a b) a]
        [(= 1 1) ((r (- a b)) b)]))))))

(define range1 (Y (λ (r) (λ (s) (λ (e) (λ (t) (λ (a)
  (cond [(>= (* t s) (* t e)) a]
        [(= 1 1) ((((r s) (- e t)) t) (cons (- e t) a))]))))))))

(define g (Y (λ (q) (λ (n) (λ (c) (λ (r)
  (cond
    [(< c 0) r]
    [(= 1 1)
     (((q n) (- c 1))
      (cons
        (cond [(= 0 ((% c) 2))
               ((((range1 (+ 1 (* c n))) (+ 1 (* c n) n)) 1) '())]
              [(= 1 1) ((((range1 (+ (* c n) n)) (* c n)) -1) '())])
        r))])))))))

(define (f n)
  (((g n) (- n 1)) '()))

(Look familiar? I translated this into tinylisp for a certain crack.) Y it the applicative-order Y combinator, taken from this blog post. All functions are curried to make using the Y combinator possible. Then I substituted the function bodies in for each reference to a function and turned f into a lambda. After that, all I had to do was play with spaces so that I could use .\W instead of .\W+ in my regex.

Brian McCutchon

Posted 2017-03-08T13:57:25.487

Reputation: 503

Cracked http://codegolf.stackexchange.com/a/113214/32353

– kennytm – 2017-03-18T08:46:17.923

1

Java 8 (Safe)

Regex (PCRE): 6 Bytes

[^yD]*

Output n=4

Output separated by spaces

1 2 3 4
8 7 6 5
9 10 11 12
16 15 14 13

Solution

The difficulty is getting to System.out without using the letter y. FileDescriptor is also forbidden because of D. Thus, reflection is heavily used to derive System.

class Snake {
  public static void main(String[] args) throws Exception {
    int n = Integer.parseInt(args[0]);
    String[][] ret = new String[n][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        int d = (i % 2 == 0) ? j + 1: n - j;
        ret[i][j] = "" + (i * n + d);
      }
    }
    String stem = "S" + (char)(1 + (int)'x') + "stem";
    String loaderMethod = "get" + stem + "ClassLoader";
    ClassLoader cl = (ClassLoader)ClassLoader.class.getMethod(loaderMethod).invoke(null);
    Class sClass = cl.loadClass("java.lang." + stem);
    for (int i = 0; i < n; i++) {
      String s = String.join(" ", ret[i]);
      ((java.io.PrintStream)sClass.getField("out").get(null)).println(s);
    }
  }
}

Wasmoo

Posted 2017-03-08T13:57:25.487

Reputation: 634

0

Jelly, 16 bytes, Cracked

This is my previous submission with a typo/thinko in the regex fixed.

Jelly seems to be quite popular in this challenge. So let's require the use of a totally different algorithm. The regex, PCRE interpreted in Jelly's encoding:

[^œŒ]{12}
Çœ\?²s

Several PCRE matchers, such as pcregrep and even perl itself, will treat input by default as "unknown 8-bit character set compatible with ASCII"; therefore, they handle Jelly's encoding just fine. (That said, I suspect you need to use perl here as many regex matchers dislike newlines in the middle of the regex. I can't just write it as \n as that's a byte longer.)

Result for an input of 4:

[[1, 2, 3, 4], [8, 7, 6, 5], [9, 10, 11, 12], [16, 15, 14, 13]]

Crack

The crack again rather misses the point of the question, but I'll have to give up on this unless I can find a way to avoid cheating. (The newline and Ç was part of that, but @Dennis simply output via stdout rather than via the return value to avoid the issue. Is it acceptable to force a certain sort of I/O in cops-and-robbers challenges?)

user62131

Posted 2017-03-08T13:57:25.487

Reputation:

Cracked. – Dennis – 2017-03-10T02:41:27.693

0

PHP (Cracked)

start from the command line

php -r <code> <args>

original code

$a=array();foreach($r=range(0,($z=$argv{1})-1)as$g)foreach(($r)as$f)$a{$g}{$f}=$g%2?$g*$z+$z-$f:$g*$z+$f+1;echo(serialize($a));

Regex (PCRE): 18 Bytes

^[$-2:-?a-}]{127}$

Output n=4

a:4:{i:0;a:4:{i:0;i:1;i:1;i:2;i:2;i:3;i:3;i:4;}i:1;a:4:{i:0;i:8;i:1;i:7;i:2;i:6;i:3;i:5;}i:2;a:4:{i:0;i:9;i:1;i:10;i:2;i:11;i:3;i:12;}i:3;a:4:{i:0;i:16;i:1;i:15;i:2;i:14;i:3;i:13;}}

Jörg Hülsermann

Posted 2017-03-08T13:57:25.487

Reputation: 13 026

1Eww what a messy output – kennytm – 2017-03-13T08:40:47.370

1

@StewieGriffin It should clear also in other languages that is it the serializing of an array. http://php.net/manual/en/function.serialize.php I have use this output to short the regex and disallow the underscore totally

– Jörg Hülsermann – 2017-03-13T12:03:34.007

Cracked. – kennytm – 2017-03-13T16:17:20.440

0

><>, length 27 + 1 for single-line mode = 28

Regex (PCRE), using single-line mode :

^(?=(.*\n){3})[^.,\d]{131}$

My program takes the input from the stack with -v, uses no jumps, no digits, no commas and exactly three linefeeds and 131 chars.

Output for n=4 :

1,2,3,4
8,7,6,5
9,10,11,12
16,15,14,13

Aaron

Posted 2017-03-08T13:57:25.487

Reputation: 3 689

0

Ruby (2nd submission)

The outside is mostly the same but my accidenal loophole is more restrictive now. I have many regrets

(\W?\W\w){4}..(?1){2}\W{8}(\w.\w)...\2(?1){5}\w*(?1)(.)\3

It's a lambda. Output is an array of arrays. Example with (n=4):

[[1, 2, 3, 4], [8, 7, 6, 5], [9, 10, 11, 12], [16, 15, 14, 13]]

Value Ink

Posted 2017-03-08T13:57:25.487

Reputation: 10 608

I guess this is safe now :-) – Stewie Griffin – 2019-05-01T08:31:03.440

@StewieGriffin damn, it's been so long that I had to change computers and no longer have the original code. Guess I might give a shot at cracking it myself some day lmao – Value Ink – 2019-05-02T21:12:06.637

0

PHP >=5.4 (Safe)

Original Solution

<?while(+$g<$a=$argv{1})echo(join("\t",$g%2?range($g*$a+$a,$g++*$a+1):range($g*$a+1,$g++*$a+$a))),"\n"?>

start from the command line

php <file> <args>

Regex (PCRE): 12 Bytes

[^ ;#/]{104}

Output n=4

separator is \t

1   2   3   4
8   7   6   5
9   10  11  12
16  15  14  13

Jörg Hülsermann

Posted 2017-03-08T13:57:25.487

Reputation: 13 026

0

PHP >=7.0 (Safe)

Original Solution

<?php while($g<$a=$_GET{0})echo($g%2?"\u{202e}":""),join("\t",array_map($g%2?strrev:trim,range($g*$a+1,$g++*$a+$a))),"\n"?>

Regex (PCRE): 30 Bytes

<\?php [^; >]{32}\\u[^; >]{82}>

Sorry a little mistake the week counts from now

Hint: Use a special unicode Character

Output n=4

separator is \t. Looks like this

1   2   3   4
8   7   6   5
9   10  11  12
16  15  14  13

Output n=4

only copy and paste from the output I use $_GET and the document sents this header Content-Type: text/plain;charset=utf-8

1   2   3   4
‮5  6   7   8
9   10  11  12
‮31 41  51  61

Jörg Hülsermann

Posted 2017-03-08T13:57:25.487

Reputation: 13 026