Chuyển đến nội dung chính

Permutation -- Liet Ke Hoan vi

def lietkehoanvi(arr, output=[]):
    for i in arr:
        if i not in output:
            output.append(i)
            if len(output) == len(arr):
                print output
            else:
                lietkehoanvi(arr, output)
            output.pop()

lietkehoanvi([1,2,3,4])

---------------------------


for i in [x*x for x in range(1,6)]:
    print i

for i in (x*x for x in range(1,6)):
    print i

def generator():
    for i in range(1,6):
        yield i*i

for i in generator():
    print i

-------------------------------------

class HoanVi():
    def __init__(self, data):
        self._data = data
        self._out = []
   
    def __iter__(self):
        return self.next()

    def next(self):
        for i in self._data:
            if i not in self._out:
                self._out.append(i)
                if len(self._out) == len(self._data):
                    yield self._out
                else:
                    for v in self.next():
                        yield v
                self._out.pop()

for i in HoanVi([1,2,3,4]):
    print i

------------------------



import copy


class HoanVi():
    _data = []
    _result = []
    _out = []
   
       
    def __init__(self, arr):
        self._data = arr[:]
        self.hoanvi()
       
    def hoanvi(self):
        for i in self._data:
            if i not in self._out:
                self._out.append(i)
                if len(self._out) == len(self._data):
                    a = copy.copy(self._out)
                    self._result.append(a)
                else:
                    self.hoanvi()
                self._out.pop()
   
   
a = HoanVi([1,5,3,6])
for i in a._result:
    print i

-------------------------
[1, 5, 3, 6]
[1, 5, 6, 3]
[1, 3, 5, 6]
[1, 3, 6, 5]
[1, 6, 5, 3]
[1, 6, 3, 5]
[5, 1, 3, 6]
[5, 1, 6, 3]
[5, 3, 1, 6]
[5, 3, 6, 1]
[5, 6, 1, 3]
[5, 6, 3, 1]
[3, 1, 5, 6]
[3, 1, 6, 5]
[3, 5, 1, 6]
[3, 5, 6, 1]
[3, 6, 1, 5]
[3, 6, 5, 1]
[6, 1, 5, 3]
[6, 1, 3, 5]
[6, 5, 1, 3]
[6, 5, 3, 1]
[6, 3, 1, 5]
[6, 3, 5, 1]

Nhận xét

Bài đăng phổ biến từ blog này

Windows 10 enable long file/folder path

Windows 10 enable long file/folder path Registry Import Enabling Long Paths Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\FileSystem] "LongPathsEnabled"=dword:00000001 [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem] "LongPathsEnabled"=dword:00000001 Enable via group policy editor Local Computer Policy -> Computer Configuration -> Administrative Templates -> System -> FileSystem -> Double click Enable Win32 long paths and select Enabled

Xcode 8 support devices ios 7

Tải XCode 5.1.1 về, copy 2 folder 7.0 & 7.1 trong thư mục /Volumes/Xcode/ Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport sang thư mục DeviceSupport của phiên bản XCode 8 (hiện tại) Mở file SDKSetting.plist trong thư mục /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk Thêm giá trị 7.0 & 7.1 vào key Root->DefaultProperties->DEPLOYMENT_TARGET_SUGGESTED_VALUE Thoát XCode & khởi động lại XCode

Tạo đĩa cứu hộ DLCD chuẩn UEFI

Chạy CMD dưới quyền quản trị (admin), nếu như bạn đang sử dụng Windows 8 trở lên thì nhấn tổ hợp phím “Windows + X” và chọn “Command Prompt (Admin)” Cửa sổ “Command Prompt” hiện ra bạn gõ lệnh  DISKPART  > gõ tiếp lệnh  LIST DISK  để nó liệt kê ra toàn bộ ổ cứng của bạn. Tạo usb chuẩn UEFI chứa bộ cài Windows Ví dụ như trong hình thì Disk 1 là USB và Disk 0 sẽ là ổ cứng, bạn nhìn vào dung lượng (Size) để biết được chính xác đâu là Disk của usb nhé. + Sau khi bạn đã biết được chính xác đâu là DISK của USB thì gõ tiếp lệnh  SELECT DISK   x  (x là số DISK của USB). Ví dụ như trong hình trên, mình sẽ gõ chính xác dòng lệnh như sau:  SELECT DISK 1 Các bạn làm theo chính xác các lệnh sau: CLEAN – Lệnh này sẽ xóa sạch dữ liệu trên ổ bạn đã chọn (ơ đây là USB). CON GPT – Lệnh này sẽ chuyển sang định dạng GPT. CREATE PARTITION PRIMARY – Lệnh này sẽ tạo Partion cho toàn bộ ổ đĩa mà bạn đã lựa chọn. FORMAT QUICK...