From 0b7f08298d49e3972e381f33b49013a4a54b9289 Mon Sep 17 00:00:00 2001 From: Andrew-Kochanov Date: Wed, 24 Sep 2025 21:25:41 +0300 Subject: [PATCH 1/4] =?UTF-8?q?=D0=9D=D0=B0=D0=BF=D0=B8=D1=81=D0=B0=D0=BB?= =?UTF-8?q?=20=D0=BF=D1=80=D0=BE=D0=B3=D1=80=D0=B0=D0=BC=D0=BC=D1=83=20?= =?UTF-8?q?=D1=81=D0=BE=D1=80=D1=82=D0=B8=D1=80=D0=BE=D0=B2=D0=BA=D0=B8=20?= =?UTF-8?q?=D0=BF=D1=83=D0=B7=D1=8B=D1=80=D1=8C=D0=BA=D0=BE=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bubble | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 bubble diff --git a/bubble b/bubble new file mode 100644 index 0000000..cb231d9 --- /dev/null +++ b/bubble @@ -0,0 +1,8 @@ +from random import randint + +checklist = [randint(1, 1000) for i in range(15)] +for index_1 in range(len(checklist) - 1): + for index_2 in range(index_1 + 1, len(checklist)): + if checklist[index_1] > checklist[index_2]: + checklist[index_1], checklist[index_2] = checklist[index_2], checklist[index_1] +print(*checklist) From d0237674441610d0ad46073b6849ff7bf535d480 Mon Sep 17 00:00:00 2001 From: Andrew-Kochanov Date: Thu, 2 Oct 2025 13:20:51 +0300 Subject: [PATCH 2/4] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB?= =?UTF-8?q?=20=D0=BD=D0=BE=D1=80=D0=BC=D0=B0=D0=BB=D1=8C=D0=BD=D1=8B=D0=B5?= =?UTF-8?q?=20=D0=BA=D0=BE=D0=BC=D0=BC=D0=B5=D0=BD=D1=82=D0=B0=D1=80=D0=B8?= =?UTF-8?q?=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bubble | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/bubble b/bubble index cb231d9..2e4a957 100644 --- a/bubble +++ b/bubble @@ -1,8 +1,12 @@ from random import randint +## массив с рандомными цифрами checklist = [randint(1, 1000) for i in range(15)] +print(*checklist) for index_1 in range(len(checklist) - 1): for index_2 in range(index_1 + 1, len(checklist)): + + ## сравнение и перестановка if checklist[index_1] > checklist[index_2]: checklist[index_1], checklist[index_2] = checklist[index_2], checklist[index_1] print(*checklist) From be97038811a9475686b3224720d133a5f840cdda Mon Sep 17 00:00:00 2001 From: Andrew-Kochanov Date: Thu, 2 Oct 2025 23:20:40 +0300 Subject: [PATCH 3/4] =?UTF-8?q?=D0=92=D1=8B=D0=B4=D0=B5=D0=BB=D0=B8=D0=BB?= =?UTF-8?q?=20=D1=81=D0=BE=D1=80=D1=82=D0=B8=D1=80=D0=BE=D0=B2=D0=BA=D1=83?= =?UTF-8?q?=20=D0=B2=20=D1=84=D1=83=D0=BD=D0=BA=D1=86=D0=B8=D1=8E,=20?= =?UTF-8?q?=D0=B0=20=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BA=D0=B8=20?= =?UTF-8?q?=D0=B8=20=D0=B2=D1=8B=D0=B2=D0=BE=D0=B4=20=D0=BE=D1=82=D0=B4?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BD=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bubble | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 bubble diff --git a/bubble b/bubble deleted file mode 100644 index 2e4a957..0000000 --- a/bubble +++ /dev/null @@ -1,12 +0,0 @@ -from random import randint - -## массив с рандомными цифрами -checklist = [randint(1, 1000) for i in range(15)] -print(*checklist) -for index_1 in range(len(checklist) - 1): - for index_2 in range(index_1 + 1, len(checklist)): - - ## сравнение и перестановка - if checklist[index_1] > checklist[index_2]: - checklist[index_1], checklist[index_2] = checklist[index_2], checklist[index_1] -print(*checklist) From 349942120b2464dec1184dc2fc675a95f7e27078 Mon Sep 17 00:00:00 2001 From: Andrew-Kochanov Date: Thu, 9 Oct 2025 23:59:09 +0300 Subject: [PATCH 4/4] =?UTF-8?q?=D0=A0=D0=B0=D0=B7=D0=BD=D1=8B=D0=B5=20?= =?UTF-8?q?=D0=B2=D0=B8=D0=B4=20=D1=80=D0=B5=D1=88=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- queens.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 queens.py diff --git a/queens.py b/queens.py new file mode 100644 index 0000000..47f1010 --- /dev/null +++ b/queens.py @@ -0,0 +1,45 @@ +# import itertools + +# def is_valid(positions): +# for i in range(len(positions)): +# for j in range(i + 1, len(positions)): +# if abs(positions[i] - positions[j]) == j - i: +# return False +# return True + +# def count_n_queens_bf(N): +# count = 0 +# for perm in itertools.permutations(range(N)): +# if is_valid(perm): +# count += 1 +# return count +#N = 4 # пример для N=8 +#print(count_n_queens_bf(N)) + + + + +def is_safe(queens, row, col): + for r, c in enumerate(queens): + if c == col or abs(r - row) == abs(c - col): + return False + return True + +def backtrack(row, queens, N): + if row == N: + return 1 + count = 0 + for col in range(N): + if is_safe(queens, row, col): + count += backtrack(row + 1, queens + [col], N) + return count + +def count_n_queens_bt(N): + return backtrack(0, [], N) + +N = 4 +print(count_n_queens_bt(N)) + + +N = 4 +print(count_n_queens_bit(N)) \ No newline at end of file