Find the Needle in the Haystack (Robbers)

18

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

The Robbers' Challenge

A cop's answer can be cracked by removing any subset of characters from the Haystack program, so that it outputs Needle instead of Haystack (while still being a valid submission in the same language). 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.

Examples

Here are a couple of simple examples in different languages:

Ruby

Haystack: puts 1>0?"Haystack":"Needle"
Delete:        XXXXXXXXXXXXXXX
Needle:   puts "Needle"

Python 2

Haystack: print "kcatsyaHeldeeN"[-7::-1]
Delete:          XXXXXXXX        XX
Needle:   print "eldeeN"[::-1]

Note that the subset of removed characters doesn't have to be contiguous.

Martin Ender

Posted 2017-10-07T14:14:40.300

Reputation: 184 808

If robber use hashing, encryption or random number generation is it allowed?(though possibility tiny) – l4m2 – 2017-12-15T18:57:46.300

Answers

11

JavaScript, 85 bytes (ES6)

Cracks Arnauld's answer

f=(k=b=x=35)=>x--?f(k*4853461&268435455):k&2?'N'+(k^12408877).toString(b):'Haystack'

"Needle" demo

f=(k=b=x=35)=>x--?f(k*4853461&268435455):k&2?'N'+(k^12408877).toString(b):'Haystack'

console.log(f())

Explanation

The original function was:

f=(k=b=x=35)=>x--?f(k*74837258394056219&268435455):k&2?'N'+(k^124038877).toString(b):'Haystack'

which is more readable as:

f = (k=b=x=35) => {
    if (x--) {
        return f(k*74837258394056219&268435455);
    } else {
        if (k&2) {
            return 'N'+(k^124038877).toString(b);
        } else {
            return 'Haystack';
        }
    }
}

Note that when n=21625674, then n.toString(35) is 'eedle'.

The 35 in the input probably cannot be changed to a subset (because we want a base large enough to contain all the letters 'del', so we need a base that's at least 22). So the numbers to change are 74837258394056219, 268435455, and 124038877. We want to replace them with numbers a, b, c, each formed with a subset of the digits of the original numbers, such that the function g(k) = (k * a & b), starting with k=35 and iterated 35 times, and then XORed with c, gives 21625674.

For this one, after thinking a bit, as the lengths are small (the maximal a has length 17, b and c have length 9), I just used brute-force :-) Wrote a C++ program to generate all possible numbers a, b, c formed as subsets of the original numbers, iterate through all a and b, and check whether the required c was in the set. Runs in about 15 seconds, and the only output is a=4853461, b=268435455, c=12408877 (turns out the number b doesn't need to be changed). I'm not sure whether there's a more clever way of inverting this function.

ShreevatsaR

Posted 2017-10-07T14:14:40.300

Reputation: 923

5

Haystack, 82 bytes

Cracks HyperNeutrino's Answer

0\1-c\
/    
?10F17+c8F+4+cd8F+3+c6-c1+c,c2+c8+c|
 0   \1++c,c|
F/c++2F8
c\8F+2+cd

Try it online!

fireflame241

Posted 2017-10-07T14:14:40.300

Reputation: 7 021

1Nice! The way I had it set up, my original solution was to literally just remove the 0 at the beginning :P Nice to see another approach though! +1 – HyperNeutrino – 2017-10-07T16:29:18.870

5

Brain-Flak, 96 bytes

Cracks Funky Computer Man's answer.

([((((()()())){}){}){}](()[()]({}([(((()()()){}))[]])[]({}({}()(((()(({}){}){}){}){}())))[]))())

Try it online!

This was a fun challenge.

The -24 at the beginning which converts y to a in the original is now used to convert e to M, which is then converted to N in place by changing the entire end loop to ()). The first pushed letter k was changed to e simply by removing a push-pop that adds 6 to it. The rest mostly just fell into place, with some humorous missteps along the way (including one program whose output was Meddle).

Comparison of the two programs:

Haystack: ([((((()()())){}){}){}](()([()](()({}([((((()()()){})))[]])[]({}({})[{}]()({}((()(({}){}){}){}){}())))[][][][][][]))[]))(((()[]){}){({}[()()])}{})
Needle:   ([((((()()())){}){}){}](() [()]   ({}([ (((()()()){})) []])[]({}({}     ()(  ((()(({}){}){}){}){}())))[]              ))   ()  )

Nitrodon

Posted 2017-10-07T14:14:40.300

Reputation: 9 181

I was sure that it would end like this

– H.PWiz – 2017-10-07T21:05:29.480

