Calcudoku puzzle forum
https://www.calcudoku.org/forum/

-4 to 4 puzzle combos
https://www.calcudoku.org/forum/viewtopic.php?f=3&t=1217
Page 2 of 4

Author:  skeeter84  [ Tue Apr 07, 2020 8:41 am ]
Post subject:  Re: -4 to 4 puzzle combos

Hi, everybody - hopefully you guys are staying safe and healthy in the midst of the COVID-19 epidemic. I AM willing to make negative mod tables, but I'll need some "briefing" before I undertake such a task. As an example involving 2 cells, I decided to work out the result for -22 mod 3. I've displayed my steps below for the sake of clarity and easier troubleshooting in case I messed up anywhere.

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

Author:  rafaelhoukes  [ Tue Apr 07, 2020 9:32 am ]
Post subject:  Re: -4 to 4 puzzle combos

Hi skeeter84. I don't see any mistakes in your post. As far as I know, the answers of questions 1 to 3 are as following:

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

Author:  skeeter84  [ Tue Apr 07, 2020 4:37 pm ]
Post subject:  Re: -4 to 4 puzzle combos

Thank you very much for your input, rafaelhoukes. In my fourth question, I was referring to one of Patrick's replies in the topic "Mod and negative numbers".

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

skeeter84

Author:  rafaelhoukes  [ Tue Apr 07, 2020 9:24 pm ]
Post subject:  Re: -4 to 4 puzzle combos

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.

Author:  pnm  [ Wed Apr 08, 2020 10:49 am ]
Post subject:  Re: -4 to 4 puzzle combos

Hm, I see I never followed up on that, [huh]
will look into this..

Author:  jpoos  [ Wed Apr 08, 2020 4:01 pm ]
Post subject:  Re: -4 to 4 puzzle combos

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.

Author:  oldmathtchr  [ Thu Apr 09, 2020 5:20 am ]
Post subject:  Re: -4 to 4 puzzle combos

I apologize for coming late to this discussion, but shouldn't the dividend determine the sign of the remainder rather than the divisor? the remainder when you divide a positive number will be positive, and the remainder when you divide a negative number will be negative. I am I oversimplifying the definition of mod?

Author:  rafaelhoukes  [ Thu Apr 09, 2020 7:51 am ]
Post subject:  Re: -4 to 4 puzzle combos

Yes, in some programming languages this is indeed the definition of the mod operator. Some languages, however, have other definitions, as is illustrated by jpoos mod table.
Mathematically seen, it doesn't matter at all: -22 mod 5 = 3, -22 mod 5 = -22 and -22 mod 5 = -1234562 are equally good answers.
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.

Author:  fzpowerman47  [ Tue May 12, 2020 11:25 pm ]
Post subject:  Re: -4 to 4 puzzle combos

Hello,
sorry, I sought but there's nothing to do, I still don't understand. [huh]
Someone could give me all solutions for mod cell ( 0mod, 1 mod, 2 mod, 3 mod and 4mod ) with numbers between -5 and 5 ?
I cant' finish 4 book puzzle and I would like finish them.
Thanks for your answer.
Fred

Author:  pnm  [ Wed May 13, 2020 8:59 am ]
Post subject:  Re: -4 to 4 puzzle combos

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


You can out the table in a
Code:
[code]
[/code]

block (but don't use tabs (!))

Code:
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

Page 2 of 4 All times are UTC + 1 hour [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/