47
\$\begingroup\$

This is the robbers' thread. The cops' thread is here.

Your challenge is to crack a cop's submission by finding an input that makes it halt. You don't have to find out why, or all inputs that make it halt if there's more than one, or the input the cop intended, just one input will do.

Once you have cracked a submission, post a link to it in a comment or edit to the cop's post. You can also flag your submission for a mod to edit it in the cop's post. Also, post the input used and a link to the cop's post in an answer in this thread. The robber that cracks the most submissions wins.

Multiple people can post cracks to the same cop submission, as long as they are different.

(If SE converted your duplicate answer to a comment, you may want to vote on this feature request)


Looking for uncracked submissions?

fetch("https://api.stackexchange.com/2.2/questions/135363/answers?order=desc&sort=activity&site=codegolf&filter=!.Fjs-H6J36vlFcdkRGfButLhYEngU&key=kAc8QIHB*IqJDUFcjEF1KA((&pagesize=100").then(x=>x.json()).then(data=>{var res = data.items.filter(i=>!i.body_markdown.toLowerCase().includes("cracked")).map(x=>{const matched = /^ ?##? ?(?:(?:(?:\[|<a href ?= ?".*?">)([^\]]+)(?:\]|<\/a>)(?:[\(\[][a-z0-9/:\.]+[\]\)])?)|([^, ]+)).*[^\d](\d+) ?\[?(?:(?:byte|block|codel)s?)(?:\](?:\(.+\))?)? ?(?:\(?(?!no[nt][ -]competing)\)?)?/gim.exec(x.body_markdown);if(!matched){return;}return {link: x.link, lang: matched[1] || matched[2], owner: x.owner}}).filter(Boolean).forEach(ans=>{var tr = document.createElement("tr");var add = (lang, link)=>{var td = document.createElement("td");var a = document.createElement("a");a.innerText = lang;a.href = link;td.appendChild(a);tr.appendChild(td);};add(ans.lang, ans.link);add(ans.owner.display_name, ans.owner.link);document.querySelector("tbody").appendChild(tr);});});
<html><body><h1>Uncracked Submissions</h1><table><thead><tr><th>Language</th><th>Author</th></tr></thead><tbody></tbody></table></body></html>

\$\endgroup\$
3
  • 2
    \$\begingroup\$ Does different mean different inputs (say, all inputs ending with 2 crack the cop's post - can you different people post different numbers ending in 2?) or different families of inputs, or different types of inputs? \$\endgroup\$
    – Stephen
    Commented Jul 24, 2017 at 17:03
  • 1
    \$\begingroup\$ Multiple people can post cracks to the same cop submission... Please define different. \$\endgroup\$
    – Dennis
    Commented Jul 25, 2017 at 13:41
  • \$\begingroup\$ @NoOneIsHere codegolf.meta.stackexchange.com/q/13437/58826 \$\endgroup\$
    – user58826
    Commented Jul 25, 2017 at 15:26

144 Answers 144

1
\$\begingroup\$

JavaScript, Step Hen

One input that stops the program is the object literal {valueOf: () => false}:

var f=x=>{while(!(x&&x==false));};
f({valueOf: () => false});
console.log('Done!');

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

JavaScript, Step Hen

[]

Try it online!

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

Python 3 (CPython), Veedrac

import gc
gc.set_debug(gc.DEBUG_SAVEALL)
gc.collect()
l(gc.garbage[0])

Try it online!

\$\endgroup\$
1
  • \$\begingroup\$ One man's garbage... (nicely done) \$\endgroup\$
    – Veedrac
    Commented Jul 25, 2017 at 15:05
1
\$\begingroup\$

JS, Step Hen

"void 0"

Simple: the 5th char is , the string doesn't have any trailing or leading whitespace, and evaled results in undefined.

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

R Jarko Dubbeldam

f=function(x)while(1)if(length(x))grep(x,'')

Fails with a function argument, e.g.,

f(mean)
# Error in as.character(pattern) : 
  cannot coerce type 'closure' to vector of type 'character'

Try it online!

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

anyfix, Mayube

-5

Easy enough once you learn the neat language. Basically once you make 0 from the addition, the rest is fluff.

Try it online.

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

JavaScript by w0lf

Object(NaN)

Another crack, more elegant way.

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

R, Jarko Dubbeldam

expression(quit())

Try it online.

\$\endgroup\$
1
  • \$\begingroup\$ Nice, indeed the intended solution. \$\endgroup\$
    – JAD
    Commented Jul 26, 2017 at 11:44
1
\$\begingroup\$

CPython 3.6, by wizzwizz4

lambda *a,main=__import__("__main__"):(exec("""main.bool=lambda:True"""),1/0)
\$\endgroup\$
1
\$\begingroup\$

C++, SIGSEGV

0

Segfaults.

Try it online!

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

C++, ecatmur

Truly the most beautiful code I have ever written.

#include <iostream>

auto killmenow = 0;

struct Tee {
    Tee() { if (killmenow++ > 10) { exit(0); } }
};

auto t = Tee{};

int main() {
    f<Tee &, t>(t);
}

This question really confuses me, ergo the above disaster.

Try it online.

\$\endgroup\$
1
  • \$\begingroup\$ Totally not the intended solution, but absolutely a valid crack. \$\endgroup\$
    – ecatmur
    Commented Jul 26, 2017 at 19:52
1
\$\begingroup\$

Python, Sudo Bash

import signal

class x:
    @property
    def x(self):
        signal.alarm(1)
    def __str__(self):
        return 'x.x'
\$\endgroup\$
1
\$\begingroup\$

Python 3, Magenta

def f(x):
 y=str(x)
 while not(x and(y[-1]+y[:-1])==str(2*x)):a=1

The trick is to find a number x which when multiplied by two is equal to itself when all the digits are shifted to the right, with wrapping.

Isaacg found the first number for which this works (105263157894736842), and using the same pattern, I found a bunch more inputs: 210526315789473684, 421052631578947368, 315789473684210526 all work.

Because I didn't make the original crack, and @Isaacg hasnt posted this yet, I made this as CW.

Note that these numbers are formed from the decimal expansion of 1/19.

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

Python 3.5, Siphor

'yield'

TIO

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

Swift, Alexander

func ==(lhs: Int, rhs: Int) -> Bool {
    return false
}

Redefine the == operator to always return false. This means that now, 0 works because 0 == 0 is now false, and 0 != 0 is still false

Alternatively, redefine the != operator to always return false so that every integer other than 0 will halt.

\$\endgroup\$
2
  • \$\begingroup\$ Solved, but I have another! It's shorter, too! codegolf.stackexchange.com/a/136343/11490 \$\endgroup\$
    – Alexander
    Commented Jul 28, 2017 at 8:02
  • \$\begingroup\$ I'm just blown away that this is something you can do. First I've seen a language allow the redefinition of critical operators. \$\endgroup\$
    – Allison
    Commented Aug 2, 2017 at 5:40
1
\$\begingroup\$

Python 3: totallyhuman's post, 143 bytes

def f(o):
 while bool(o)==bool(o):0

# My code starts here

class A:
	def __init__(s):s.a=False
	def __bool__(s):s.a=not s.a;return s.a

f(A())

Try it online!

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

Python 2, Alex Hall

__builtin__,True,

Try it online!

We override True to the empty string, which is falsy.

\$\endgroup\$
1
  • \$\begingroup\$ Well done. That was the intended solution. \$\endgroup\$
    – Alex Hall
    Commented Jul 29, 2017 at 12:18
1
\$\begingroup\$

Python 3, Alex Hall

eval(input())
__import__("os")._exit(0)

Try it online!

Clearly not the intended answer. Bypasses the length limit by evaluating the input.

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

C (gcc), dj0wns

%s12345678

Try it Online!

Since c is only defined as an 8 ('\b') character array and the fgets is passed a second argument of 12 ('\f') longer strings begin to corrupt d which is located after c on the stack. Adding enough characters will cause the snprintf to segfault when it tries to reference the pointer d which has been corrupted

\$\endgroup\$
2
  • \$\begingroup\$ Yay! You found it! \$\endgroup\$
    – dj0wns
    Commented Jul 30, 2017 at 18:48
  • \$\begingroup\$ I wanted to find a way to make a buffer overflow non-obvious so my misdirection added alternate solutions sadly. \$\endgroup\$
    – dj0wns
    Commented Jul 30, 2017 at 18:59
1
\$\begingroup\$

Python, Alex Hall

"%307d"%1

This creates a truthy string consisting of 306 spaces followed by 1.

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

Python, by veedrac

import sys;sys.settrace(-1)

The -1 can be replaced with any other non-callable object

\$\endgroup\$
4
  • \$\begingroup\$ Well, that was fast. \$\endgroup\$
    – Veedrac
    Commented Jul 30, 2017 at 23:10
  • \$\begingroup\$ Was this the intended solution? \$\endgroup\$ Commented Jul 30, 2017 at 23:13
  • \$\begingroup\$ Yep, this was it. \$\endgroup\$
    – Veedrac
    Commented Jul 30, 2017 at 23:15
  • \$\begingroup\$ I've done far worse things with sys.setprofile and sys.settrace \$\endgroup\$ Commented Jul 30, 2017 at 23:16
1
\$\begingroup\$

Batch, SteveFest

Just undo the quote.

"&&exit 

(with a trailing )

Another unintended solution:

"|exit
\$\endgroup\$
2
  • \$\begingroup\$ Well done! Although this is not me intended solution \$\endgroup\$
    – stevefestl
    Commented Jul 29, 2017 at 12:45
  • \$\begingroup\$ I will add the link to here shortly \$\endgroup\$
    – stevefestl
    Commented Jul 29, 2017 at 12:45
1
\$\begingroup\$

Python 3, Alex Hall

1<<1017

Try it online!

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

JS, Step Hen

991

Lots of obfuscation!

Try it online!

\$\endgroup\$
3
  • 1
    \$\begingroup\$ How did you unobfuscate this? \$\endgroup\$
    – user41805
    Commented Jul 24, 2017 at 19:25
  • \$\begingroup\$ @Cowsquack Removed everything except the obfuscated code, than removed the (). \$\endgroup\$
    – user58826
    Commented Jul 24, 2017 at 19:31
  • \$\begingroup\$ * Step Hen :P and @Cowsquack JSF*** decoder \$\endgroup\$
    – Stephen
    Commented Jul 24, 2017 at 19:35
1
\$\begingroup\$

Python 3 by Veedrac

A single 0xff byte for UTF-8, or anything else that cannot be decoded by the selected encoding.

Try it online!

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

05AB1E, MilkyWay90

1

TIO

Pretty easy one, all I had to do was look up the command list for the language.

\$\endgroup\$
7
  • \$\begingroup\$ Yeah, my one was easy to crack. \$\endgroup\$
    – MilkyWay90
    Commented Dec 19, 2018 at 3:02
  • \$\begingroup\$ @MilkyWay90 Nothing wrong with that, either. \$\endgroup\$ Commented Dec 19, 2018 at 3:23
  • \$\begingroup\$ Okay, thank you! I have another answer that you could crack (A BrainF one) \$\endgroup\$
    – MilkyWay90
    Commented Dec 19, 2018 at 3:25
  • \$\begingroup\$ @MilkyWay90 I don't know anything about-- \$\endgroup\$ Commented Dec 19, 2018 at 3:28
  • \$\begingroup\$ Oh, okay. I didn't know anything about it until today so... \$\endgroup\$
    – MilkyWay90
    Commented Dec 19, 2018 at 3:28
1
\$\begingroup\$

Python 3, Makonede

class A:
    def __eq__(self, x):
        exit()

f(A())

Try it online!

The solution checks if x == x, and then loops while a or not a. This is always truthy. You cannot override the logical NOT operator so there is no way for this to be falsy. However, you can just input a custom object that exits the program when it is checked with == so the function is still called and runs but exits before it can hit the infinite loops.

\$\endgroup\$
4
  • \$\begingroup\$ "there is no way for this to be falsy" your statement is falsy lol \$\endgroup\$
    – Makonede
    Commented May 20, 2021 at 20:47
  • 1
    \$\begingroup\$ @Makonede oh. lol, that's smart \$\endgroup\$
    – hyper-neutrino
    Commented May 20, 2021 at 20:53
  • 1
    \$\begingroup\$ @Makonede an object which switches state when observed... who needs quantum computing when you have magic methods? \$\endgroup\$
    – hakr14
    Commented May 20, 2021 at 21:05
  • \$\begingroup\$ @hakr14 i know. magical \$\endgroup\$
    – Makonede
    Commented May 21, 2021 at 1:40
1
\$\begingroup\$

Javascript, cracks Ethertyte's answer

f(eval('delete Object.prototype.hasOwnProperty'))

Try it online!

I can't believe I didn't think of this earlier.

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

Python 3, cracks hakr14's challenge

class x():
 def __init__(s):
  global isinstance
  isinstance=lambda x,y:0

f(x())

Try it online!

Simply replaces isinstance with a lambda returning 0, causing the isinstance call to always return 0, instantly exiting the loop.

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

JavaScript (ES6), programmer5000

"Infinity"

The condition first tests if the input has a .slice method (aka if it's a string or an array) and gets the absolute value of the numeric representation of the string/array. This is then added to 0 and checked against Infinity.

Try it online!

\$\endgroup\$
4
  • \$\begingroup\$ :( I thought mine would last longer! Nice Job! \$\endgroup\$
    – user58826
    Commented Jul 24, 2017 at 18:07
  • \$\begingroup\$ @programmer5000 thanks :) \$\endgroup\$
    – Stephen
    Commented Jul 24, 2017 at 18:08
  • \$\begingroup\$ [Infinity] also works. \$\endgroup\$ Commented Jul 25, 2017 at 13:41
  • \$\begingroup\$ @w0lf also ["Infinity"] \$\endgroup\$
    – Stephen
    Commented Jul 25, 2017 at 13:45

Your Answer

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