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

Posted Mar 9, 2023, 6:51 AM UTC

Posted Mar 9, 2023, 6:51 AM UTC
change to a different school
You forgot sudo.
--no-preserve-root
Right click: run as admin
I run everything as root
.... I hope your teacher burns you at the stake
In the production code that’s a professional incompetence. Don’t do things like that beyond your local machine.
[deleted]
Haha we’ve all been there! Good learning opportunity to find “the correct” way of doing this in the future
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
Yeah I was thinking of doing something similar but I was already pretty tired. I’ll try it sometime soon. Thanks for the advice!
At least you… tried
No I didn’t
Well you tried really hard to not try
But they still did try
In fact, a lot of programming is just trial and error.
He tried and then catched
Your comments lol. Especially
I'll "fix" it later
Hey in python asking forgiveness is cheaper than asking permission, so this would have been the correct approach actually! /s
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.
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.
It's the "I can't be bothered" line that will probably come across in the worst way.
Damn really? I thought it would be the six try catch statements coming before that line
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."
Opinions may diverge. :P
lmfao
My teacher would have eaten me alive for this.
If only there was a way to abstract out repetitive steps
Wish i had an answer FOR you.
Sure is hard to FUNCTION this way
Well I definitely wasn’t able to think of a solution
Using exceptions to handle business rule. That's sweet
So that's what postscript is...
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
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.
Couldn't you just surround all of those lines with a single try-catch considering they're throwing just one type of error?
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 :)
Ahh didn't think of that
I'm not even trying to decipher this.
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.
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
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.
Why
I was tired. I wanted sleep. Brain no think. This was the result.
Fair enough lol
I died laughing when I saw the exception swallowing in such abundance 😂
Time to get a new teacher maybe
Nah he’s a chill dude. Pretty sure it’s the TA’s that do the checking.
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.
That's terrible.
Yep