Author 
Message 
paulv66
Posted on: Wed May 13, 2020 10:32 am
Posts: 917 Location: Ukraine Joined: Tue Mar 01, 2016 10:03 pm

Re: 4 to 4 puzzle combos
Looking at the above table, it seems that there is consistency across the various programming languages if and only if the sign of both numbers is the same. The dilemma would therefore be solved by having this as one of the conditions of a cage featuring the mod operator i.e. the sign of the value of the cage determines the sign of both numbers in the cage.
I can’t remember if this is the approach that was used in the books for puzzles featuring the mod operator and negative numbers.




skeeter84
Posted on: Wed May 13, 2020 11:20 am
Posts: 123 Joined: Tue Apr 24, 2012 7:47 pm

Re: 4 to 4 puzzle combos
Hi, guys  hopefully everybody is staying safe from COVID19. fzpowerman is trying to complete a few book puzzles involving negative modulo cages. I'm willing to compile tables, but I'll need some serious "briefing" before doing so. I took QBasic in college, but I was NOT a comp sci major. I never remembered coming across the modulo operator, and my class was in spring 2005 if memory serves correctly. As a website administrator, Patrick is likely in the best position to explain how negative modulo operators work. Of course, I welcome input from clm, bram, etc. and any computer programmers on calcudoku.org. Patrick's table is very helpful, and I'd better understand negative modulo operators if he could explain his table to me. Anyhow, my lack of understanding is why I haven't made tables yet and I apologize for my delayed response.
skeeter84




paulv66
Posted on: Wed May 13, 2020 11:51 am
Posts: 917 Location: Ukraine Joined: Tue Mar 01, 2016 10:03 pm

Re: 4 to 4 puzzle combos
I’ve completed all the books. If it’s any help, I could have a look at one of the puzzles that is causing problems for fzpowerman to see if I can identify what the issue is.




fzpowerman47
Posted on: Wed May 13, 2020 1:58 pm
Posts: 76 Joined: Fri May 13, 2011 1:16 am

Re: 4 to 4 puzzle combos
I tried to do many times puzzles with mod and negative numbers but I make mistakes everytime. For example, a cage of 2 cells with "0mod", what are the possible solutions with negative numbers ? I don't know... 1 and 2 ? 1 and 3 ? 1 and 0 ? Or a cage with "1mod", we can have 1 and 2 ? 1 and 3 ? I don't know if I'm speaking clearly... I have no problem with positive numbers but with negative numbers, I'm lost...




fzpowerman47
Posted on: Wed May 13, 2020 2:06 pm
Posts: 76 Joined: Fri May 13, 2011 1:16 am

Re: 4 to 4 puzzle combos
with numbers between 0 and 9, I think all solutions are :
0mod : 12,13,14,15,16,17,18,19,24,26,28,36,39,48 1mod : 12,13,14,15,16,17,18,19,23,25,27,29,34,37,45,49,56,67,78,89 2mod : 23,24,25,26,27,28,29,35,38,46,57,68,79 3mod : 34,35,36,37,38,39,47,58,69 4mod : 45,46,47,48,49,59 5mod : 56,57,58,59 6mod : 67,68,69 7mod : 78,79 8mod : 89
But with negative numbers, I don't know...




paulv66
Posted on: Wed May 13, 2020 4:35 pm
Posts: 917 Location: Ukraine Joined: Tue Mar 01, 2016 10:03 pm

Re: 4 to 4 puzzle combos
I remembered having a problem with this particular issue a while back and I found this thread about it viewtopic.php?f=3&t=1089 It wasn't really resolved then and it looks as if it's still hanging. There's no consensus about how the mod function should work with negative numbers and my personal view is that the concept of using the mod function with negative numbers is meaningless, a bit like division by zero. There were only 4 puzzles in the book that had a combination of negative numbers and the mod function. 3 of these were 9x9, with numbers from 1 to +7 and the other was 11x11 with numbers from 5 to +5. They all caused me some difficulty, in particular a4v14. My advice to you is not to waste any more time trying to figure out how the mod function works with negative numbers, as it really won't help you to solve these particular puzzles. SPOILER ALERT: I'm going to explain below why it's irrelevant for these puzzles. I don't think this is really giving anything away, but don't read on if you feel that doing so would give you any unfair assistance in tackling these problems. In the 9x9 puzzles, 1 does not appear in any of the mod cages, so the question of how to deal with negative numbers does not arise. In the 11x11 puzzle, all the mod cages had 0 value. The use of negative numbers is not really an issue when the answer is 0.




fzpowerman47
Posted on: Wed May 13, 2020 6:16 pm
Posts: 76 Joined: Fri May 13, 2011 1:16 am

Re: 4 to 4 puzzle combos
ok, thank for your answer, Paulv66, it will help me. I'll try again to finish these puzzle




clm
Posted on: Wed May 13, 2020 10:25 pm
Posts: 840 Joined: Fri May 13, 2011 6:51 pm

