# 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);});});
<html><body><h1>Uncracked Submissions</h1><table><thead><tr><th>Language</th><th>Author</th></tr></thead><tbody></tbody></table></body></html>

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

# Braingolf, Mayube

163


### Code explanation:

1+[#£-0!e>:$_1>|] 1+ # Add 1 to the input [ ] # While bottom of the stack > 0.. #£ # Push 163 - # Subtract from the input 0 # Push 0 ! # Peek top of the stack e # If greater than zero, do.. > # Rotate the stack one to the right : # Else..$_       #     Discard top of the stack
1      #     Push
>     #     Rotate the stack one to the right
|    #   End ifelse


Which results in outputting 0.

Try it online!

• Woop! You got it! Fyi 163 is the Unicode codepoint of £ – Skidsdev Jul 24 '17 at 18:18
• @Mayube Yeah, just running #£ alone gave it a bit away :p. – Adnan Jul 24 '17 at 18:22
• Darn! I actually tested 163 as an argument and it didn't work at all! – Erik the Outgolfer Jul 24 '17 at 19:58
• @EriktheOutgolfer then you did something wrong, it's taken as an argument – Skidsdev Jul 24 '17 at 20:09
• @Mayube I just passed in 163...maybe I saw something wrong. – Erik the Outgolfer Jul 24 '17 at 20:09

# JavaScript (Babel Node), programmer5000

new Set() was posted as a crack but didn't work for me (Try it online!), so I made one that doesn't throw, but does create a TypeError.

let f=x=>{while(x+"h");}

class Halt {
toString() {
return {}
}
}
f(new Halt())


Try it online!

P.S. The solution I really wanted was to negate the charCode somehow and be errorless but I couldn't get that to not resolve to concatenation. :)

EDIT: An more modern alternative:

f( {
[Symbol.toPrimitive] (hint) {
return {}
}
} )

• Good, but still not desired! – programmer5000 Jul 25 '17 at 1:19
• So there's an error-free solution? – Haumed Rahmani Jul 25 '17 at 1:21
• A solution that doesn't use throw. – programmer5000 Jul 25 '17 at 1:22

# Python 2, Quelklef

def x():
import ctypes
ctypes.cast(1, ctypes.POINTER(ctypes.c_int))[0]

f(x)


I'm sure this isn't the intended solution, but a segfault counts, right?

• Not intended, but does work... Wish I could disable imports. – Quelklef Jul 25 '17 at 1:53

# Python 2, Quelklef

def f(x):
try:x()
except:1
while True:1
def x():global True;True=False
f(x)


Try it online!

Redefines True to False.

• Yay! This is the solution I was looking for! I did it differently, as f( lambda: globals().update({"True": False}) ) – Quelklef Jul 25 '17 at 2:33

# J, miles

Input: '' (the empty vector). Errors with an index error.

$:@#~^:(0([=[e.{#])#~) ''  This approach (erroring out) will work for infinity, floats, and non-positive numbers. The intended approach is probably an imaginary number, such as 2j2, which returns a result. $:@#~^:(0([=[e.{#])#~) 2j2
2j2


Let's decompose the program:

$:@#~^:(0([=[e.{#])#~)$:@                       call this function (recurse)
#~                     with the input repeated itself times
^:(             )    if:
0(    f   )#~         f(0, #~ y)
[=[e.{#]

[ = [ e. { # ]  x = 0, y = #~ y
#    repeat
]     y
{         y[0] times
[ e.        check if 0 is in this list
[ =             check if that is false


So, we want an input y such that (0{y) # (#~ y) contains a zero. When using an imaginary number as y = a + bi, we get:

#~ y
y # y
(a + j. b) # y
(a # y) , (b # 0)


Which gives us b zeroes in the input. This will make the aforementioned condition false, and this only run once.

• Does ending with an error count as cracked? There is actually an input that lets it exit without error. Good find, I didn't think of testing empty input. – miles Jul 25 '17 at 2:48
• @miles Yeah, so long as the program is finite. I'm still looking for a non-empty solution, however. – Conor O'Brien Jul 25 '17 at 2:50
• Yes, that's what I had in mind, I'll have to test more input types next time. – miles Jul 25 '17 at 3:11
• @miles Cool! That was fun, I learned something new about # today. – Conor O'Brien Jul 25 '17 at 3:12
• Yeah, it's one of the few features I haven't found a good use for yet. – miles Jul 25 '17 at 3:13

# R, Rift

expression(T <- 0)


Sets T to a false value. I don't know R, seems to work.

Try it online.

# JavaScript (browser), tsh

document.all


I started trying falsy values. document.all did the job.

# JS, 11bytes / 18bytes

code:

 f=a=>{while(!Array.isArray(a)||!a.length);a.map(_=>{for(;;);})}


cracked (throws no error):

f(Array(5))


cracked (throws error):

 a=[1];a.map=1;f(a)


# 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) – Veedrac 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. – JAD Jul 26 '17 at 11:44

# CPython 3.6, by wizzwizz4

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


# C++, SIGSEGV

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. – ecatmur 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.

# Python 3.5, Siphor

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

# 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. – Alex Hall 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! – dj0wns 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. – dj0wns Jul 30 '17 at 18:59

# Python, by veedrac

import sys;sys.settrace(-1)


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

• Well, that was fast. – Veedrac Jul 30 '17 at 23:10
• Was this the intended solution? – pppery Jul 30 '17 at 23:13
• Yep, this was it. – Veedrac Jul 30 '17 at 23:15
• I've done far worse things with sys.setprofile and sys.settrace – pppery 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 – stevefestl Jul 29 '17 at 12:45
• I will add the link to here shortly – stevefestl Jul 29 '17 at 12:45

# JS, Step Hen

991


Lots of obfuscation!

Try it online!

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