I've got an idea for a new kind of puzzle and would like to ask if it's OK first. It's a bit different than the usual code-golf kind of question. It doesn't ask for the shortest solution, or something funny/silly like the troll questions, but actually for something semi-useful. I'll give an example first, and then describe the general idea:

Example: Implement multi-line lambdas in Python. Guido van Rossum said it couldn't be done, prove him wrong. Your solution should allow something like:

>>> f = multilinelamba("hour", """
...     if hour > 20 or hour < 6:
...         print "Good night"
...     else:
...         print "Hello world"
...     """)
>>> f(10)
... 'Hello world'

Your solution should be as close as possible to the behavior of real def or lambda. The actual syntax or way of implementation doesn't matter (e.g. define a function, write a preprocessor, ...). You get bonus points:

  • If your solution captures outside variables in a closure, like real def
  • For correct handling of exceptions in the multiline lamba
  • (and so on, a checklist of objective criteria or 'unit tests' to judge)

I posted this question a while ago on Stack Overflow: Recipe for anonymous functions in python?, but it received a lot of hate. People didn't answer it, but told my why it was a bad idea, and I had to justify myself and put up big disclaimers. So now I'm trying something different, I'm posing it not as a SO question, but as a programming riddle. Explicitly not looking for a solution for production code, but just for fun. That doesn't mean I'm looking for silly solutions - they should be well-engineered and in principle usable. I have a couple of these questions where tinkering is required, and I'm really curious to see clever solutions, but I'm afraid of posting them on SO for obvious reasons.

I personally don't really care for rating the answers, and would be happy with two or three interesting submissions per question without picking a winner. But it seems the community feels strongly about having objective winning criteria, so I propose a check list of "tests" like above that the solution must pass, the more it passes the better.

One think I'd like to add is that the answers should be compact enough to fit in an answer. You may link to a repository, if your solution lead to something cool and useful, of course, but the core idea (and basis of rating, if desired) should be presented succinctly.

Finally, it should be a question that doesn't fit directly on SO, so no straightforward programming questions, but rather hackish "I wonder if it could be done?" kind of challenges. The kind where people refuse to answer, and say "don't" or "what are you trying to accomplish?".

As for a tag name, I have no great idea. Maybe something like tinker-challenge or clever-hack?

As Guido said, "Language Design Is Not Just Solving Puzzles", but solving puzzles is fun!

  • \$\begingroup\$ possible duplicate of Let's create some new types of challenges! \$\endgroup\$ Mar 22 '14 at 13:55
  • \$\begingroup\$ @JanDvorak: Not a duplicate, that question said: "To propose a genre, ask a question here on meta with the new-genre tag.". Hope I didn't misunderstand that post... \$\endgroup\$
    – jdm
    Mar 22 '14 at 13:57
  • 1
    \$\begingroup\$ Huh... sorry. I was under the impression new genres were supposed to be posted as answers to that post. Retracting. \$\endgroup\$ Mar 22 '14 at 14:00
  • 1
    \$\begingroup\$ What if more than one of the entries pass all of the tests? Also, this seems like it would have to be language-specific, if I understand it correctly. \$\endgroup\$
    – Doorknob Mod
    Mar 22 '14 at 14:01
  • \$\begingroup\$ @Doorknob: Yes, this is language specific, I hope that's OK. It's not inherent to the challenge type, other questions may or may be not language specific. And yes, if multiple questions pass all mandatory and optional tests, then they receive the same rating (that can also happen with code golf, but is less likely). But as I said, this is more about seeing clever solutions than picking a winner. \$\endgroup\$
    – jdm
    Mar 22 '14 at 14:10
  • 3
    \$\begingroup\$ Language specific challenges are generally discouraged here, so an entire challenge type that requires them doesn't seem ideal. Also, if they receive the same rating, how do you decide which one wins? \$\endgroup\$
    – Doorknob Mod
    Mar 22 '14 at 14:12
  • \$\begingroup\$ @Doorknob: The challenge type is not about language specific questions, only this example is! And if both receive the same rating, it's just a tie? I don't know, what do you do when that happens in code-golf? Personally I don't want it to be a competition, but a challenge. Every working, conforming answer wins! If you feel it's necessary to add a ranking on top, feel free to suggest additional criteria. \$\endgroup\$
    – jdm
    Mar 22 '14 at 14:24
  • \$\begingroup\$ Okay, but how would you create a challenge like this that is not language-specific? The idea of having a tiebreaker of sorts sounds good. \$\endgroup\$
    – Doorknob Mod
    Mar 22 '14 at 14:26
  • \$\begingroup\$ @Doorknob I think language-independent questions of this type would tend to be algorithmic. Two mediocre examples from my SO questions would be Layout dependencies in tree graph (similar to gitk) and Difference (XOR) between two rectangles, as rectangles? . The more interesting examples tend to be platform or language specific, however: "Do this crazy thing with C++ templates/the C preprocessor", "Make a Hybrid Windows 8 Desktop/Metro app" (actually possible, but evil), and so on. \$\endgroup\$
    – jdm
    Mar 22 '14 at 14:40

You must log in to answer this question.

Browse other questions tagged .