Re: 4 to 4 puzzle combos
fzpowerman47 wrote: I tried to do many times puzzles with mod and negative numbers but I make mistakes everytime. For example, a cage of 2 cells with "0mod", what are the possible solutions with negative numbers ? I don't know... 1 and 2 ? 1 and 3 ? 1 and 0 ? Or a cage with "1mod", we can have 1 and 2 ? 1 and 3 ? I don't know if I'm speaking clearly... I have no problem with positive numbers but with negative numbers, I'm lost... If you divide 1 by 2 the quotient is 0 then as 0 x (2) = 0 the remainder is 1, but if you divide 2 by 1 the quotient is 2, then 2 x (1) = 2 and the remainder is 0 (2  [2] = 2 + 2 = 0). Case 1 and 3, quotient is 0, remainder is 1, while in case 3 and 1 quotient is 3, 3 x (1) = 3 and the remainder is 0 (3  [3] = 3 + 3 = 0). Case 1 and 0: Since the division by 0 is not allowed, 1 and 0 can only be considered as 0 divided by 1, quotient 0, remainder 0. For the other question I would answer that, consequently, in no case, with 1 and 2 or with 1 and 3 you will have “1 mod”, only “1 mod” or “0 mod” (in both cases). I will propose you a table and later I will make some comments: ________  5_____ 4_____ 3_____ 2_____ 1_____0_____1_____2_____3_____4_____5 ___  5___________ 1______ 2______ 1______0_____N/A_____0_____ 1____ 2_____ 1_____0 ___  4___ 4______________ 1_______0______0_____N/A_____0______0_____ 1______0____ 4 ___  3___ 3______ 3______________ 1______0_____N/A_____0_____ 1_____0_____ 3____ 3 ___  2___ 2______ 2______ 2______________0_____N/A_____0______0____ 2_____ 2____ 2 ___  1___ 1______ 1______ 1______ 1____________N/A_____0_____ 1____ 1_____ 1____ 1 ____ 0____0_______0_______0_______0______0______N/A_____0______0_____0_______0_____0 ____ 1____1_______1_______1_______1______0______N/A____________1_____1_______1_____1 ____ 2____2_______2_______2_______0______0______N/A_____0____________2_______2_____2 ____ 3____3_______3_______0_______1______0______N/A_____0______1_____________3_____3 ____ 4____4_______0_______1_______0______0______N/A_____0______0_____1_____________4 ____ 5____0_______1_______2_______1______0______N/A_____0______1_____2_______1______ To get a result you use the coordinates, that is, i.e., 3 mod 4 = 3. To use the table inversely we look for the result inside, i.e., “4 mod” could be [5, 4] or [4, 5]. For “3 mod” you find in the table four possible combinations, eight combinations for “2 mod”, etc.. To obtain this table I have followed a “natural” thinking, making the division, …, instead of successive subtractions … . For instance, in the Code table provided by Patrick, for the first 7 languages (from C to Javascript) the operation “13 mod 3” gives a result of 1, this is because you have a quotient of 4 (with positive sign since you divide two negative signs), so 4 x (3) = 12 and the remainder is 13 – (12) = 13 + 12 = 1. Similarly, “13 mod 3”, quotient is 4, then (4) x 3 = 12, remainder: 13 – (12) = 1. With languages Ruby or Python it seems that, for instance, in “13 mod 3”, a quotient of 5 (lower than 4) is taken, then (5) x (3) = 15, remainder 13 – 15 = 2, etc.. Since there are dozens of languages, Patrick should specify more precisely the way the modulo operation is evaluated in his software, I mean in the preamble of the books, since this operation, modulo with negative numbers, does not appear for the moment in the daily puzzles. Generally speaking, the modulo operation between two numbers D and d, was conceived for positive integers, such that “D mod d” = r, with a dividend (D), a divisor (d) (different from zero), a quotient (q) and a remainder (r). The result of the modulo operation is the remainder r, with r < d, and being both positive, obviously, r < d (the bars indicate the absolute value). This creates the “classes of equivalence”. For instance, if you go to the Wikipedia you find this: “In mathematics, the result of the modulo operation is an equivalence class, and any member of the class may be chosen as representative; however, the usual representative is the least positive residue, the smallest nonnegative integer that belongs to that class, i.e. the remainder of the Euclidean division. However, other conventions are possible. Computers and calculators have various ways of storing and representing numbers; thus their definition of the modulo operation depends on the programming language or the underlying hardware”. The concept of the modulo operation may be extended, as exposed by jpoos in a previous thread (the link provided by paulv66), to negative numbers (dividend, divisor or both) or even fractional numbers. And this brings new uncertainties and complexity, i.e., considering only integers you can find two results for the operation, one positive and one negative, though both accomplish the condition r < d. See this comment in the Wikipedia: “In nearly all computing systems, the quotient q and the remainder r of a (D) divided by n (d) satisfy these conditions
q is a member of Z (the set Z includes all positive and negative integers including 0) (My note: More precisely, in my approach, the 0 should be excluded, so leaving the sets N+ and N) D = dq + r r<d
However, this still leaves a sign ambiguity if the remainder is nonzero: two possible choices for the remainder occur, one negative and the other positive, and two possible choices for the quotient occur. Usually, in number theory, the positive remainder is always chosen, but programming languages choose depending on the language and the signs of a(D) or n (d)”.




fzpowerman47
Posted on: Wed May 13, 2020 11:49 pm
Posts: 76 Joined: Fri May 13, 2011 1:16 am

Re: 4 to 4 puzzle combos
cool, thank you clm, it's clear in my head, now ! your table is perfect for me, I'll succeed to finish my 4 book puzzles, I know it now, it's nice, thank again




skeeter84
Posted on: Thu May 14, 2020 12:08 am
Posts: 123 Joined: Tue Apr 24, 2012 7:47 pm

Re: 4 to 4 puzzle combos
Hi, fzpowerman. I'm glad clm was able to clear things up for you regarding the negative modulo operator. I simply didn't understand how negative modulo operators work, and I didn't want you to have to start your puzzles all over had I made any mistakes. I'm sorry for my lack of knowledge concerning negative modulo operators. skeeter84






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

