This is probably bad but I still turned it in. I doubt my teacher would care.

This is probably bad but I still turned it in. I doubt my teacher would care.

Posted Mar 9, 2023, 6:51 AM UTC

38371
Speco7•

Time to get a new teacher maybe

99
Musa2005OP•

Nah he’s a chill dude. Pretty sure it’s the TA’s that do the checking.

26

I had a c professor who never looked at our code. He had a perl (loved perl and regex like they were his child) script that checked to see if it was similar to other students. If it compiled and did what it was intended you were good. If it didn't compile you got a zero. You could write whatever comments you wanted and they would never know.

3
mohragk•

That's terrible.

1

Yep

1
john-batteryacid [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo “You live”•

change to a different school

77
pindab0ter•

You forgot sudo.

28
ManPickingUserHard•

--no-preserve-root

13

Right click: run as admin

4
Secure-Cobbler1471•

I run everything as root

1
Truebotted•

.... I hope your teacher burns you at the stake

75
leosadovsky•

In the production code that’s a professional incompetence. Don’t do things like that beyond your local machine.

48
[deleted]•

[deleted]

1
Sir_NaCl•

Haha we’ve all been there! Good learning opportunity to find “the correct” way of doing this in the future

43
Sir_NaCl•

Not sure if it’s actually the preferred way of doing it but I’d probably implement a helper function that extracts an array of the coordinate pairs to be flipped (all neighbouring squares inside the grid). Then doing the flipping by iterating through that list

20
Musa2005OP•

Yeah I was thinking of doing something similar but I was already pretty tired. I’ll try it sometime soon. Thanks for the advice!

10
feldejars•

At least you… tried

42
Musa2005OP•

No I didn’t

51
TobofCob•

Well you tried really hard to not try

11
PinHeavy608•

But they still did try

6

In fact, a lot of programming is just trial and error.

3
xNeiR•

He tried and then catched

51
bruderjakob17•

Your comments lol. Especially

I'll "fix" it later

23
Duke_Nukem_1990•

Hey in python asking forgiveness is cheaper than asking permission, so this would have been the correct approach actually! /s

22
memorable_zebra•

If you do want to make it better in the future for your own edification, I would advise making an array containing the offsets to each row and column and iterating through that with the try-catch within each loop of the iteration.

17
mohragk•

If it's a simple n-sized square you can just use a double for loop to iterate over every cell in the square. And don't use a try catch in every iteration, just use a simple check whether it's in bound and continue if it isn't.

1
machine3lf•

It's the "I can't be bothered" line that will probably come across in the worst way.

16
Musa2005OP•

Damn really? I thought it would be the six try catch statements coming before that line

2†
madwilliamflint•

Really really.

Nothing says "I know better but I just don't care enough to fix it." like "I know better but I just don't care enough to fix it."

13
machine3lf•

Opinions may diverge. :P

5
PM_ME_YOUR_REPO•

lmfao

1
bored1_Guy•

My teacher would have eaten me alive for this.

9

If only there was a way to abstract out repetitive steps

9
brianplusplus•

Wish i had an answer FOR you.

3

Sure is hard to FUNCTION this way

2
Musa2005OP•

Well I definitely wasn’t able to think of a solution

0
flying_spaguetti [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo “You live”•

Using exceptions to handle business rule. That's sweet

6
pLeThOrAx•

So that's what postscript is...

6
marcoom_•

As a teacher in uni, I don't care if a student gives this. I'm pretty sure the exercise is not at all about this function, so I wouldn't want to see a student losing time writing "clean" code instead of the clear objective of the exercise.

Of course I would point that there is a way cleaner way to do this, but I won't give any penalty for this

5
noop_noob•

Another way is to have a helper method that checks if the an index is in bounds, and flips that. Then, call that method 8 times.

4
_Xertz_•

Couldn't you just surround all of those lines with a single try-catch considering they're throwing just one type of error?

4
Daimanta•

Good question!

The answer is no however. Imagine step "3" fails. If you have one try-catch block, step 4-9 will not be executed regardless if they are not out of bounds. This method works, although beautification is certainly possible :)

7
_Xertz_•

Ahh didn't think of that

1
xxmalik•

I'm not even trying to decipher this.

3
eldentings•

I thought I knew at first but looking at this more it looks more like he's flipping all of the values (in range, lol) within a 3x3 area, rather than setting a single point to true and the others to false, like I originally thought.

3
Musa2005OP•

Close, I’m flipping the value of all the blocks around the tile I’m clicking, while the tile I click says the same value and doesn’t change color

2
eldentings•

Ah, I didn't notice you actually don't set the value for the row and column, just all the other variations. Makes it even more horrific.

2
Feathercrown•

Why

3
Musa2005OP•

I was tired. I wanted sleep. Brain no think. This was the result.

6
Feathercrown•

Fair enough lol

5
SurprisedTissue•

I died laughing when I saw the exception swallowing in such abundance 😂

3