That certainly works, but I had somehow convinced myself that N was 77 instead of 78, so I didn't catch it.

– Nitrodon – 2017-10-07T21:32:16.337

Yours is shorter anyway. – H.PWiz – 2017-10-07T21:38:46.050

Interesting solution! I've added my intended solution to the original post if you would like to see it. – Post Rock Garf Hunter – 2017-10-09T22:22:56.527

5

Haskell

Cracks @Laikoni's answer.

s=map;hay=zipWith;a=head;h=s a.(hay(scanr id).s a<*>s(succ<$))$words"Haysta ayst ackH ays k ayst"

Try it online!

Original code:

hays=map;hay=zipWith;stack=head;h=stack{-
 hay.(hays.(stackany hay$or id).stack hay
<*>hays(sum$stack haystack<$>hay))-}$words
 "Haystack Hayst ackH aysta ckH aystac k"

replacing removed characters with underscores:

___s=map;hay=zipWith;__a__=head;h=s______
 _a_.(hay__(s__c_an_______r id).s____ _a_
<*>___s(su_____c________c_<$____))__$words
 "Haysta__ _ayst ackH ays__ _k_ ayst____"

How Needle is constructed: the string at the end of the code is split into words. The first char of each word is incremented as many times as there are characters in the word, e.g. Haysta -> H plus 6 chars -> N.

nimi

Posted 2017-10-07T14:14:40.300

Reputation: 34 639

5

Hexagony, 17 bytes, H.PWiz

];N@cl;e;;(\.s.;_

Try it online!

Comparison with original:

];N.@cl;e@;;(\H/;ya;_.>s.;t//<._  original
];N @cl;e ;;(\       . s.;     _  modified

Visualisation:

  ] ; N
 @ c l ;
e ; ; ( \
 . s . ;
  _ . .

Explanation

Bonus marks - uses all 6 IPs and all but one of the cells!

Coloured paths

The IP #0 starts by heading right along the black path into the ].
We then transition to IP #1, which heads along the red path, printing N with N; then wrapping back into the ] again.
We then transition to IP #2, which heads along the blue path, storing e in the current memory cell, then along the green path, executing (with a reflection at \) ;;(; which prints ee, decrements the memory cell from e to d then prints d.
The IP continues along the orange path, executing Nl;se which prints l, and stores e in the current memory cell. It continues along the brown path, printing the e with ;. By this point we have already printed Needle, so the rest is just finishing. The IP stores c, then hits ].
Coloured paths 2
We then transition to IP #3, which heads along the blue path, hitting \, bouncing into _ which bounces into ].
We then transition to IP #4, which heads along the green path, bouncing on _, then \ and branching to ] (since c is positive).
Finally, we transition to IP #5, which stores e then exits with @.

boboquack

Posted 2017-10-07T14:14:40.300

Reputation: 2 017

Nice! That was the intended solution. – H.PWiz – 2017-10-19T05:54:48.317

4

Python 2, 123 bytes

Cracks agtoever's Answer

import numpy
print "".join([dir(numpy)[int(i)][0] for i in numpy.poly1d([-143/2e1,-31,14,131,61,184])(numpy.arange(-3,3))])

repl.it

Comparison:

print "".join([dir(numpy)[int(i)][1-0] for i in numpy.poly1d([-1*1433/252e1,-3232/1920.,4026./72/2/3.,613/(6*4.)*1,-4723./1.8e2,-9763/120.,-2689/(-1+5*17.),1+138*.4*2])(numpy.arange(-12/3,13%9))])
print "".join([dir(numpy)[int(i)][  0] for i in numpy.poly1d([-1  43 /2  e1,-3    1    ,               1     4    ,       1         3 1   ,  6     1       ,1   8  4  ])(numpy.arange(-   3, 3  ))])

I had a lot of fun finding solutions that printed Meedle and Needlf by fitting a polynomial to the median of the indices of the numpy symbols that start with each of the letters in Needle. I then tried to find similar coefficients with subsets of the original program by hand, but I ended up having to resort to brute forcing one to find a valid solution.

jacobly

Posted 2017-10-07T14:14:40.300

Reputation: 881

Wow! Great job! I didn’t expect it to be cracked that soon. – agtoever – 2017-10-09T12:31:17.387

I originally developed the challenge based on numpy 1.13, which I didn’t find in any repl environment, so I had to rewrite it for numpy 1.12... ;-) – agtoever – 2017-10-09T12:33:28.857

2

Javascript, 91 bytes

