19
\$\begingroup\$

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.

\$\endgroup\$
1
  • \$\begingroup\$ If robber use hashing, encryption or random number generation is it allowed?(though possibility tiny) \$\endgroup\$
    – l4m2
    Commented Dec 15, 2017 at 18:57

21 Answers 21

11
\$\begingroup\$

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.

\$\endgroup\$
5
\$\begingroup\$

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!

\$\endgroup\$
1
  • 1
    \$\begingroup\$ 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 \$\endgroup\$
    – hyperneutrino
    Commented Oct 7, 2017 at 16:29
5
\$\begingroup\$

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

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.

\$\endgroup\$
5
\$\begingroup\$

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

\$\endgroup\$
1
  • \$\begingroup\$ Nice! That was the intended solution. \$\endgroup\$
    – H.PWiz
    Commented Oct 19, 2017 at 5:54
4
\$\begingroup\$

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.

\$\endgroup\$
2
  • \$\begingroup\$ Wow! Great job! I didn’t expect it to be cracked that soon. \$\endgroup\$
    – agtoever
    Commented Oct 9, 2017 at 12:31
  • \$\begingroup\$ 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... ;-) \$\endgroup\$
    – agtoever
    Commented Oct 9, 2017 at 12:33
3
\$\begingroup\$

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. :)

\$\endgroup\$
2
  • \$\begingroup\$ If I've messed up/missed anything, please let me know. \$\endgroup\$
    – Jo.
    Commented Dec 15, 2017 at 7:08
  • \$\begingroup\$ Nice work, this looks pretty accurate. I'll compare it with what I had originally over the weekend. \$\endgroup\$ Commented Dec 15, 2017 at 7:20
2
\$\begingroup\$

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

\$\endgroup\$
0
2
\$\begingroup\$

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.

\$\endgroup\$
1
  • \$\begingroup\$ Exactly the one I had in mind Nebbed+ruble without any of rub. \$\endgroup\$ Commented Oct 8, 2017 at 19:09
2
\$\begingroup\$

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.

\$\endgroup\$
2
\$\begingroup\$

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.

\$\endgroup\$
2
\$\begingroup\$

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'
\$\endgroup\$
2
\$\begingroup\$

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
\$\endgroup\$
5
  • \$\begingroup\$ gg! i knew that putting that much numbers was a bad idea) \$\endgroup\$
    – cab404
    Commented Oct 11, 2017 at 19:52
  • \$\begingroup\$ @cab404 Just curious: did you use a very different calculation to get to 86197399743589? \$\endgroup\$
    – agtoever
    Commented Oct 11, 2017 at 19:56
  • \$\begingroup\$ yeah, it is a lot longer \$\endgroup\$
    – cab404
    Commented Oct 11, 2017 at 20:00
  • \$\begingroup\$ 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... \$\endgroup\$
    – agtoever
    Commented Oct 11, 2017 at 20:05
  • \$\begingroup\$ i guess that would generally require some serious math to calculate all the posibilities and prove that there's only that number of them) \$\endgroup\$
    – cab404
    Commented Oct 11, 2017 at 20:49
1
\$\begingroup\$

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.

\$\endgroup\$
1
1
\$\begingroup\$

Brain-Flak, 102 bytes

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

Cracks H.PWiz's answer.

Try it online!

((((((((((()()()){}){}()){}){}()){}()))<({}[(()()()()){}])(([[]]({})<>)<>)>((()()())){}{})[()]))<[[]()]>((()){}){}((){}[][(<>){}<>])(<>){}(({}<>()[()])[(((()()()){}<[()]>)<(()){}>{}){}()])
 (((((((((()()()){}){}  ){}){}()){}()))      ()()                   <>)     (()()()) {}    () ) <      >((()      ((){}    <>)     )   )  (({}        )[(((()()  ){}  ()  )  () {}   ){}()])
\$\endgroup\$
1
\$\begingroup\$

Ly, 21 bytes

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

Try it online!

Cracks LyricLy's answer.

\$\endgroup\$
1
\$\begingroup\$

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.

\$\endgroup\$
1
  • \$\begingroup\$ Ha, nice one - I hadn't actually thought of simply removing the loop! Removing the equals method works just as well. \$\endgroup\$ Commented Oct 20, 2017 at 12:17
1
\$\begingroup\$

Vyxal o, cracks emanresu A's answer

‛₍∞

Try it Online!

Simply pushes the string Needle in compressed form, then prints it implicitly.

Characters removed:

‛Ha:₍₴Cv∑∑Ṙ⌊√‹½⇩⇩²C:₴«•∞yλ;ß4ġ∆Ė_□∴9«øc:3Ẏ$4ȯ∇ppĖ5e
 XXX XXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXX
\$\endgroup\$
0
\$\begingroup\$

Pyth, 21 bytes

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

cracks this.

Try it online!

\$\endgroup\$
1
  • \$\begingroup\$ Of course, nice. It was just a first try, so the crack was fairly trivial ;-) \$\endgroup\$
    – Mr. Xcoder
    Commented Oct 8, 2017 at 9:52
0
\$\begingroup\$

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)
\$\endgroup\$
0
\$\begingroup\$

PHP

Cracks Titus answer

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

Try it online

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.