Source code online books for professionals by professionals


IMpLeMeNtING the CheCKerBOarD COVerING



Download 4,67 Mb.
Pdf ko'rish
bet51/266
Sana31.12.2021
Hajmi4,67 Mb.
#213682
1   ...   47   48   49   50   51   52   53   54   ...   266
Bog'liq
2 5296731884800181221

IMpLeMeNtING the CheCKerBOarD COVerING
although the checkerboard covering problem has a very easy recursive solution conceptually, implementing it can 
require a bit of thinking. the details of the implementation aren’t crucial to the main point of the example, so feel 
free to skip this sidebar, if you want. one way of implementing a solution is shown here:
 
def cover(board, lab=1, top=0, left=0, side=None):
    if side is None: side = len(board)
 
    # Side length of subboard:
    s = side // 2
 
    # Offsets for outer/inner squares of subboards:
    offsets = (0, -1), (side-1, 0)
 
    for dy_outer, dy_inner in offsets:
        for dx_outer, dx_inner in offsets:
            # If the outer corner is not set...
            if not board[top+dy_outer][left+dx_outer]:
                # ... label the inner corner:
                board[top+s+dy_inner][left+s+dx_inner] = lab
 
    # Next label:
    lab += 1
    if s > 1:
        for dy in [0, s]:
            for dx in [0, s]:
                # Recursive calls, if s is at least 2:
                lab = cover(board, lab, top+dy, left+dx, s)
 
    # Return the next available label:
    return lab
 

Download 4,67 Mb.

Do'stlaringiz bilan baham:
1   ...   47   48   49   50   51   52   53   54   ...   266




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish