1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555
| REM ***** BASIC *****
Dim XN As Integer
Dim Na(4) As String
Sub Main '(NN As Integer, SB As Integer)
rem NN Nombre de cases*cases par bloc : reçu par Sub Dia
rem SB correspond à la difficulté : reçu par Sub Dia
Dim NN as integer
Dim SB as integer
NN = 3
SB = 2
Dim Dok as object
Set Dok = ThisComponent
XN = NN*NN
Dim List(2) As Object
Dim A(XN-1,XN-1) As Integer
Dim Tsvet(NN-1,NN-1) As Long
Dim PN1(XN-1) As Integer
Dim fx(XN-1) As Integer
Dim fx3(XN-1,NN-1,1) As Integer
Dim nx As Integer
Dim PN2(XN-1) As Integer
Dim PN3(NN-1,NN-1) As Integer
Dim PN4(NN-1) As Integer
Dim PN5(XN-1,1) As Integer
Dim StRange As String
Randomize
lig = 1 ' Définition du numéro de ligne pour affichage
col = 1 ' Définition du numéro de colonnes pour affichage
j=3
Dim ZN AS Integer
While ZN<XN
ZN=j*(j-1)*(j-2)
j=j+1
Wend
ZN = j
If ZN<NN then ZN=NN
Dim RN(ZN-1) As Integer
Dok.Sheets.removeByName(Dok.Sheets(2).Name)
Dok.sheets.insertNewByName(1,2)
Dok.Sheets.insertNewByName(2,3)
Dok.Sheets.insertNewByName(3,4)
Dok.Sheets.insertNewByName("Liste données",5)
feuille = Dok.Sheets.getByIndex(5)
rem Fin Affichage --------------------------------------------
lig = 1
Col = 1
feuille.getCellByPosition(0, lig).String = "NN : Nombre de cases*cases par bloc"
lig = lig + 1
feuille.getCellByPosition(col, lig).String = "NN ="
col = col + 1
feuille.getCellByPosition(col, lig).value = NN
lig = lig + 1
col = 1
feuille.getCellByPosition(col, lig).String = "XN ="
col = col + 1
feuille.getCellByPosition(col, lig).value = XN
lig = lig + 1
col = 1
feuille.getCellByPosition(col, lig).String = "ZN ="
col = col + 1
feuille.getCellByPosition(col, lig).value = ZN
lig = lig + 1
col = 1
lig = lig + 1
rem Fin Affichage --------------------------------------------
RN(0)=130+Int(125*rnd)
rem Affichage ------------------------------------------------
col = 2
feuille.getCellByPosition(col, lig).String = "(i)"
lig = lig + 1
col = 1
feuille.getCellByPosition(0, lig).String = "RN(i)=130+(Int(RN(i-1)+10+20*rnd) mod 125)"
ligne = ligne + 1
rem Fin Affichage --------------------------------------------
For i =1 to ZN-1
RN(i)=130+(Int(RN(i-1)+10+20*rnd) mod 125)
rem Affichage ------------------------------------------------
feuille.getCellByPosition(col, lig).String = "RN(" & i &") ="
col = col + 1
feuille.getCellByPosition(col, lig).value = i
col = col + 1
feuille.getCellByPosition(col, lig).value = RN(i)
lig = lig + 1
col = 1
rem Fin Affichage --------------------------------------------
Next
rem Affichage ------------------------------------------------
lig = lig + 1
col = 1
feuille.getCellByPosition(0, lig).String = "ji = 2+Int((ZN-1)*rnd)"
lig = lig + 1
feuille.getCellByPosition(col, lig).String = "(ZN-1) ="
col = col + 1
feuille.getCellByPosition(col, lig).value = ZN-1
lig = lig + 1
col = 1
feuille.getCellByPosition(col, lig).String = "Int((ZN-1)*rnd) ="
col = col + 1
feuille.getCellByPosition(col, lig).value = Int((ZN-1)*rnd)
lig = lig + 1
col = 1
rem Fin Affichage --------------------------------------------
ji = 2+Int((ZN-1)*rnd)
rem Affichage ------------------------------------------------
feuille.getCellByPosition(col, lig).String = "ji ="
col = col + 1
feuille.getCellByPosition(col, lig).value = ji
lig = lig + 1
lig = lig + 1
feuille.getCellByPosition(0, lig).String = "Tsvet(i,j) donne la couleur des cases"
lig = lig + 1
feuille.getCellByPosition(0, lig).String = "Tsvet(i,j) = RGB(RN(i),RN((i+j+1) mod ZN),RN((i+j+ji) mod ZN))"
lig = lig + 1
col = 1
feuille.getCellByPosition(col, lig).String = "NN-1 ="
col = col + 1
feuille.getCellByPosition(col, lig).value = NN-1
lig = lig + 1
col = 1
feuille.getCellByPosition(col, lig).String = "i ="
lig = lig + 1
feuille.getCellByPosition(col, lig).String = "j ="
lig = lig + 1
feuille.getCellByPosition(col, lig).String = "RN(i) ="
lig = lig + 1
feuille.getCellByPosition(col, lig).String = "RN((i+j+1) mod ZN) = "
lig = lig + 1
feuille.getCellByPosition(col, lig).String = "RN((i+j+ji) mod ZN) ="
lig = lig + 1
feuille.getCellByPosition(col, lig).String = "Red ="
lig = lig + 1
feuille.getCellByPosition(col, lig).String = "Green ="
lig = lig + 1
feuille.getCellByPosition(col, lig).String = "Blue ="
lig = lig + 1
feuille.getCellByPosition(col, lig).String = "Tsvet(i,j) ="
col = 2
rem Fin Affichage --------------------------------------------
For i =1 to NN-1
For j=0 to NN-1
Tsvet(i,j) = RGB(RN(i),RN((i+j+1) mod ZN),RN((i+j+ji) mod ZN))
RN(i) = 130+(Int(RN(i-1)+10+20*rnd) mod 125)
RN((i+j+1) mod ZN) = 130+(Int(RN(i-1)+10+20*rnd) mod 125)
RN((i+j+ji) mod ZN) = 130+(Int(RN(i-1)+10+20*rnd) mod 125)
RGB1 = RN(i)
RGB2 = RN((i+j+1) mod ZN)
RGB3 = RN((i+j+ji) mod ZN)
rem Affichage ------------------------------------------------
lig = lig - 8
feuille.getCellByPosition(col, lig).value = i
lig = lig + 1
feuille.getCellByPosition(col, lig).value = j
lig = lig + 1
feuille.getCellByPosition(col, lig).value = RN(i)
lig = lig + 1
feuille.getCellByPosition(col, lig).value = RN((i+j+1) mod ZN)
lig = lig + 1
feuille.getCellByPosition(col, lig).value = RN((i+j+ji) mod ZN)
lig = lig + 1
feuille.getCellByPosition(col, lig).value = RGB1
lig = lig + 1
feuille.getCellByPosition(col, lig).value = RGB2
lig = lig + 1
feuille.getCellByPosition(col, lig).value = RGB3
lig = lig + 1
feuille.getCellByPosition(col, lig).value = Tsvet(i,j)
col = col + 1
rem Fin Affichage --------------------------------------------
Next
Next
Dok.Sheets.removeByName(Dok.Sheets(0).Name)
Dok.Sheets.removeByName(Dok.Sheets(0).Name)
List(0)=Dok.Sheets(0)
rem Affichage ------------------------------------------------
Col = 1
lig = lig + 2
feuille.getCellByPosition(col, lig).String = "(i) ="
lig = lig + 1
feuille.getCellByPosition(col, lig).String = "PN1(i) ="
lig = lig + 1
feuille.getCellByPosition(col, lig).String = "A(i,0) ="
col = 2
rem Fin Affichage --------------------------------------------
For i=0 to 2
List(i) = Dok.Sheets(i)
Dok.Sheets(i).Name = Na(i)
next
For i =0 to XN-1
PN1(i) = i+1
A(i,0)= i+1
rem Affichage ------------------------------------------------
lig = lig - 2
feuille.getCellByPosition(col, lig).value = i
lig = lig + 1
feuille.getCellByPosition(col, lig).value = PN1(i)
lig = lig + 1
feuille.getCellByPosition(col, lig).value = A(i,0)
col = col + 1
rem Fin Affichage --------------------------------------------
Next
rem Affichage ------------------------------------------------
col = 1
lig = lig + 2
feuille.getCellByPosition(col, lig).String = "(i) ="
lig = lig + 1
feuille.getCellByPosition(col, lig).String = "YN ="
lig = lig + 1
feuille.getCellByPosition(col, lig).String = "(i+YN) mod XN ="
lig = lig + 1
feuille.getCellByPosition(col, lig).String = "A((i+YN) mod XN,j) ="
col = 2
rem Fin Affichage --------------------------------------------
For j=1 to XN-1
YN = j*NN + Int(j/NN)
For i =0 to XN-1
A((i+YN) mod XN,j) = A(i,0)
rem Affichage ------------------------------------------------
lig = lig - 3
feuille.getCellByPosition(col, lig).value = i
lig = lig + 1
feuille.getCellByPosition(col, lig).value = YN
lig = lig + 1
feuille.getCellByPosition(col, lig).value = (i+YN) mod XN
lig = lig + 1
feuille.getCellByPosition(col, lig).value = A((i+YN) mod XN,j)
col = col + 1
rem Fin Affichage --------------------------------------------
Next i
Next j
rem Affichage ------------------------------------------------
col = 1
lig = lig + 2
feuille.getCellByPosition(col, lig).String = "(i) ="
lig = lig + 1
feuille.getCellByPosition(col, lig).String = "nx ="
lig = lig + 1
feuille.getCellByPosition(col, lig).String = "PN2(XN-1) ="
lig = lig + 1
feuille.getCellByPosition(col, lig).String = "fx(XN-1) ="
col = 2
rem Fin Affichage --------------------------------------------
i=0
nx = Int(XN*rnd)
PN2(0) = PN1(nx)
fx(nx)=1
While i<XN-1
nx = Int(XN*rnd)
If fx(nx)=0 then
i=i+1
PN2(i) = PN1(nx)
fx(nx)=1
rem Affichage ------------------------------------------------
lig = lig - 3
feuille.getCellByPosition(col, lig).value = i
lig = lig + 1
feuille.getCellByPosition(col, lig).value = nx
lig = lig + 1
feuille.getCellByPosition(col, lig).value = PN2(i)
lig = lig + 1
feuille.getCellByPosition(col, lig).value = fx(nx)
col = col + 1
rem Fin Affichage --------------------------------------------
Endif
Wend
rem Affichage ------------------------------------------------
lig = lig + 2
col = 1
feuille.getCellByPosition(col, lig).String = "XN-1 ="
col = col + 1
feuille.getCellByPosition(col, lig).value = XN-1
lig = lig + 2
col = 1
feuille.getCellByPosition(col, lig).String = "PN4(NN-1) ="
lig = lig + 1
feuille.getCellByPosition(col, lig).String = "(NN-1) ="
lig = lig + 1
feuille.getCellByPosition(col, lig).String = "i ="
lig = lig + 1
feuille.getCellByPosition(col, lig).String = "j ="
lig = lig + 1
feuille.getCellByPosition(col, lig).String = "k ="
lig = lig + 1
feuille.getCellByPosition(col, lig).String = "PN3(NN-1,NN-1) ="
lig = lig + 1
feuille.getCellByPosition(col, lig).String = "nx ="
lig = lig + 1
feuille.getCellByPosition(col, lig).String = "fx(XN-1) ="
lig = lig + 1
feuille.getCellByPosition(col, lig).String = "fx3(XN-1,NN-1,1) ="
lig = lig + 2
feuille.getCellByPosition(col, lig).String = "i ="
lig = lig + 1
feuille.getCellByPosition(col, lig).String = "k ="
lig = lig + 1
feuille.getCellByPosition(col, lig).String = "zz ="
lig = lig + 1
feuille.getCellByPosition(col, lig).String = "NN ="
lig = lig + 1
feuille.getCellByPosition(col, lig).String = "i mod NN ="
lig = lig + 1
feuille.getCellByPosition(col, lig).String = "NN-1 ="
lig = lig + 1
feuille.getCellByPosition(0, lig).String = "PN5(XN-1,1), PN5(i,k)=zz*NN+PN3(i mod NN,zz)"
feuille.getCellByPosition(col, lig).String = "PN5(XN-1,1) ="
col = 2
lig = lig - 16
rem Fin Affichage --------------------------------------------
For i=0 to NN-1
PN4(i) = i
rem Affichage boucle -----------------------------------------
feuille.getCellByPosition(col, lig).value = PN4(i)
col = col + 1
rem Fin Affichage --------------------------------------------
Next
rem Affichage ------------------------------------------------
col = 2
lig = lig + 1
rem Fin Affichage --------------------------------------------
For k=0 to 1
For j=0 to NN-1
i=0
nx = Int(NN*rnd)
PN3(0,j) = PN4(nx)
fx3(nx,j,k)=1
While i<NN-1
nx = Int(NN*rnd)
If fx3(nx,j,k)=0 then
i=i+1
PN3(i,j) = PN4(nx)
fx3(nx,j,k)=1
Endif
Wend
rem Affichage boucle -----------------------------------------
feuille.getCellByPosition(col, lig).value = NN-1
lig = lig + 1
feuille.getCellByPosition(col, lig).value = i
lig = lig + 1
feuille.getCellByPosition(col, lig).value = j
lig = lig + 1
feuille.getCellByPosition(col, lig).value = k
lig = lig + 1
feuille.getCellByPosition(col, lig).value = PN3(0,j)
lig = lig + 1
feuille.getCellByPosition(col, lig).value = nx
lig = lig + 1
feuille.getCellByPosition(col, lig).value = fx(nx)
lig = lig + 1
feuille.getCellByPosition(col, lig).value = fx3(nx,j,k)
col = col + 1
lig = lig - 7
rem Fin Affichage --------------------------------------------
Next
rem Affichage ------------------------------------------------
lig = lig + 9
rem Fin Affichage --------------------------------------------
For i=0 to XN-1
zz = Int(i/NN)
rem Affichage boucle -----------------------------------------
feuille.getCellByPosition(col, lig).value = i
lig = lig + 1
feuille.getCellByPosition(col, lig).value = k
lig = lig + 1
feuille.getCellByPosition(col, lig).value = zz
lig = lig + 1
feuille.getCellByPosition(col, lig).value = NN
lig = lig + 1
feuille.getCellByPosition(col, lig).value = i mod NN
lig = lig + 1
feuille.getCellByPosition(col, lig).value = NN-1
lig = lig + 2
rem Fin Affichage --------------------------------------------
PN5(i,k)=zz*NN+PN3(i mod NN,zz)
rem Affichage ------------------------------------------------
feuille.getCellByPosition(col, lig).value = PN5(i,k)
col = col + 1
lig = lig - 7
rem Fin Affichage --------------------------------------------
Next
lig = lig - 9
col = col + 1
Next k
rem Affichage ------------------------------------------------
col = 1
lig = lig + 16
feuille.getCellByPosition(0, lig).string = "List(2).getCellByPosition(i,j).Value = A(i,j)"
feuille.getCellByPosition(col, lig).string = "List(2)"
col = col + 1
print "Définition grille sur feuille3"
rem Fin Affichage --------------------------------------------
For i =0 to XN-1
For j=0 to XN-1
List(2).getCellByPosition(i,j).Value = A(i,j)
rem Affichage ------------------------------------------------
feuille.getCellByPosition(col, lig).value = A(i,j)
col = col + 1
rem Fin Affichage --------------------------------------------
Next
Next
rem Affichage ------------------------------------------------
col = 1
lig = lig + 1
feuille.getCellByPosition(0, lig).string = "List(1).getCellByPosition(i,j).Value = PN2(A(PN5(i,0),PN5(j,1))-1)"
feuille.getCellByPosition(col, lig).string = "List(1)"
col = col + 1
print "Définition grille sur feuille2"
rem Fin Affichage --------------------------------------------
For i =0 to XN-1
For j=0 to XN-1
List(1).getCellByPosition(i,j).Value = PN2(A(PN5(i,0),PN5(j,1))-1)
rem Affichage ------------------------------------------------
feuille.getCellByPosition(col, lig).value = PN2(A(PN5(i,0),PN5(j,1))-1)
col = col + 1
rem Fin Affichage --------------------------------------------
Next
Next
rem Affichage ------------------------------------------------
col = 1
lig = lig + 1
feuille.getCellByPosition(0, lig).string = "List(0).getCellByPosition(i,j).Formula = ''=''+Na(1)+''.''+List(0).Columns(i).Name+cStr(j+1)"
feuille.getCellByPosition(col, lig).string = "List(0)"
col = col + 1
print "Définition grille sur feuille1"
rem Fin Affichage --------------------------------------------
For i =0 to XN-1
For j=0 to XN-1
rem code remplacé : = "="+Na(1)+"."+List(0).Columns(i).Name+cStr(j+1)
List(0).getCellByPosition(i,j).Formula = "="+2+"."+List(0).Columns(i).Name+cStr(j+1)
List(0).getCellByPosition(i,j).CharColor = 0
rem Affichage ------------------------------------------------
feuille.getCellByPosition(col, lig).value = "="+2+"."+List(0).Columns(i).Name+cStr(j+1)
col = col + 1
rem Fin Affichage --------------------------------------------
Next
Next
rem Affichage ------------------------------------------------
Col = 1
lig = lig + 2
feuille.getCellByPosition(col, lig).string = "Mx ="
lig = lig + 1
feuille.getCellByPosition(col, lig).string = "NN mod PN(Mx) ="
col = col + 1
lig = lig - 1
rem Fin Affichage --------------------------------------------
Dim M(SB-1) As Integer
PN() = Array(2,3,5,7,11,13,17,19,23,29,31)
Mx = 0
For k=0 to SB-1
Do
Mx = (Mx+1+Int(4*rnd)) mod 11
rem Affichage ------------------------------------------------
feuille.getCellByPosition(col, lig).value = Mx
lig = lig + 1
feuille.getCellByPosition(col, lig).value = NN mod PN(Mx)
col = col + 1
lig = lig - 1
rem Fin Affichage --------------------------------------------
Loop Until (NN mod PN(Mx))<>0
M(k) = PN(Mx) ' M = pas d'effacement
Next
rem Effacement des cases selon le pas M(j):
For j=0 to SB-1
For i=0 to (XN*XN)-1 step M(j)
List(0).getCellByPosition(Int(i/XN),i mod XN).Formula = ""
List(0).getCellByPosition(Int(i/XN),i mod XN).CharColor = 2302940
Next
Next
With List(0).Columns(XN+1)
.Width = 6000
.CharHeight = 12
.IsTextWrapped = TRUE
.HoriJustify = com.sun.star.table.CellHoriJustify.RIGHT
.VertJustify = com.sun.star.table.CellVertJustify.BOTTOM
End With
With List(0).Columns(XN+2)
.CharHeight = 12
.HoriJustify = com.sun.star.table.CellHoriJustify.LEFT
.VertJustify = com.sun.star.table.CellVertJustify.BOTTOM
End With
List(0).getCellByPosition(XN+1,0).String = Na(3)
List(0).getCellByPosition(XN+2,0).Formula = "="+cStr(XN*XN)+"-COUNTA("+StRange+")"
List(0).getCellByPosition(XN+1,1).Formula = "=IF("+List(0).Columns(XN+2).Name+"1=0;"+Na(4)+";"""")"
List(0).getCellByPosition(XN+2,1).ArrayFormula = "=IF("+List(0).Columns(XN+2).Name+"1=0;SUM(IF("+Na(0)+"."+StRange+"-"+Na(1)+"."+StRange+"=0;"""";1));"""")"
List(0).getCellRangeByName(List(0).Columns(XN+1).Name+"1"+":"+List(0).Columns(XN+2).Name+"3").CellBackColor = RGB(200+50*rnd,200+50*rnd,200+50*rnd)
Dok.setModified(FALSE)
End Sub |
Partager