[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [PROGRAMMERING] En pudsig ting med modulus



Per Riber skrev:

Niels Muller Larsen skrev:

Hvem synes du har ret?

IMHO den programmør, som undlader at bruge modulus-funktionen med negative operander. Det andet er noget rod :-)

mvh Per

HM, ja, og dog.
Den konkrete problemstilling var kodning af Game of Life, hvor en celles skæbne afgøres som en funktion af de 8 nabocellers indhold.
Når man står ved venstre eller øverste kant af et to-dimensionalt array, så får nogle af de 8 naboceller negativt index, og så har vi miseren.


Problemet er jo relativt let at løse, men problemstillingen viser dog, at man ikke blindt kan stole på sprogene.

I øvrigt er INGEN af sprogene korrekte i følge den matematiske sagkundskab, hvor resultaterne burde være:

`mod`(13, 5);
3
`mod`(-13, 5);
2
`mod`(13, -5);
3
`mod`(-13, -5);
                              2

jf Maple V10.03. Dette er i overensstemmelse med Tattersalls Elementary Number Theory in Nine Chapters, Grimaldis Discrete and Combinatorial Mathematics og Landrock & Nissens Kryptologi.

Sætningen siger at:

m = q*n + r,  0<= r < n   (sidste del er jo afgørende)

gælder for vilkårlige hele tal m og n med n>0.

Så de to sidstnævnte eksempler skulle måske være 'undefined' i stedet. I så fald er Python, Ruby og Perl jo korrekte.

Hilsen
Niels




 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2006-10-01, 02:01 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *