scalapuzzlers / scalapuzzlers.github.com

Github Pages behind scalapuzzlers.com
www.scalapuzzlers.com
161 stars 53 forks source link

Puzzler 27: Padded Answer #56

Closed som-snytt closed 12 years ago

som-snytt commented 12 years ago

I reserved Puzzler 26 for a puzzler bearing on Scalaz, by virtue of z=26. I feel confident that such a puzzler will surface.

The present puzzler is not a head-scratcher, but may induce a mild double-take.

Feel free to refer me to "Scala D'oh" dot com.

demobox commented 12 years ago

Hi Som

Thanks for submitting! Busy times right now, so please be patient, but looking forward to reviewing soon!

Regards

Andrew

demobox commented 12 years ago

Thanks for the update, @som-snytt . Still planning to get round to this soon. Scala Puzzlers is at Devoxx so I'll definitely try to get this done by then!

demobox commented 12 years ago

Hi @som-snytt

Looks like we have a guess of "great minds think alike" with respect to PR 57, which looks like it's based on the same fundamental issue. Obviously, yours was submitted first!

I'm thinking about ways in which we could combine these or make them less similar. Naturally, we'll ensure everyone is appropriately credited.

@nermin any thoughts..?

demobox commented 12 years ago

http://scalapuzzlers.com/#pzzlr-027 ;-) Thanks!

som-snytt commented 12 years ago

Could you change the attribution to: "Based on a submission by A. P. Marki"?

The strategy (as I understand it) of showing both the output and the exception in one answer kind of gives away the game. Also, omitting the obvious answer, that it doesn't compile, makes no sense. Josh Suereth and Daniel Sobral both endorsed that option (because it's obvious).

Also, the title is no longer funny.

I would reserve the "Keep on Truckin'" reference for something that rhymes with "Truckin'."

Maybe I can come up with that elusive Scalaz puzzler, "Keep on Functin'." No, "Play that Funcky Music."

demobox commented 12 years ago

Could you change the attribution to: "Based on a submission by A. P. Marki"?

Sure! 8a1ab624

showing both the output and the exception in one answer kind of gives away the game

I see your point, but I feel then you miss one dimension of the puzzler: the fact that you actually end up calling charAt. The example that doesn't fail demonstrates the other puzzler aspect: that append is only called once, but I think it would be a shame to touch on the second case only in the explanation.

Also, omitting the obvious answer, that it doesn't compile,

Out of curiosity: why would you consider that "obvious"? Which part of the code looks like it shouldn't compile - using sb.append('*') as the function body because it does not appear to be a function? But happy to put that back in - in place of the "everything works as expected" answer? Or rather the "both fail" one?

Also, the title is no longer funny.

I agree; also about keeping the "Keep On..." reference open. Can you explain a bit what made you come up with the original "Padded Answer"? I was looking for something that refers to the repeated invocation, but this one is boring. "Padded Out"?

demobox commented 12 years ago

Also, the title is no longer funny.

How about "Padding Kitteh" or just "Hello Kitteh"? Or "Kitteh Likes Padding"?

demobox commented 12 years ago

Regarding the "does not compile" option, what do you think about the following choices:

1) Prints

Hello, kitteh!*
Hello!*

2) Second fails with runtime exception, first prints

Hello, kitteh!*

3) First fails with runtime exception, second prints

Hello!**************

4) Does not compile

The exception options would be more symmetrical and so hopefully the correct answer wouldn't stand out as much, and we'd get rid of the "everything works as expected" answer which obviously most people don't go for.

som-snytt commented 12 years ago

That's a good idea. For this set, I'd say there's a preponderance of foo, so the multiple choice brain, which as you know lies right below the so-called reptilian brain, says, foo can't be totally wrong, why do they think I'd pick that, let me figure that out before I jump to any answers. I don't remember anymore what the original was, but I think a good puzzler plays on people's worst instincts, not their best.

You're right that nobody picks "as expected," but that's called misdirection in magic. When you feel you've identified the wrong answer, the wrong answer you pick feels right. It's not quite the Monty Hall effect, where one door is opened for you.

demobox commented 12 years ago

In that case how about 2) - 4) as above, but

1) Prints

Hello, kitteh!******
Hello!*

or

1) Prints

Hello, kitteh!*
Hello!**************
som-snytt commented 12 years ago

I can has padding?

demobox commented 12 years ago

Like! (I'm guessing as a title suggestions) @nermin ?

som-snytt commented 12 years ago

I submitted a new PR with the title and other changes. I guess I lied when I said I couldn't spend time on it. First I started looking at lolcats. Some of the changes are style; what I think I see in the Scala codebase. Others, like using 1 to n instead of 0 until n are more devious. 1 to n looks like an off-by-one to a C/Java guy, so it's a red herring. Also, I think 1 to n for counting is more natural. (Though I resisted it as a C/Java guy.) I'll incorporate comments on the PR if you want to pursue it. The good bye string is pretty funny for some reason. There must be a good cat pun on strings, too; maybe next puzzler. This PR includes your answer suggestion.

som-snytt commented 12 years ago

Can you explain a bit what made you come up with the original "Padded Answer"?

That's an idiom, right? "He padded his answer" means he BSed (i.e. snow, fluff), which is generally more possible on literature exams than in the sciences.