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

139 Answers 139

1
\$\begingroup\$

Braingolf, Mayube

Answer

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!

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

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 {}
    }
} )
| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ Good, but still not desired! \$\endgroup\$ – programmer5000 Jul 25 '17 at 1:19
  • \$\begingroup\$ So there's an error-free solution? \$\endgroup\$ – Haumed Rahmani Jul 25 '17 at 1:21
  • 1
    \$\begingroup\$ A solution that doesn't use throw. \$\endgroup\$ – programmer5000 Jul 25 '17 at 1:22
1
\$\begingroup\$

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?

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ Not intended, but does work... Wish I could disable imports. \$\endgroup\$ – Quelklef Jul 25 '17 at 1:53
1
\$\begingroup\$

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.

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

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


dyad:
[ = [ 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.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ 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. \$\endgroup\$ – miles Jul 25 '17 at 2:48
  • \$\begingroup\$ @miles Yeah, so long as the program is finite. I'm still looking for a non-empty solution, however. \$\endgroup\$ – Conor O'Brien Jul 25 '17 at 2:50
  • \$\begingroup\$ Yes, that's what I had in mind, I'll have to test more input types next time. \$\endgroup\$ – miles Jul 25 '17 at 3:11
  • \$\begingroup\$ @miles Cool! That was fun, I learned something new about # today. \$\endgroup\$ – Conor O'Brien Jul 25 '17 at 3:12
  • \$\begingroup\$ Yeah, it's one of the few features I haven't found a good use for yet. \$\endgroup\$ – miles Jul 25 '17 at 3:13
1
\$\begingroup\$

R, Rift

expression(T <- 0)

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

Try it online.

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

JavaScript (browser), tsh

document.all

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

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

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)
| improve this answer | |
\$\endgroup\$
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!');

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

JavaScript, Step Hen

[]

Try it online!

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

Python 3 (CPython), Veedrac

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

Try it online!

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ One man's garbage... (nicely done) \$\endgroup\$ – Veedrac Jul 25 '17 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.

| improve this answer | |
\$\endgroup\$
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!

| improve this answer | |
\$\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.

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

JavaScript by w0lf

Object(NaN)

Another crack, more elegant way.

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

R, Jarko Dubbeldam

expression(quit())

Try it online.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ Nice, indeed the intended solution. \$\endgroup\$ – JAD Jul 26 '17 at 11:44
1
\$\begingroup\$

CPython 3.6, by wizzwizz4

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

C++, SIGSEGV

0

Segfaults.

Try it online!

| improve this answer | |
\$\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.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ Totally not the intended solution, but absolutely a valid crack. \$\endgroup\$ – ecatmur Jul 26 '17 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'
| improve this answer | |
\$\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\$
1
\$\begingroup\$

Python 3.5, Siphor

'yield'

TIO

| improve this answer | |
\$\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.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ Solved, but I have another! It's shorter, too! codegolf.stackexchange.com/a/136343/11490 \$\endgroup\$ – Alexander Jul 28 '17 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\$ – Sirens Aug 2 '17 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!

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

Python 2, Alex Hall

__builtin__,True,

Try it online!

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

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ Well done. That was the intended solution. \$\endgroup\$ – Alex Hall Jul 29 '17 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.

| improve this answer | |
\$\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

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ Yay! You found it! \$\endgroup\$ – dj0wns Jul 30 '17 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 Jul 30 '17 at 18:59
1
\$\begingroup\$

Python, by veedrac

import sys;sys.settrace(-1)

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

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

Batch, SteveFest

Just undo the quote.

"&&exit 

(with a trailing )

Another unintended solution:

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

JS, Step Hen

991

Lots of obfuscation!

Try it online!

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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