View unanswered posts | View active topics It is currently Thu Mar 28, 2024 7:45 pm



← Back to the Calcudoku puzzle page




Reply to topic  [ 34 posts ]  Go to page Previous  1, 2, 3, 4  Next
 -4 to 4 puzzle combos 
Author Message

Posted on: Tue Apr 07, 2020 8:41 am




Posts: 135
Joined: Tue Apr 24, 2012 7:47 pm
Post 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


Profile

Posted on: Tue Apr 07, 2020 9:32 am




Posts: 74
Joined: Tue Mar 10, 2015 5:59 pm
Post 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


Profile

Posted on: Tue Apr 07, 2020 4:37 pm




Posts: 135
Joined: Tue Apr 24, 2012 7:47 pm
Post 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


Profile

Posted on: Tue Apr 07, 2020 9:24 pm




Posts: 74
Joined: Tue Mar 10, 2015 5:59 pm
Post 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.


Profile
User avatar

Posted on: Wed Apr 08, 2020 10:49 am




Posts: 3296
Joined: Thu May 12, 2011 11:58 pm
Post Re: -4 to 4 puzzle combos
Hm, I see I never followed up on that, [huh]
will look into this..


Profile

Posted on: Wed Apr 08, 2020 4:01 pm




Posts: 158
Joined: Sun Nov 03, 2013 10:28 pm
Post 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.


Profile

Posted on: Thu Apr 09, 2020 5:20 am




Posts: 18
Joined: Sun Mar 11, 2012 8:48 pm
Post 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?


Profile

Posted on: Thu Apr 09, 2020 7:51 am




Posts: 74
Joined: Tue Mar 10, 2015 5:59 pm
Post 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.


Profile

Posted on: Tue May 12, 2020 11:25 pm




Posts: 81
Joined: Fri May 13, 2011 1:16 am
Post 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


Profile
User avatar

Posted on: Wed May 13, 2020 8:59 am




Posts: 3296
Joined: Thu May 12, 2011 11:58 pm
Post 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


Profile
Display posts from previous:  Sort by  
Reply to topic   [ 34 posts ]  Go to page Previous  1, 2, 3, 4  Next

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
All forum contents © Patrick Min, and by the post authors.

Forum software phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware.