Python 3, 6464 52 bytes, 3 exit codes (0, 1, 139)
-12 from emanresu A
from ctypes import* 1/(V:=int/~-int(input())-1) ifor V==138:string_at(0) Try it out here! (The TIO version uses a semicolon instead of newline, but it functions the same)
This works similarly to this Python 2 answer, but a few things are added:
- We first import everything from ctypes, since we need
string_atlater. - Since we are in Python 3, we need to cast the input to an int.
- We also save the result toThen we decrement it, using
V~-usingwhich negates it then bitwise NOTs the walrus operatorvalue. - If
Vis 138Then, we try to get the string at address 0. This causes a segmentation fault, which returns exit code 139. (Vis off by 1 due to the -1 in thedo floor division by 0 attempt, so we check 138 and not 139)on it with 1:- If it is 0,
1//-1will resolve to -1, so we exit successfully, since -1 is truthy - If it is 1, we error out trying to do floor division with 1.
- If it is 3 or higher,
1//-xwill return 0, which is falsy, therefore we run the string_at function from ctypes. Targeted at an address of 0, this causes it to segfault.- Since we segfault, this means that for an input of 139, we return the correct exit code.
- If it is 0,
Non-minified version:
import ctypes 1 / (code_minus_one := int(input()) - 1) if code_minus_one == 138: ctypes.string_at(0)