Significant Whitespace: Robbers

18

This is part of a Cops and Robbers challenge. Go here for the cops' part.

For the purpose of this challenge, we'll define whitespace as only linefeeds (0x0A) and spaces (0x20). Note that most languages and regex flavours consider many other characters as whitespace as well, both inside and outside the ASCII range so you might not be able to make use of the corresponding built-ins.

The Robbers' Challenge

A cop's answer can be cracked by transforming it into a valid program or function (in the chosen language), which performs the task of removing whitespace from an input string, by inserting whitespace into the code. For example if you received the following input:

H e l l o,
 W o r l  d!

The program should output

Hello,World!

After inserting whitespace, the byte count of the solution must not exceed the byte count stated in the cop's answer. You don't have to find the exact same solution as the cop intended, as long as yours is valid by the above constraints.

If you manage this, post an answer with the solution, linking to the cop's answer, and leave a comment on the cop's answer linking back to yours.

The robber who cracks the most cop answers wins. Ties are broken by the sum of sizes of the cracked cop answers (in favour of the robber who cracks longer submissions).

Each cop answer can only be cracked once, and of course, you're not allowed to crack your own answer. If the cop's answer turns out to be invalid before or after being cracked, it is not counted towards the robber's score.

Martin Ender

Posted 2016-12-14T19:32:48.610

Reputation: 184 808

Answers

8

Haskell, 100 bytes, by Laikoni

main=interact$id doid lines id words 
doid oi d o id=do
 iddoid<-do oi id
 oid<-do o iddoid
 do d oid

nimi

Posted 2016-12-14T19:32:48.610

Reputation: 34 639

7

><>, 40 bytes, by DanTheMan

v <<
i/\
:=
:
:a?
0/>/
1?o
-=
="
?
;"
>^

Really fun to work out.

Try it on ><>language

Teal pelican

Posted 2016-12-14T19:32:48.610

Reputation: 1 338

Good job! I'm glad you enjoyed cracking it. – DanTheMan – 2016-12-15T16:45:58.020

7

JavaScript ES6, 199 bytes by Arnauld

s=>eval(atob`ISYgJiAtOkI8Qk97BRBeaxZFShoUZSsiOGkMenNy`.replace(/./g,(c,i)=>String.fromCharCode(c.charCodeAt()^(k+="     S    e c  r   e t     C    o   d  e   ".split(/\w/)[i%11].length)),k=0)).join``

I realized the splitting "SecretCode" meant I was looking for 11 numbers that summed to (I assumed) 33. This is a stars and bars problem where the number of spaces are the stars and the letters in "SecretCode" were the bars. I did the math to see how many combintations there were to try (1,917,334,783 combinations) and decided to just brute force it, took all day.

There's probably a smarter way to have gone about it, for instance noticing that k has to be 33 and 66 for index 10 and 21 respectively, but I'm lazy.

SLuck49

Posted 2016-12-14T19:32:48.610

Reputation: 901

Hey, well done! ;-) – Arnauld – 2016-12-17T00:44:28.300

2$/**/=/[ \n]/;s['sp'+'lit']($)... oh, that's dirty. – Patrick Roberts – 2016-12-17T00:46:49.473

In case anyone was curious about my brute force attempt, it was http://pastebin.com/aN9Z1jVM

– Patrick Roberts – 2016-12-17T01:02:54.677

6

C, 475 bytes by rexroni

#include<unistd.h>
#define a char
#define b *
#define c write
#define d stdin
#define e stdout
#define f read
#define g (
#define h )
#define i while
#define j if
#define k 0
#define l &
#define m ,
#define n =
#define o ;
#define p 1
#define gpml ml h
#define abo
#define ml d m p
#define jg d o abo
#define lb abo d
#define gf h abo c
#define jgm b e n
#define pml f g
#define gpm lb
int main(){a jg a jgm l jg i g pml k m l gpml h j g d!=' '&&gpm!='\n'gf g p m l gpml o}

I might start using some of these defines :)

After the pre-processor the code looks something like this:

int main(){
    char stdin;
    char *stdout = &stdin;
    while(read(0, &stdin, 1))
        if(stdin !='' && stdin!='\n')
            write(1, &stdin, 1);
}   

