# Will it halt? (Robbers)

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);});});

• 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? Jul 24 '17 at 17:03
• Multiple people can post cracks to the same cop submission... Please define different. Jul 25 '17 at 13:41
• @NoOneIsHere codegolf.meta.stackexchange.com/q/13437/58826
– user58826
Jul 25 '17 at 15:26

# 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!');

# JavaScript, Step Hen

[]

Try it online!

## Python 3 (CPython), Veedrac

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

Try it online!

• One man's garbage... (nicely done) Jul 25 '17 at 15:05

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

# 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!

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

# JavaScript by w0lf

Object(NaN)

Another crack, more elegant way.

# R, Jarko Dubbeldam

expression(quit())

Try it online.

• Nice, indeed the intended solution.
Jul 26 '17 at 11:44

# CPython 3.6, by wizzwizz4

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

0

Segfaults.

Try it online!

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

• Totally not the intended solution, but absolutely a valid crack. Jul 26 '17 at 19:52

Python, Sudo Bash

import signal

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

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

'yield'

TIO

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

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

# 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!

# Python 2, Alex Hall

__builtin__,True,

Try it online!

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

• Well done. That was the intended solution. Jul 29 '17 at 12:18

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

# 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

• Yay! You found it! Jul 30 '17 at 18:48
• I wanted to find a way to make a buffer overflow non-obvious so my misdirection added alternate solutions sadly. Jul 30 '17 at 18:59

# Python, Alex Hall

"%307d"%1

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

# Python, by veedrac

import sys;sys.settrace(-1)

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

• Well, that was fast. Jul 30 '17 at 23:10
• Yep, this was it. Jul 30 '17 at 23:15
• I've done far worse things with sys.setprofile and sys.settrace Jul 30 '17 at 23:16

# Batch, SteveFest

Just undo the quote.

"&&exit

(with a trailing )

Another unintended solution:

"|exit
• Well done! Although this is not me intended solution Jul 29 '17 at 12:45
• I will add the link to here shortly Jul 29 '17 at 12:45

1<<1017

Try it online!

# JS, Step Hen

991

Lots of obfuscation!

Try it online!

• How did you unobfuscate this? Jul 24 '17 at 19:25
• @Cowsquack Removed everything except the obfuscated code, than removed the ().
– user58826
Jul 24 '17 at 19:31
• * Step Hen :P and @Cowsquack JSF*** decoder Jul 24 '17 at 19:35

# 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!

# 05AB1E, MilkyWay90

1

TIO

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

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

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

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

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

Try it online!

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

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

# 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!

• :( I thought mine would last longer! Nice Job!
– user58826
Jul 24 '17 at 18:07
• @programmer5000 thanks :) Jul 24 '17 at 18:08
• [Infinity] also works. Jul 25 '17 at 13:41
• @w0lf also ["Infinity"] Jul 25 '17 at 13:45