Warning
This page is located in archive.

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

courses:b3b33alp:cviceni:t13 [2020/01/07 11:11]
stepan created
courses:b3b33alp:cviceni:t13 [2020/01/07 11:46] (current)
stepan
Line 81: Line 81:
     print("​Nelze vyresit"​)     print("​Nelze vyresit"​)
 </​code>​ </​code>​
 +<​code>​
 +def spravne(a):
 +    ret = True
 +    for i in range(len(a)-1):​
 +        roz = len(a)-1-i
 +        if (a[i]-a[-1])==roz or (a[-1]-a[i])==roz:​
 +            ret = False
 +            break
 +    return ret
 +
 +def kralovny(hotovo,​ neumistene):​
 +    print('​s:',​hotovo,​ neumistene)
 +    if len(neumistene)==0:​
 +        return(hotovo)
 +    else:
 +        vysl = []
 +        for i in range(len(neumistene)):​
 +            hotovo2 = [x for x in hotovo]
 +            neumistene2 = [x for x in neumistene]
 +            hotovo2.append(neumistene[i])
 +            if spravne(hotovo2):​
 +                neumistene2.pop(i)
 +                vysl = kralovny(hotovo2,​neumistene2)
 +                if (len(vysl)>​0):​
 +                    break
 +        return vysl
 +
 +print(kralovny([],​ [0,​1,​2,​3,​4,​5,​6,​7]))
 +</​code>​
 +
 +<​code>​
 +def spravne(a):
 +    ret = True
 +    for i in range(len(a)-1):​
 +        roz = len(a)-1-i
 +        if (a[i]-a[-1])==roz or (a[-1]-a[i])==roz:​
 +            ret = False
 +            break
 +    return ret
 +
 +def kralovny(hotovo,​ neumistene, res):
 +    print('​s:',​hotovo,​ neumistene)
 +    if len(neumistene)==0:​
 +        res.append(hotovo)
 +        return []
 +    else:
 +        vysl = []
 +        for i in range(len(neumistene)):​
 +            hotovo2 = [x for x in hotovo]
 +            neumistene2 = [x for x in neumistene]
 +            hotovo2.append(neumistene[i])
 +            if spravne(hotovo2):​
 +                neumistene2.pop(i)
 +                vysl = kralovny(hotovo2,​neumistene2,​ res)
 +                if (len(vysl)>​0):​
 +                    break
 +        return vysl
 +a=[]
 +kralovny([],​ [0,​1,​2,​3,​4,​5,​6,​7],​ a)
 +print(a) ​   ​
 +</​code>​
 +
courses/b3b33alp/cviceni/t13.txt · Last modified: 2020/01/07 11:46 by stepan