_=>(+{}+[])[+[]]+([][[]]+[])[3]+([][[]]+[])[3]+([][[]]+[])[2]+(![]+['t'])[2]+([][[]]+[])[3]

Cracks this. It actually was fun.

let f =

_=>(+{}+[])[+[]]+([][[]]+[])[3]+([][[]]+[])[3]+([][[]]+[])[2]+(![]+['t'])[2]+([][[]]+[])[3]

console.log(f())

my pronoun is monicareinstate

Posted 2017-10-07T14:14:40.300

Reputation: 3 111

2

Jelly, 14 bytes

Cracks Jonathan Allan's Answer

“¡#ɦṢÞɠ»ḟ“¡pṄ»

Try it online!

Comparison:

“¿ọ⁽ṅ*FỊ⁼g£¡#!ʋzoɦṪ£ṢÞḲÐɠ`”m3⁾“»jVḟ“¡!pṄ»
“          ¡#    ɦ  ṢÞ  ɠ      »  ḟ“¡ pṄ»

I used œc to iterate through various subsets of the literal strings, used tr -d for each possible filter, and greped for Needle. Using the assumption that none of the used characters in the first string were used in the answer let it find an answer in under 15 seconds.

jacobly

Posted 2017-10-07T14:14:40.300

Reputation: 881

Exactly the one I had in mind Nebbed+ruble without any of rub. – Jonathan Allan – 2017-10-08T19:09:16.930

2

Python 2, 73 bytes

Cracks user71546's Answer.

a,b,s=2707385038437,0b10000000,""
while a>0:
 s=chr(a%b)+s
 a//=b
print s

Try it online!

Solved with this program.

jacobly

Posted 2017-10-07T14:14:40.300

Reputation: 881

2

Java (OpenJDK 8), 191 bytes

Cracks Luke Steven's answer

String d(){int h=3905055,m=55,s=15443;String d="0"+h*2+""+m*20+""+s*7,x="",y;for(int g=0;g<d.length();g+=3){y="";for(int e=0;e<3;e++)y+=d.charAt(e+g);x+=(char)Integer.parseInt(y);}return x;}

Try it online!

Deleted chars:

int h=3609000-5055+911,m=557558,s=15441301-157*10000
       xx  xxx    xxxx     xxxx       x xxxxxxxxxxxx

This makes d evaluate to 078101101100108101, which spells Needle.

milk

Posted 2017-10-07T14:14:40.300

Reputation: 3 043

2

Ruby, 149 bytes

Cracks this: https://codegolf.stackexchange.com/a/144790/74216

Module was quite small, so I wrote a multi-threaded birthday thing and hoped for the best.

Edit: And after that found an even shorter answer.

x='hxDKFQOoqJLuVNW'
s="n=x.to_i 36;x.bytjs.jach_cons(3){|a,b,c|n+=n*b%c;n*=a^b};puts n%8675309==1388649 ?'Njjdlj':'Haystack'"
eval s.tr ?j,s.size.chr

Try it online!

Changes:

x='yGwztsPXhxDkBKlCYdFjQnpUROfoHvqmTgbaJSLcEiZrIAuMVNW'
x='        hxD  K    F Q    O o  q     J L       u VNW'

# and here's some more variants for extra pwnage:
x=' G  tsPx     KlCYd  Qn U   o v mT  a SLc    I u  NW'
x='  w  s    D BKl  dF QnpU O        ba SLcEiZrI  MV  '
x='yGwz s Xh Dk K C  F  npU O  Hvq   b   L    rIAu V W'

cab404

Posted 2017-10-07T14:14:40.300

Reputation: 141

2

dc, 34 bytes

93 9 2*+432212+ 47*4242160 7 2++*P

Cracks this. TIO.

I started by getting the numerical representation of Haystack (5215583380252484459) and Needle (86197399743589). Next, I did a factorisation of the latter, which is 47*432323*4242169. From this, it was quite easy to reconstruct those numbers.

Marking the characters used:

6 93 3 9 2 2**+*+483622 1 2 3 3*+3*+89 47*+*+3 5 2* 269 158 9**107 97*2 4*++2 3 3*+42 14 2**+*+5*+5 2148 1 6 2*+*+68262 5 280 7 2 3 3*+5 2**+*+*+*+P
  XXX  XXX   XX  X X XX X X     X     XXXX                              X   X      XX X                    X                XXXXX     X     XX     X

agtoever

Posted 2017-10-07T14:14:40.300

Reputation: 2 661

gg! i knew that putting that much numbers was a bad idea) – cab404 – 2017-10-11T19:52:08.830