Riley

Posted 2016-12-14T19:32:48.610

Reputation: 11 345

Wow! Good work. I was even having trouble reading it by the end, and I wrote it. – rexroni – 2016-12-15T18:38:43.960

@rexroni #defineabo threw me off for a while. At first I thought it had to be #define ab o which would just add some extra ;s, but that didn't work near the end. – Riley – 2016-12-15T18:42:46.693

yes, that was specifically chosen to make it harder :) – rexroni – 2016-12-15T18:46:31.460

5

Ruby, 86 bytes + 1 flag = 87 by histocrat

eval"( T $ }{(! // ; : 67 8 ? 32. && )".gsub(/ |(.)/){$1&&$&.ord.^($'.count(' ')).chr}

This was really fun, each character in the string passed to eval is replaced with the character code (ord) XORed ^(...) against the number of remaining spaces in the string. The resultant code is:

$_.tr!(''<<32<<10,'')

Dom Hastings

Posted 2016-12-14T19:32:48.610

Reputation: 16 415

4

RprogN, by Ataco

This appears to do the trick

' ' ` R
"
" ` R

MickyT

Posted 2016-12-14T19:32:48.610

Reputation: 11 735

I accidentally golfed it while cracking haha, down to 14 bytes – Alfie Goodacre – 2016-12-14T22:33:21.120

I'm really curious how you golfed it. – ATaco – 2016-12-14T22:54:37.287

@ATaco the program is just 14 bytes. Did you count a trailing linefeed or something? – Martin Ender – 2016-12-14T23:08:42.757

Looks like 15 bytes to me – ATaco – 2016-12-14T23:23:40.390

@ATaco I was wrong, I couldn't test newlines on the compiler online, which in turn caused me to think it was working but I had removed the lf literal – Alfie Goodacre – 2016-12-15T10:43:36.153

4

V, 37 bytes, by DJMcMayhem

O     VrS200@"kIi|D@"A üî|D@"

Unprintables:

O     <esc>Vr<C-a>S200<esc>@"kIi<C-v><C-v><esc>|D@"<esc>A üî<esc>|D@"

TryItOnline

The ü really threw me for a loop, I kept expecting both it and î to be commands.

O                 # Insert 5 spaces above this line
Vr<C-a>           # Change them all to <C-a>
S200<esc>         # Replace the line with 200
@"                # Play back the 5 <C-a>'s, 200 -> 205
k                 # ????
Ii<C-v><C-v><esc> # insert "i<C-v>" so our line is now "i<C-v>205"
|D@"<esc>         # Delete the line and then run it, which inserts "Í" (ASCII 205)
A üî<esc>         # Append " üî" so our line is "Í üî"
|D@"              # Delete the line and run it

Í üî in V translates to :%s/ \|\n//g in vim, which globally removes all whitespace. The Í command is on the wiki, and the ü and î are | and n respectively with their high bit set

nmjcman101

Posted 2016-12-14T19:32:48.610

Reputation: 3 274

Good job! That's the exact solution I had. :) – James – 2016-12-15T15:43:27.863

3

C, 140 bytes by betseg

#include<stdio.h>
int main(){int a=getchar();while(a!=EOF){//\a=getchar();
if(a!=10&&a!=32)//\\putchar(a^10^32);
putchar(a);a=getchar();}}

(I also hope I'm doing this right.)

Riley

Posted 2016-12-14T19:32:48.610

Reputation: 11 345

Ninja'd me by one minute! – user41805 – 2016-12-14T20:16:31.157

@KritixiLithos Same, was just about to submit when this anwer popped up ^^ – Denker – 2016-12-14T20:17:43.267

3

MATL, 22 bytes by Luis Mendo

Though I can't be sure why, this seems to work

t' @ * 'dm1e5%M
dw%Y
(

I'll have to see if I can work out what it's doing. I figured that the comments had to have line feeds after them and then it was just a matter of getting the spaces in the correct spots.

MickyT

Posted 2016-12-14T19:32:48.610

Reputation: 11 735

Nice, +1 I added a partial explanation in my answer :) – Stewie Griffin – 2016-12-16T19:27:28.567

1@StewieGriffin, thanks for the explanation. I was trying to work why it worked, but it was going slowly. Very comprehensive docs Luis:) – MickyT – 2016-12-16T19:31:51.763

1@MickyT You mean verbose like Java :-P Nice cracking work! – Luis Mendo – 2016-12-16T19:47:09.710

3

MATL, 22 21 bytes by Luis Mendo.

Finally... MickyT cracked it while I was writing an explanation, so his answer is the "valid" one. I posted this anyway, in accordance with this meta post.


M and Y are unnecessary and are commented out. It's enough to add 4 whitespace characters, not 5.

t' @ *'dm1e5%M
dw%Y
(

This is equivalent to the more compact:

t' @ *'dm7dw(

Partial explanation:

         % Implicit input
t        % Duplicate input
' @ *'   % String with ASCII-values [32   64   32   42]
d        % diff, giving [32  -32   10], 32 is space, 10 is newline
m        % ismember, checking if the character is 32 or 10
1e5      % 10000, but could just as well be 7
d        % Taking the diff of the scalar 1e5, returning an empty matrix []
w        % Swap stack in order to use ( below
(        % Equivalent to x(y)=[], where x is the input string, and y is the logical
         % vector found using ismember (m)
         % Implicit output

Stewie Griffin

Posted 2016-12-14T19:32:48.610

Reputation: 43 471

Nice cracking work! – Luis Mendo – 2016-12-16T19:47:39.993

2Thanks :) I knew nothing about MATL before I started... I guess my explanation is not entirely correct (but should be fairly close?). It took me a long time, since the 1e5 either printed 100000, or 1e was a call to reshape, but then what was 5? (I see now that the % is in the end of the line, so it would be 5M, not a five and an M. Also, I thought I had to have Y( on one line. All in all, a very nice MATL tutorial :) – Stewie Griffin – 2016-12-17T22:10:26.350

The explanation is totally correct :-) Yes, it's a good (if only a little hard) way to start with a language – Luis Mendo – 2016-12-18T01:07:53.567

2

C#6, 201 bytes, by milk

using System.Linq;
_=>string./**/
#if trueJoin
(/*"*//*/""/**//*/"*/",
#else
Concat(//*/,
#endif
from m in" "let p=$@"{@" 
"[1]}"from i in(_.Replace(p,@""))where!new[]{p[0]^32^10}.Contains(i)select@i);

repl.it demo

trueJoin is not defined, so only string.Concat() remains.
p is "\n". p[0]^32^10 is space. It would have been (a bit) more difficult if it's p[0]^42 or other similar constants.

Link Ng

Posted 2016-12-14T19:32:48.610

Reputation: 593

As commented on milks answer this needs C# 6+, if they change it can you too? – TheLethalCoder – 2016-12-15T15:34:18.463

2

Befunge-98, 65 bytes by ninjalj

~v       >#@
 >::':'0--\'[';--!8v1+!
*1+j  !j,v         >#@

Try it online!

This was a lot of fun. I deduced that since there are few direction-changing commands and no ^<[]?x or similar, it has to use wrapping. I then wrote a Python script to help with getting the spacing right for the j's.

The code works by taking input (~) and duplicating it twice (::). It then subtracts 10 (':'0 or ord(':') - ord('0')) and 32 ('['; or ord('[') - ord(';')). Then, the second result is logically negated (1 if was space, 0 otherwise) and an 8 is pushed.

Now comes the part that needed figuring out what to skip. The 1+! is skipped by continuing to the next line. # skips the @. The logically negated result (0 or 1) is multiplied by the 8, and 1 is added.

The code then jumps that many (i.e. 1 or 9) spaces plus one extra as the IP moves. If the character wasn't a space it ends up at the !. The character code minus 10 is logically negated (1 if was newline, 0 otherwise). j then skips nothing, and the print (,) is called and the loop resumes by wrapping vertically.

If the character was a space, the bottom line loops again with 32, 22 as the bottom of stack. The first j jumps 705 spaces. Then the line loops a third time. If there are more than two 10's left on the stack (the code only leaves those), the first j jumps 100 spaces and the loop repeats. Otherwise, the first j jumps to the !, a zero is negated, the second j jumps over the print and the program continues.

I managed to golf it down to 59 bytes.

PurkkaKoodari

Posted 2016-12-14T19:32:48.610

Reputation: 16 699

Listing the number of the cop in your header is fine (since the tiebreaker rewards larger sizes anyway). – Martin Ender – 2016-12-15T13:48:14.143

2

reticular, 43 bytes, by Conor O'Brien

ISBqv<>>$$4j
E :d/v$v?
c+91d/ v?E
;!?l$/o $

Try it online!

This was more difficult for me than it should have been because I was too stupid to find the documentation and ended up having to guess how some of the commands worked. So some of this explanation may not be entirely accurate, but this was my basic understanding of the code.

I               Push all the input on to the stack as a string
 S              Convert it into a character array.
  B             Turns that array into individual characters on the stack.
   q            Reverse the stack so the first letter is on top.
    v           Move down... 
    /           ...and turn left.
E :d            Duplicate the value and test if equal to space.

       v?       If it is a space we move down until we wrap to the top.
       >$$      Drop the test result and the space.
          4j    Jump over the next 4 commands (having wrapped to the start).
    v           Bringing us back to the first down arrow, ready to test the next char.

     v$         If it wasn't a space, drop the test result and move down.
c+91d/          Turn left and push a newline (char 10) on to the stack.
       v?E      If equal, we go down, following the same path as with the space.

     /          If not equal, turn down.
   l$/          Then turn left, drop the test result, and push the stack size.
;!?             If zero (the stack is empty) we terminate.
        o$      Otherwise wrap around, drop the stack size, and output the char. 
     /          Then turn down wrapping around to the top of the program.
    v<          Then turn left and down to start the process from the beginning again.

James Holderness

Posted 2016-12-14T19:32:48.610

Reputation: 8 298

There's docs on the github wiki. – Conor O'Brien – 2016-12-18T05:43:10.353

good idea! And impressive that you did this without the wiki :D – Conor O'Brien – 2016-12-18T15:18:15.587

1

C#, 159 bytes by LethalCoder

using System.Linq;s=>string.Join("",string.Join("",s.Split(@" 
".Replace(new string((char)0x0D,1),"").ToCharArray())).Select(c=>c+""!=""?c+"":"").ToArray());

repl.it

The string at the end of line 1 is " \n" (space+newline).

/*Func<string, string> Lambda =*/ s =>
    string.Join("",                                                           // No-op
    string.Join("",                                                           // Join (without whitespace)
        s.Split(@" \n".Replace(new string((char)0x0D,1),"").ToCharArray())    // Split on whitespace
    ).Select(c=>c+""!=""?c+"":"").ToArray());                                 // No-op

milk

Posted 2016-12-14T19:32:48.610

Reputation: 3 043

1

Minkolang v0.15, 88 bytes by Kritixi Lithos

$oI[dd" "=$r'10'=1J,? 1R]r$O3.14
$$$
Cdollars             >
$$$
Ceverywhere           >x

Explanation

                               # Layer 1
$o                             # input chars onto stack
  I                            # stack length pushed to stack
   [                    ]      # loop popped TOS times (length of string)
    dd                         # duplicate, duplicate
      " "                      # push space to stack
         =                     # equality check
          $r                   # swap
            '10'               # number 10 to stack (LF char)
                =              # equality
                 1J            # or
                   ,           # not
                    ?          # if true jump next
                               # drop to layer 2
                      1R       # rotates the stack 1 time
                         r     # reverse the stack
                          $O   # output the stack
                             . # stop
$$$                            # Layer 2
                     >         # shift right and then drop to layer 3
$$$                            # Layer 3
                      >x       # shift right, pop char off stack and drop to Layer 1 (end loop)

MickyT

Posted 2016-12-14T19:32:48.610

Reputation: 11 735

Well done in cracking it! I was hoping the Comments would be confusing, but nice job nevertheless! – user41805 – 2016-12-18T21:53:53.917

@KritixiLithos to be honest once I split the layers and realised that most of the work was done in the top layer, it became easier. I learnt a bit about the language doing this, so thanks :) – MickyT – 2016-12-19T01:12:48.330