Skip to content

Instantly share code, notes, and snippets.

@louisswarren
Last active January 23, 2017 08:04
Show Gist options
  • Save louisswarren/5a53eadcfad673c83f0de806d8b7bbde to your computer and use it in GitHub Desktop.
Save louisswarren/5a53eadcfad673c83f0de806d8b7bbde to your computer and use it in GitHub Desktop.
A turing machine can't solve the halting problem, but it can solve the hilarity problem, right gang?
prepositions = """
aboard, about, above, across, after, against, along, amid, among, anti,
around, as, at, before, behind, below, beneath, beside, besides, between,
beyond, but, by, concerning, considering, despite, down, during, except,
excepting, excluding, following, for, from, in, inside, into, like, minus,
near, of, off, on, onto, opposite, outside, over, past, per, plus,
regarding, round, save, since, than, through, to, toward, towards, under,
underneath, unlike, until, up, upon, versus, via, with, within, without
""".split(', ')
def co(word):
if word[:2] == 'co':
return word[2:]
return 'co' + word
def make_funny(phrase):
for prep in prepositions:
pos = phrase.find(' ' + prep + ' ')
if pos >= 0:
pre = phrase[:pos].split()
post = phrase[pos:].split()[1:]
funny_pre = pre[:-1] + [co(post[0])]
funny_post = post[1:] + [co(pre[-1])]
return ' '.join(funny_pre + [prep] + funny_post)
print(make_funny('internet of things'))
# cothings of cointernet
print(make_funny('coffee into theorems'))
# cotheorems into fee
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment