rage / ohjelmointi-22

6 stars 6 forks source link

Osa05-08_sudoku_osa6: 4. tarkistus virheellinen? #65

Closed nuburgeri closed 2 years ago

nuburgeri commented 2 years ago

Koodi:

def kopioi_ja_lisaa(sudoku: list, rivi: int, sarake: int, luku: int):
    kopio = []
    kopio[:] = sudoku
    kopio[rivi][sarake] = luku
    return kopio

Aiheuttaa virheen:

s = [
  [ 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
  [ 0, 5, 0, 0, 0, 0, 0, 0, 0 ],
  [ 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
  [ 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
  [ 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
  [ 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
  [ 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
  [ 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
  [ 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
]
vast = kopioi_ja_lisaa(s, 1, 1, 5)
palauttaman matriisin vast rivin 1 pitäisi edelleen olla:
[0, 0, 0, 0, 0, 0, 0, 0, 0]:
se kuitenkin muuttunut muotoon:
[0, 5, 0, 0, 0, 0, 0, 0, 0]

Jo parametrina annetun sudokun rivi 1 on 0,5,0,...