Crazy "solution" to lightsaber question, grabbing the testcase answer off the stack... #2957
darrellroot
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Here's a standard solution for "How many lightsabers do you own?" in C https://www.codewars.com/kata/51f9d93b4095e0a7200001b8
But one of my students was confused and "solved" it with this (I edited the printf slightly), which passed all the tests!
First, note how he added an extra parameter to the function. Here's what the test case looks like:
And here's the log output from the test cases (with my modified printf):
I think what's happening is the extra parameter is taking the next integer off of the stack, which happens to be the next parameter to the testcase!
Not helpful for learning C, but completely crazy and I thought I'd share.
Beta Was this translation helpful? Give feedback.
All reactions