@cab404 Just curious: did you use a very different calculation to get to 86197399743589? – agtoever – 2017-10-11T19:56:19.587

yeah, it is a lot longer

– cab404 – 2017-10-11T20:00:52.513

Wow. That’s remarkable. That might be another codegolf question: how many ways are there to get a certain result by deleting characters in an expression... – agtoever – 2017-10-11T20:05:51.917

i guess that would generally require some serious math to calculate all the posibilities and prove that there's only that number of them) – cab404 – 2017-10-11T20:49:40.897

2

Hexagony, 19 bytes, Martin Ender

[@;(...e<l.a;./;N>;

Try it online!

Comparison with original

H[@;(...e<l.a;./$.>;\sN;\ac.>).;;;._y
 [@;(...e<l.a;./   ;  N     >  ;

Unfolded code

  [ @ ;
 ( . . .
e < l . a
 ; . / ;
  N > ;

So, I've never written anything in Hexagony, but I figured with only 37 bytes that I could come up with the crack. Martin, I hope you know I put a lot of time into trying to figure this out. :)

I may be incorrect, but I will explain what I think this code is doing:

The program starts off with [, which automatically moves to IP #5. This IP starts in the west corner, heading toward the [ once again, which moves it to IP #4. From here, it executes N;e then heads to the southeast corner and executes ;, bounces to the right for another ; then wraps to ( which decrements the current e to a d. It then continues (with a wrap) to ...;. then bounces to the l and gets to the [ one last time, moving to IP #3. It executes ;, > redirects to the northwest to . then < redirects to the west, hitting e, wrapping to ;, and terminating on the @.

Verbose version

[   We move to the previous instruction pointer (starting at the e and moving NE)
e   e is entered into the current memory cell
(   Decrements the memory cell to d
[   We move to the previous instruction pointer (starting at the N and moving NW)
N   N is entered into the current memory cell
;   Outputs N
e   e is entered into the current memory cell (IP now wraps to the SE corner)
;   Outputs e
/   Mirrors IP to the east
;   Outputs e (IP now wraps to ( on NW edge)
(   Decrements the memory cell to d
... No-ops (IP now wraps to ; on SW edge)
;   Outputs d
.   No-op
/   Mirrors IP to the NW
l   l is entered into the current memory cell
.   No-op
[   We move to the previous instruction pointer (starting at the ; and moving west)
;   Outputs l
>   Redirects the IP NW
.   No-op
<   Redirects the IP west
e   e is entered into the current memory cell (IP now wraps to ; on the NE corner)
;   Outputs e
@   Terminates the program

I am so glad that you used a normal hexagon size for the Needle program; I was checking size 19 programs (for a length-3 side hexagon) when I realized you could remove any number of characters and it would automatically fill the hexagon with .s at the end, which would make it dramatically more difficult to crack. As it is, Hexagony is an evil language for this challenge because (mostly) any character that is removed changes the whole execution path of the program. That being said, I enjoyed trying to come up with this, even if I did end up brute forcing it at the end. :)

Jo.

Posted 2017-10-07T14:14:40.300

Reputation: 974

If I've messed up/missed anything, please let me know. – Jo. – 2017-12-15T07:08:30.587

Nice work, this looks pretty accurate. I'll compare it with what I had originally over the weekend. – Martin Ender – 2017-12-15T07:20:43.107

1

Java (OpenJDK 8), 151 bytes

Cracks Kevin Cruijssen's Answer

v->{String h="H";int x=7;return new String(new byte[]{(byte)((-~-~-~-~-~-~1^x++*x)+15),new Byte("10"+h.length())})+new StringBuffer("elde").reverse();}

Try it online!

Comparison:

v->{String h="Haystack";int x=-7;return x<0?h:new String(new java.math.BigInteger(new byte[]{(byte)((~-~-~-~-~-~-~-~-~-~1^-x++*x)+151),new Byte("2"+"1+\"0+\"".length()+(x=h.length()*4/x)+"-x-7")}).toByteArray())+(new StringBuffer("hidden".substring(++x%3^4,--x-x--).replaceFirst("dd","e"+(char)(x*211%+93))).reverse());}
v->{String h="H       ";int x= 7;return       new String(                         new byte[]{(byte)(( -~-~-~-~-~-~      1^ x++*x)+15 ),new Byte("    1   0  "          +   h.length()    )        })               + new StringBuffer("    e                                 l          d    e"      )             .reverse() ;}

I feel like the last part wasn't intended.

jacobly

Posted 2017-10-07T14:14:40.300

Reputation: 881

Lol ok, that's a smart way to make "edle". While fiddling around I already thought I did a bit too much and loads of solutions would be possible.. ;) The intended solution was: v->{String h="Haystack";int x=7;return new String(new java.math.BigInteger(new byte[]{(byte)((~-~-~-~-~-~-~-~1^-x++*x)+15),new Byte(""+10+((x=h.length()*4/x)+x-7))}).toByteArray())+(new StringBuffer("hidden".substring(++x%3,x).replaceFirst("d","e"+(char)(x*21+3))).reverse());} (don't know why I've included the BigInteger since just byte-array is enough..), but I like yours better.. :)

– Kevin Cruijssen – 2017-10-10T07:11:25.487

1

Brain-Flak, 102 bytes

(((((((((()()()){}){}){}){}()){}()))()()<>)(()()()){}())<>((()((){}<>)))(({})[(((()()){}())(){}){}()])

Cracks H.PWiz's answer.

Try it online!

((((((((((()()()){}){}()){}){}()){}()))<({}[(()()()()){}])(([[]]({})<>)<>)>((()()())){}{})[()]))<[[]()]>((()){}){}((){}[][(<>){}<>])(<>){}(({}<>()[()])[(((()()()){}<[()]>)<(()){}>{}){}()])
 (((((((((()()()){}){}  ){}){}()){}()))      ()()                   <>)     (()()()) {}    () ) <      >((()      ((){}    <>)     )   )  (({}        )[(((()()  ){}  ()  )  () {}   ){}()])

Nitrodon

Posted 2017-10-07T14:14:40.300

Reputation: 9 181

1

Ly, 21 bytes

(78)"e"sl(100)"l"l&o;

Try it online!

Cracks LyricLy's answer.

Nitrodon

Posted 2017-10-07T14:14:40.300

Reputation: 9 181

1

Java by Johnathan S.

import java.util.*;interface Main{static void main(String[]args){Stack<Hay>s=new Stack();s.add(new Needle());System.out.println(s.get(s.indexOf(new Hay())+1).a);}}class Needle extends Hay{{a="Needle";}}class Hay{String a="Haystack";public boolean equals(Object o){return getClass().equals(o.getClass());}}

TiO

Simply remove the loop that adds the Hay and nothing will be left on the stack but the needle.

Titus

Posted 2017-10-07T14:14:40.300

Reputation: 13 814

Ha, nice one - I hadn't actually thought of simply removing the loop! Removing the equals method works just as well. – Jonathan S. – 2017-10-20T12:17:54.093

0

Pyth, 21 bytes

Kr."Dn2û"2+Kr."EL8"Z

cracks this.

Try it online!

Leaky Nun

Posted 2017-10-07T14:14:40.300

Reputation: 45 011

Of course, nice. It was just a first try, so the crack was fairly trivial ;-) – Mr. Xcoder – 2017-10-08T09:52:12.470

0

T-SQL by phroureo, 757 bytes

seleCT 'Needle'

Somehow I don't think that was the intended solution. Uses the characters surrounded by {}:

create table a(l int,c int)
in{se}rt into a va{l}u{e}s (1,10),(2,1),(3,8),(4,0)
go
;CREATE FUN{CT}ION b(@ varchar(max)) returns varchar(max) as
begin return{ '}char('+@+'),'''','end 
go
;CREATE FU{N}CTION h(@ varchar(max),@a varchar(max), @b varchar(max), @c varchar(max), @d varchar(max), @e varchar(max), @f varchar(max), @g varchar(max), @h varchar(max))
r{e}turns varchar(max) as 
b{e}gin
return replace(replace(replace(replace(@,@a,@b),@c,@d),@e,@f),@g,@h)
end
{d}ec{l}ar{e} @x varchar(max),@ int=1,@y varchar(99)={'}'
,@D varchar(4)='Ha',@O varchar(4)='ys'
,@T varchar(3)='ta',@A varchar(4)='ck'
WHILE @<=4
BEGIN
set @y+=(SELECT dbo.b(c+100)from a where l=@)+' '
set @+=1
END
SELECT @x='select
left(dbo.h('''+@D+@O+@T+@A+''','+ left(@y,len(@y)-1) +'),char(56))'
execute(@x)

Robert Fraser

Posted 2017-10-07T14:14:40.300

Reputation: 912

0

PHP

Cracks Titus answer

for($i=1;$c=H_aNyesetdalcek[$i+=2];)echo$c;

Try it online

Cinaski

Posted 2017-10-07T14:14:40.300

Reputation: 1 588