[ 3 / biz / cgl / ck / diy / fa / ic / jp / lit / sci / vr / vt ] [ index / top / reports ] [ become a patron ] [ status ]
2023-11: Warosu is now out of extended maintenance.

/sci/ - Science & Math

Search:


View post   

>> No.9717996 [View]
File: 8 KB, 222x227, How the fuck does Modulo Work with negatives.jpg [View same] [iqdb] [saucenao] [google]
9717996

Hello /sci/ I must be developmentally challenged because I can't understand modulus

When it comes to modulus I always assumed it was like an integer remainder operator.

i.e. 5%10 = 5 because 5/10 = 0 r 5
and 5%3 = 2 because 5/3 = 1 r 2

When it comes to negatives I just can NOT grasp the concept

-5%7 isn't -5 and instead gives 2
-4%3 isn't -1 and instead gives 2 as well

I can rationalize the first example by turning off my brain and just adding the second and the first together, but it doesn't apply to the bottom, and I KNOW that's not how it really works.

I came across this problem when looking at how to improve and shorten rock paper scissors code in python. I can make a seperate post with that snippet, but what's really important here is that I'm FUCKING STUPID and don't understand how modulus REALLY works especially with negatives.

>> No.9717985 [DELETED]  [View]
File: 8 KB, 222x227, How the fuck does Modulo Work with negatives.jpg [View same] [iqdb] [saucenao] [google]
9717985

Explain it to me like I'm fucking dumb because I am /sci/

HOW DOES MODULUS WORK WITH NEGATIVES?

I always thought of modulus as a remainder operator i.e. 5 % 10 would be 5 because 5/10 in integer division is 0 with a remainder 5. 5 % would be 2 because 3 goes into 5 once with a remainder of 2 etc. etc.

When it comes to negatives I get completely lost.
-5 % 3 in my mind would give -2, but it gives 1.

-3 % 7 in my mind would give -3 for the above reason but it's instead 4. The only way I can wrap my head around it is if I just subtract the first from the second, if the second is larger and the first is negative, but I KNOW this isn't how it works.

I came across this problem while looking at a solution for simplifying a rock paper scissors script in python using dictionaries and keys.

I didn't understand how or why modulus could be used to eliminate all the conditionals and relegate it to one line to determine whether user input won.

tl:dr How does modulus actually work with negative numbers? I can't understand the actual reason, even though I know a brain dead solution.

>> No.8490877 [View]
File: 8 KB, 222x227, Unknown.jpg [View same] [iqdb] [saucenao] [google]
8490877

Hey Guys!

Need some help trying to work out a formula to return a percentage

Basically I'm trying to compare two football teams based on a bunch of statistics to then predict who would win in a game.

One of the statistics is Goal difference, obviously a positive goal difference is better, but how would you determine a percentage value for that?
For example:
Team1 = +20
Team2 = -5

I was thinking if a team had a greater goal difference, then to just add a (say) 50% into the forumla to calculate their final overall percentage but that wouldn't be fair if it was only marginally different.


Advice is greatly appreciated

Navigation
View posts[+24][+48][+96]