# Cops: Make a regex - Make a snake

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.

• Seed, length 1, .. – user41805 Mar 8 '17 at 16:04
• Can I use one of the languages documented here? codegolf.stackexchange.com/questions/61804/… – user15259 Mar 8 '17 at 16:09
• @KritixiLithos Except you have to release your original program to become safe ;-) – ETHproductions Mar 8 '17 at 17:50
• @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! – user15259 Mar 8 '17 at 19:48
• Is this meta consensus allowing unary I/O for sed, that has no data types, be valid for this challenge? – seshoumara Mar 10 '17 at 14:42

# 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}ˆ  • oooooomg - dude that's dope (compliment, of course) – Tilak Maddy Mar 8 '17 at 14:49 • @mbomb007: Letters with accent does not match \w no. You can try yourself at regex101 – Emigna Mar 8 '17 at 16:47 • You could make your regex shorter by changing .{0,2} to .?.? – Aaron Mar 8 '17 at 17:13 • You can put the - in last position of the bracketed char class ([+*\/%-]) so you don't have to escape it. – Dada Mar 8 '17 at 21:19 • @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 Mar 8 '17 at 21:25 # 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


• Cracked – xsot Mar 11 '17 at 5:06

# Jelly, length 6, cracked

^.{9}$ ### Sample output  1 2 3 4 8 7 6 5 9 10 11 12 16 15 14 13  • This is forcing to golf really well in Jelly :D – Yytsi Mar 8 '17 at 14:58 • Any nine characters? You're feeling generous! :D – AdmBorkBork Mar 8 '17 at 15:46 • 'Any nine' How many functions were there in Jelly? – Matthew Roh Mar 8 '17 at 16:54 • 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 Mar 8 '17 at 18:35 • @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 Mar 8 '17 at 20:03 # 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  • 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 Mar 9 '17 at 5:03 • @BLT Thanks, it was an interesting problem to try and make difficult. – MickyT Mar 9 '17 at 6:01 • Cracked, though probably not the same code as yours. – plannapus Mar 9 '17 at 9:41 # 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]]  # ><>, 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 • .. is shorter than .{2} ;) – Aaron Mar 13 '17 at 13:18 • 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 Mar 13 '17 at 16:45 • @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 Mar 14 '17 at 5:24 # 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]]  • If 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 Mar 8 '17 at 18:23 • @mbomb007 Good point. – Nick Clifford Mar 8 '17 at 18:27 • Cracked :) – Emigna Mar 9 '17 at 12:46 • @Emigna Well done! – Nick Clifford Mar 9 '17 at 12:51 # 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)asv)s.=str_pad(v,l=strlen(max(r))+1,"\x20",0);echo(chunk_split(s,l*w));  • Please note that answers can use base64_decode because your regex does not disallow it. – CalculatorFeline Mar 9 '17 at 4:26 • @CalculatorFeline: the regex blocks 6, which might block base64_decode. – nneonneo Mar 9 '17 at 6:09 • – kennytm Mar 9 '17 at 13:11 • Oops, missed that. But ^ so it doesn't matter. – CalculatorFeline Mar 9 '17 at 15:29 # 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 _;}  • – kennytm Mar 11 '17 at 11:53 • Well done, I should have tried to make the length more challenging at least... – EklipZ Mar 11 '17 at 20:53 # 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  • So all symbols in the source must be preceded by a letter. – CalculatorFeline Mar 9 '17 at 15:31 • @CalculatorFeline One or more letters. – mbomb007 Mar 10 '17 at 19:21 • 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 Mar 10 '17 at 19:27 • @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 Mar 10 '17 at 21:25 • – kennytm Mar 11 '17 at 16:51 # 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 • It seems for me that you miss the ) in the second part of the regex – Jörg Hülsermann Mar 10 '17 at 20:19 • @JörgHülsermann no nothing is missing, the regex is correct. – kennytm Mar 10 '17 at 20:25 • @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 Mar 10 '17 at 22:39 • @DLosc Now it is clear . Thank You – Jörg Hülsermann Mar 10 '17 at 23:03 • Cracked – xsot Mar 12 '17 at 4:14 # 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.  • 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 Mar 9 '17 at 7:12 • @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 Mar 9 '17 at 7:16 • 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 Mar 10 '17 at 6:46 • @seshoumara Nice job! – Mitchell Spector Mar 10 '17 at 6:56 • @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 Mar 10 '17 at 7:05 # 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  • Cracked codegolf.stackexchange.com/a/112656/32353. This one is nice :D – kennytm Mar 11 '17 at 18:01 • Glad you enjoyed it @kennytm you've found exact solution as my original command! – Marcos M Mar 13 '17 at 12:11 # 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)))))?> • @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 Mar 10 '17 at 21:18 • – Jörg Hülsermann Mar 11 '17 at 12:18 • @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 Mar 11 '17 at 19:19 • @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 Mar 12 '17 at 5:52 • level 2 cracked regex101.com/r/XtVl9G/1 thank you for the hint. Now I am waiting for level 3 :-) – Jörg Hülsermann Mar 12 '17 at 21:26 # 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?) • – kennytm Mar 11 '17 at 12:25 # 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]]  • 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 Mar 8 '17 at 16:43 • @ETHproductions Good point, thanks for the tip! – Tom Mar 8 '17 at 16:44 • Cracked – ovs Mar 8 '17 at 16:46 • @ovs Wow, that was fast. Good job! – Tom Mar 8 '17 at 16:49 • @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 Mar 8 '17 at 17:22 # 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:",")}  • – kennytm Mar 9 '17 at 12:29 • 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 Mar 9 '17 at 21:54 • Note: You may keep the post, since it's already been cracked :) – Stewie Griffin Mar 9 '17 at 22:06 • @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 Mar 10 '17 at 8:43 # 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');}  • You can remove one r in your regex. – kennytm Mar 9 '17 at 17:49 • @kennytm - thanks - missed that one – user15259 Mar 9 '17 at 18:55 • – kennytm Mar 9 '17 at 19:39 # 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. • Cracked. This was a fun one. – Dennis Mar 10 '17 at 2:53 # 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  • Cracked – Matt Mar 10 '17 at 20:13 • What was your solution? – Matt Mar 10 '17 at 21:46 • @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 Mar 10 '17 at 21:50 # 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! • 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 Mar 9 '17 at 9:41 • I do hope the documentation is in English, not Finnish though :) – Stewie Griffin Mar 9 '17 at 9:44 • @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 Mar 9 '17 at 9:50 • Cracked! :) – user41805 Mar 11 '17 at 9:39 # 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  • I believe your answer is now safe :) – Aaron Mar 17 '17 at 13:19 • @Aaron I wonder me that is was not cracked. Original Code is added – Jörg Hülsermann Mar 17 '17 at 13:56 # 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]  # 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  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  # 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  • Are we allowed to use flags such as -S? – Brian McCutchon Mar 18 '17 at 1:06 • @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 Mar 18 '17 at 4:38 • 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 Mar 19 '17 at 3:32 • @BrianMcCutchon I can't comment on any specifics, of course, but I'm really enjoying the progress update. ^_^ – DLosc Mar 19 '17 at 5:37 • I think it's safe now. How'd you do it? – Brian McCutchon Mar 21 '17 at 3:58 # 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]]  • Cracked. Nice idea. :) There seem to be quite a lot of approaches that work, I wonder what you had in mind. – Martin Ender Mar 13 '17 at 10:58 • My answer actually satisfies a tighter regex — I’ll show it when that one gets cracked! – Lynn Mar 13 '17 at 11:32 # 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. • Cracked. – Martin Ender Mar 13 '17 at 13:25 • 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 Mar 13 '17 at 17:13 ## 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}}  • – kennytm Mar 14 '17 at 13:21 • @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 Mar 14 '17 at 13:22 # 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))). # 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)

• – kennytm Mar 9 '17 at 21:07