r/ProgrammerHumor • • Nov 30 '19

C++ Cheater

Post image
79.3k Upvotes

1.0k comments sorted by

View all comments

Show parent comments

299

u/shekurika Nov 30 '19

what was the worst piece of code youve seen handed in? I tutored intro to programming 2 years ago. One guy needed 25 lines of code to calculate the midpoint between 2 2D points

503

u/PM-Me-Your-TitsPlz Nov 30 '19

Professor demonstrated switch statements with basically:

case 1:
    isEven = false;
    break;
case 2:
    isEven = true;
    break;
case 3:
    isEven = false;
    break;
...

It was just to show off switch statements. He wasn't being serious. A couple days later, a student comes up to me because he got a 0 on his homework that works "perfectly." He did the switch cases up to 4096.

370

u/Astrokiwi Nov 30 '19

There is a rule in teaching that you never write anything wrong on the whiteboard (or, I guess, on the projector or screen), even if you tell people it's wrong, because somebody who is forgetful or just isn't listening is going to copy that into their notes or code.

129

u/HouseCatAD Nov 30 '19

There was a girl in my algebra 2 class in high school who completely bombed an exam because she thought the only log(x) functions in existence were the ones the teacher wrote on the board and studied the shit out of those

89

u/KuntaStillSingle Nov 30 '19

Lol teach her change of base she'd be a log God.

→ More replies (1)

33

u/Gonzako Nov 30 '19

Hell yeah

→ More replies (10)

41

u/monoshift Nov 30 '19

shudders

46

u/memeticmachine Nov 30 '19
switch (num & 1) {
    case 0:
        isEven = true;
        break;
    case 1:
    default:
        isEven = false;
        break;
}
→ More replies (11)
→ More replies (5)

122

u/ajkachnic Nov 30 '19

how do you even take 25 lines of code for that? sounds more like a genius for being that inefficient

131

u/shekurika Nov 30 '19

idk, I needed a while to figure out what he did. essentially he checked which point is closer to the origin, calculated the distance and the direction between those points and added half the distance times the direction to the point that is closer to the origin. It was correct ofc, but...

47

u/robchroma Nov 30 '19

You could write a random number generator for which point was closer to the origin and it'd still work.

→ More replies (2)

29

u/[deleted] Nov 30 '19

That’ll probably do it

31

u/DataJeopardyRL Nov 30 '19

I get what you're saying here with that being more complicated than necessary, but I think that that's a good thing. It's easy to learn the "right" way to solve sanitized problems, but it's hard to learn how to come up with a solution when you don't know the "right" way (if it even exists). I think that, for the most part, you either have it or you don't, and it sounds like that student has it.

→ More replies (2)
→ More replies (1)

18

u/LeCrushinator Nov 30 '19

Maybe he heard about the programming jobs where they care about the number of lines of codes you write.

→ More replies (1)
→ More replies (4)

55

u/[deleted] Nov 30 '19

[removed] — view removed comment

32

u/dkyguy1995 Nov 30 '19

Sounds to me like someone didn't know their midpoint formula and thought they had to invent math

→ More replies (1)

20

u/shekurika Nov 30 '19

yeah, thats the code they couldve come up with

→ More replies (1)

34

u/ThatRestaurant Nov 30 '19

I also tutor intro to programming. this one person refused to use loops, so their entire program was around 700 lines, just to get the output right

39

u/TomGraphy Nov 30 '19

That’s when you start increasing the size of the test inputs exponentially

16

u/dkyguy1995 Nov 30 '19

Yep the best thing about code is you write it once and it works for input size 5 or input size 5000000000.

→ More replies (6)

18

u/drleebot Nov 30 '19

Was he coding in Brainfuck perhaps? Or maybe he was playing reverse code golf?

20

u/WikiTextBot Nov 30 '19

Brainfuck

Brainfuck is an esoteric programming language created in 1993 by Urban Müller, and is notable for its extreme minimalism.

The language consists of only eight simple commands and an instruction pointer. While it is fully Turing complete, it is not intended for practical use, but to challenge and amuse programmers. Brainfuck simply requires one to break commands into microscopic steps.


[ ^PM | Exclude ^me | Exclude from ^subreddit | FAQ / ^Information | ^Source ] Downvote to remove | v0.28

→ More replies (1)

13

u/yosho27 Nov 30 '19

I once did an entire project for a class in a single line of python code. The teacher said I couldn't one-line the program though, so I wrote 80 lines of code and all they did was take the input and call a function containing the one line.

→ More replies (1)
→ More replies (8)