The fact that mathematics don't give us one number as an answer, combined with the differences between the languages, makes this topic quite tricky.

]]>

rafaelhoukes wrote:

Thank you, that post clarifies a lot.

However, I see I've made a mistake myself: apparently, if you divide a negative number by a negative number, the remainder should be negative.

So -22 mod -5 would become -2 (and not 3). In all other cases, the answer should be non-negative, (for example: -22 mod 5 = 3) if I've not misunderstood Patrick's post.

I also see that negative modulo could probably create a lot of trouble, so it might be not possible at all to generate a puzzle with negative modulo numbers.

I'm not really sure if there is common convention for negative mod functions. From a mathematical perspective, -22 mod 5 = 3 and -22 mod 5 = -2 should be equally valid. I think it's up to you which one you find more practical to use.

It seems different programming languages don't quite agree on this either: I found the following table on the following site: https://torstencurdt.com/tech/posts/mod ... e-numbers/

Language 13 mod 3 -13 mod 3 13 mod -3 -13 mod -3

C 1 -1 1 -1

Go 1 -1 1 -1

PHP 1 -1 1 -1

Rust 1 -1 1 -1

Scala 1 -1 1 -1

Java 1 -1 1 -1

Javascript 1 -1 1 -1

Ruby 1 2 -2 -1

Python 1 2 -2 -1

Edit: I see this table doesn't come out quite as I hoped... anyway, you can fight a proper one on that linked website.

]]>

will look into this..

]]>

So -22 mod -5 would become -2 (and not 3). In all other cases, the answer should be non-negative, (for example: -22 mod 5 = 3) if I've not misunderstood Patrick's post.

I also see that negative modulo could probably create a lot of trouble, so it might be not possible at all to generate a puzzle with negative modulo numbers.

]]>

https://www.calcudoku.org/forum/viewtopic.php?f=3&t=1089

skeeter84

]]>

Quote:

1) Can the numerator and denominator BOTH be negative? If so, how would that work?

Yes, that works exactly the same as with two positive numbers: subtract the rightmost number from the leftmost, till the answer is non-negative, but smaller than the rightmost number. For example: -22 mod -5 = -17 mod -5 = -12 mod -5 = -7 mod -5 = -2 mod -5 = 3 mod -5, so the answer is 3.

Quote:

2) You can't divide by zero, but is 0 mod -2 possible? If so, would the answer be -2 or something else?

Yes, you can, but the answer is (always) 0: if we divide 0 by -2, we get 0 and a remainder of 0, so the answer is 0.

Quote:

3) Are 3-cell mod cages possible and, if so, how would they work? Can they have zeroes in the numerator or negatives in the numerator and/or denominator?

The current mod function is probably only well-defined for two numbers. Three numbers would probably generate way too many solutions, by the way.

I'm not an experienced programmer either, and I don't completely understand your fourth question. Maybe another user can answer your last question.

I hope I've made no mistakes myself, and have been able to answer some of your questions.

Rafaël

]]>

Problem: -22 mod 3

Step 1: -22 + 3 = -19

Step 2: -19 + 3 = -16

Step 3: -16 + 3 = -13

Step 4: -13 + 3 = -10

Step 5: -10 + 3 = -7

Step 6: -7 + 3 = -4

Step 7: -4 + 3 = -1

Step 8: -1 + 3 = 2 for the final result

Please let me know if I made any mistakes in my work above. I'd rather not have to redo a ton of work just because I did my math incorrectly. That said, I've got some questions regarding the modulo operator.

1) Can the numerator and denominator BOTH be negative? If so, how would that work?

2) You can't divide by zero, but is 0 mod -2 possible? If so, would the answer be -2 or something else?

3) Are 3-cell mod cages possible and, if so, how would they work? Can they have zeroes in the numerator or negatives in the numerator and/or denominator?

4) I have no experience whatsoever with either Perl or C++, so I'm clueless as to whether I should follow the sign of the divisor or that of the dividend.

As I said before, I'm willing to make negative number tables involving the modulo function. I've never come across negative modulo cages before, so please feel free to correct any errors I may have made. Thanks for your patience regarding my questions and stay safe and healthy.

skeeter84

]]>

That would help me (and probaly not only me... ) because I have some doubts about a few combos to solve 3 or 4 books puzzle.

I hope it will be ok because we have a lot of free time because of containment and I believe it's the same in U.S or everywhere...

Thank for your answer

]]>

skeeter84

]]>

]]>

skeeter84

]]>

skeeter84

]]>