# Find the Needle in the Haystack (Robbers)

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.

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.

• If robber use hashing, encryption or random number generation is it allowed?(though possibility tiny) – l4m2 Dec 15 '17 at 18:57

# JavaScript, 85 bytes (ES6)

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'

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.

# Haystack, 82 bytes

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!

• Nice! 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 – hyper-neutrino Oct 7 '17 at 16:29

# Brain-Flak, 96 bytes

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

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:   ([((((()()())){}){}){}](() [()]   ({}([ (((()()()){})) []])[]({}({}     ()(  ((()(({}){}){}){}){}())))[]              ))   ()  )
• I was sure that it would end like this – H.PWiz Oct 7 '17 at 21:05
• That certainly works, but I had somehow convinced myself that N was 77 instead of 78, so I didn't catch it. – Nitrodon Oct 7 '17 at 21:32
• Yours is shorter anyway. – H.PWiz Oct 7 '17 at 21:38
• Interesting solution! I've added my intended solution to the original post if you would like to see it. – Wheat Wizard Oct 9 '17 at 22:22

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:

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:

_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.

# 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

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

## Explanation

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

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 ].

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 @.

• Nice! That was the intended solution. – H.PWiz Oct 19 '17 at 5:54

# Python 2, 123 bytes

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.

• Wow! Great job! I didn’t expect it to be cracked that soon. – agtoever Oct 9 '17 at 12:31
• 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 Oct 9 '17 at 12:33

# 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())

# Jelly, 14 bytes

“¡#ɦṢÞɠ»ḟ“¡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.

• Exactly the one I had in mind Nebbed+ruble without any of rub. – Jonathan Allan Oct 8 '17 at 19:09

# Python 2, 73 bytes

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

Try it online!

Solved with this program.

# Java (OpenJDK 8), 191 bytes

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.

# Ruby, 149 bytes

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'

# 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
• gg! i knew that putting that much numbers was a bad idea) – cab404 Oct 11 '17 at 19:52
• @cab404 Just curious: did you use a very different calculation to get to 86197399743589? – agtoever Oct 11 '17 at 19:56
• yeah, it is a lot longer – cab404 Oct 11 '17 at 20:00
• 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 Oct 11 '17 at 20:05
• 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 Oct 11 '17 at 20:49

## Hexagony, 19 bytes, Martin Ender

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

Try it online!

Try it online