-1
$\begingroup$

There's this built-in python module, we'll call it mystery.
Now, mystery has this function, we'll call it ted.
Also, mystery has another function, we'll call it jan.
Finally, lets bring Thomas into the equation, your typical python programmer.

One day, Thomas goes

import mystery

print(mystery.ted('Hello world.'...

The program runs with no error, and ted gives him a message. "Very mysterious..." Thomas thinks.

Days later Thomas goes

import mystery

print(mystery.jan('Hello world.'...

The program runs with no error, and jan gives him a message. At fist Thomas doesn't think much of it... until HE REMEMBERS TED! He goes pale. "Is someone or something trying to tell me something?" he thinks.

Thomas decides to tell ted what jan said, cause obviously ted would be interested. No errors, but ted's answer have Thomas shocked! "He... he's alive..." he realizes.

What is this mysterious module? Will ted and jan take over the world?

No, seriously, find out what this so-called "mystery" module is called in real life, for example, "os", and also explain what functions "ted" and "jan" are.

Note: when Thomas first called mystery.ted() and mystery.jan(), he put the exact same parameters into the brackets.

Hint:

If you've joined SO and PSE, this module is for you!

Hint (2):

This involves code right?

Hint (3):

Something's rotten about this situation...

$\endgroup$
9
  • 1
    $\begingroup$ @Vicky It works both ways, so I guess it doesn't matter. $\endgroup$ Oct 28, 2020 at 13:12
  • 2
    $\begingroup$ Are the ... literal contents of the code, or your way of obfuscating to us what comes after? If the former, it seems like the puzzle is about discovering which module import will allow such bizarre syntax. If the latter, I suspect there's way too little information (granted, I'm not really a Python user). $\endgroup$ Oct 28, 2020 at 17:59
  • 1
    $\begingroup$ @TheRubberDuck ... will give a syntax error, so it's pretty clear to programmers that the string is not the only parameter. The story is detailed enough to figure the module. $\endgroup$ Oct 28, 2020 at 19:16
  • 6
    $\begingroup$ Well, I'm definitely a programmer, and it was not clear to me that the text in the code blocks was not literal text that should be run through Python, and clearly from their answer the same applies to ChoKaPeek. I was looking for a module that would somehow have redefined ( or print( or something. I really don't get it - like @TheRubberDuck says, it seems like there's way too little information here. $\endgroup$
    – Vicky
    Oct 28, 2020 at 20:27
  • 3
    $\begingroup$ I'm a little confused why a typical Python programmer is anthropomorphizing functions, or why he's at all surprised by what gets returned by a built-in function. $\endgroup$ Nov 6, 2020 at 19:57

3 Answers 3

8
$\begingroup$

Hint 3 makes it sound like the functions are

codecs.encode and codecs.decode, with second argument "rot13".

>>> import codecs
>>> print(codecs.encode('Hello, world.', 'rot13'))
Uryyb, jbeyq.
>>> import codecs
>>> print(codecs.decode('Hello, world.', 'rot13'))
Uryyb, jbeyq.
>>> print(codecs.decode('Uryyb, jbeyq.', 'rot13'))
Hello, world.

“He’s alive” is a weird reaction to that, but there you go.

$\endgroup$
1
  • $\begingroup$ I actually really like this answer, it fits a lot of the hints, and the overall story. The only problem is -- and I kept running into this -- when you print the output of a function that returns a string, it doesn't print with quotes, so you can't just put the raw output from jan into ted. Maybe I understood this part too literally, though, because the answer fits so well. $\endgroup$ Nov 3, 2020 at 5:18
9
$\begingroup$

I've given up and tried to bruteforce it - with little regards to what could happen to my machine.

I'm importing every builtin module and evaluating the input on every function they've got. As I don't know a list of builtins, I'm using the help("modules") one, the pkgutil.iter_modules() one, and the sys.builtin_module_names one.

import pkgutil
import sys
import inspect

# help("modules") formatted output
help_modules = "\
    __future__          audioop             idle                scrolledlist\
    __main__            autocomplete        idle_test           search\
    _ast                autocomplete_w      idlelib             searchbase\
    _asyncio            autoexpand          imaplib             searchengine\
    _bisect             base64              imghdr              secrets\
    _blake2             bdb                 imp                 select\
    _bootlocale         binascii            importlib           selectors\
    _bz2                binhex              inspect             setuptools\
    _codecs             bisect              io                  shelve\
    _codecs_cn          browser             iomenu              shlex\
    _codecs_hk          builtins            ipaddress           shutil\
    _codecs_iso2022     bz2                 itertools           signal\
    _codecs_jp          cProfile            json                site\
    _codecs_kr          calendar            keyword             smtpd\
    _codecs_tw          calltip_w           lib2to3             smtplib\
    _collections        calltips            linecache           sndhdr\
    _collections_abc    cgi                 locale              socket\
    _compat_pickle      cgitb               logging             socketserver\
    _compression        chunk               lzma                sqlite3\
    _csv                cmath               macosx              sre_compile\
    _ctypes             cmd                 macpath             sre_constants\
    _ctypes_test        code                macurl2path         sre_parse\
    _datetime           codecontext         mailbox             ssl\
    _decimal            codecs              mailcap             stackviewer\
    _distutils_findvs   codeop              mainmenu            stat\
    _dummy_thread       collections         marshal             statistics\
    _elementtree        colorizer           math                statusbar\
    _functools          colorsys            mimetypes           string\
    _hashlib            compileall          mmap                stringprep\
    _heapq              concurrent          modulefinder        struct\
    _imp                config              msilib              subprocess\
    _io                 config_key          msvcrt              sunau\
    _json               configdialog        multicall           symbol\
    _locale             configparser        multiprocessing     symtable\
    _lsprof             contextlib          netrc               sys\
    _lzma               copy                nntplib             sysconfig\
    _markupbase         copyreg             nt                  tabnanny\
    _md5                crypt               ntpath              tarfile\
    _msi                csv                 nturl2path          telnetlib\
    _multibytecodec     ctypes              numbers             tempfile\
    _multiprocessing    curses              opcode              test\
    _opcode             datetime            operator            textview\
    _operator           dbm                 optparse            textwrap\
    _osx_support        debugger            os                  this\
    _overlapped         debugger_r          outwin              threading\
    _pickle             debugobj            paragraph           time\
    _pyclbr             debugobj_r          parenmatch          timeit\
    _pydecimal          decimal             parser              tkinter\
    _pyio               delegator           pathbrowser         token\
    _random             difflib             pathlib             tokenize\
    _sha1               dis                 pdb                 tooltip\
    _sha256             distutils           percolator          trace\
    _sha3               doctest             pickle              traceback\
    _sha512             dummy_threading     pickletools         tracemalloc\
    _signal             dynoption           pip                 tree\
    _sitebuiltins       easy_install        pipes               tty\
    _socket             editor              pkg_resources       turtle\
    _sqlite3            email               pkgutil             turtledemo\
    _sre                encodings           platform            types\
    _ssl                ensurepip           plistlib            typing\
    _stat               enum                poplib              undo\
    _string             errno               posixpath           unicodedata\
    _strptime           faulthandler        pprint              unittest\
    _struct             filecmp             profile             urllib\
    _symtable           fileinput           pstats              uu\
    _testbuffer         filelist            pty                 uuid\
    _testcapi           fnmatch             py_compile          venv\
    _testconsole        formatter           pyclbr              warnings\
    _testimportmultiple fractions           pydoc               wave\
    _testmultiphase     ftplib              pydoc_data          weakref\
    _thread             functools           pyexpat             webbrowser\
    _threading_local    gc                  pyparse             windows\
    _tkinter            genericpath         pyshell             winreg\
    _tracemalloc        getopt              query               winsound\
    _warnings           getpass             queue               wsgiref\
    _weakref            gettext             quopri              xdrlib\
    _weakrefset         glob                random              xml\
    _winapi             grep                re                  xmlrpc\
    abc                 gzip                redirector          xxsubtype\
    aifc                hashlib             replace             zipapp\
    antigravity         heapq               reprlib             zipfile\
    argparse            help                rlcompleter         zipimport\
    array               help_about          rpc                 zlib\
    ast                 history             rstrip              zoomheight\
    asynchat            hmac                run                 zzdummy\
    asyncio             html                runpy\
    asyncore            http                runscript\
    atexit              hyperparser         sched"

tested = []

def main():
    total_errors = 0
    for module in sys.builtin_module_names:
        total_errors += syntastic(module)
    for module in pkgutil.iter_modules():
        total_errors += syntastic(module.name)
    for module in help_modules.split():
        total_errors += syntastic(module)

    print(f"{total_errors} errors out of {len(tested)} potential functions")


def syntastic(module_name):
    errors = 0
    try:
        imported = __import__(module_name)
    except Exception:
        return 0
    for function_name, function in inspect.getmembers(imported, inspect.isfunction):
        tested.append(".".join([module_name, function_name]))
        try:
            eval("print(imported.function('Hello world.'...")
        except SyntaxError:
            errors += 1
            continue
        print(f"Answer could be {module_name}.{function_name}")
        
    return errors


if __name__ == "__main__":
    main()

Sadly on python 3.6, reality is often disappointing:

3620 errors out of 3620 potential functions

I guess I deserved it for trying to cheat... But still what am I missing?

$\endgroup$
3
  • 1
    $\begingroup$ Definitely +1 for trying it! $\endgroup$
    – Vicky
    Oct 28, 2020 at 15:52
  • $\begingroup$ I'm pretty sure that the ellipses after 'Hello World' is supposed to represent something other than an ellipsis. I believe that the errors in question are all going to be of the form "you didn't close the parenthesis on your eval call" $\endgroup$
    – Ben Barden
    Oct 28, 2020 at 17:06
  • $\begingroup$ See the comment thread on the question - evidently, this is not the right approach at all (although I agreed with you that it seemed to be what the question was looking for). $\endgroup$
    – Vicky
    Oct 28, 2020 at 20:29
3
$\begingroup$

Likely not the intended answer, as this does not fit any of the hints in the question, but it is a built-in module that

has two different functions that return something printable when given 'Hello world.' as their first argument.

In fact, a very built-in module: enter image description here There are several other builtins functions that work, such as sorted for jan and len for ted, or reversed for jan and anything that takes a string for ted.

$\endgroup$
1
  • $\begingroup$ This is a good answer, and also reveals my underlying issue with the puzzle in that it seems there are several possible valid answers. $\endgroup$
    – Vicky
    Nov 5, 2020 at 12:38

Your Answer

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

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