This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun spiral-matrix (mat n &optional (x 0) (y 0) (k 1) (dx 1) (dy 0) (defval 0)) | |
;; Рекурсивная функция для создания спиральной квадратной матрицы (по часовой стрелке) | |
;; mat - массив n*n заполненый изчально defval | |
;; никаких проверок нет, если mat или n кривые будет ошибка | |
(if (<= k (* n n)) | |
(progn | |
(setf (aref mat y x) k) | |
(let ((x1 (+ x dx)) (y1 (+ y dy))) | |
(if (and | |
(>= x1 0) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defvar *n* (read)) | |
(defvar *counter* 0) | |
(do () ((= *n* 1) *n*) | |
(setf *counter* (1+ *counter*)) | |
(format t "~d->~d~%" | |
*n* | |
(if (= (mod *n* 2) 0) | |
(let ((n1 (/ *n* 2))) (setf *n* n1) n1) | |
(let ((n1 (1+ (* *n* 3)))) (setf *n* n1) n1)))) | |
(format t "Loops in ~d steps~%" *counter*) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun div(n d) | |
(multiple-value-bind (q r) (floor n d) q)) | |
(defun per(n) | |
(if (= n (rem n 10)) | |
(format t "~d~%" n) | |
(progn | |
(format t "~d->" n) | |
(setq mul 1) | |
(loop while (> n 0) do |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun factorize(n) | |
(setq facts '() d 2) | |
(loop while (<= (* d d) n) do | |
(loop while (= 0 (rem n d)) do | |
(setq n (/ n d)) | |
(setq facts (push d facts))) | |
(setq d (1+ d))) | |
(when (/= n 1) | |
(setq facts (push n facts))) | |
facts) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(loop for i from 1 to 10 do | |
(mapcar (lambda (x) (format t "~d x ~d = ~d~%" i x (* x i))) | |
'(1 2 3 4 5 6 7 8 9 10)) | |
(terpri))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Задача: есть массив целых чисел. В нем необходимо определить подмножество с максимальным модулем суммы чисел входящих в него. | |
Входные данные: arr - массив целых чисел, размер массива от 1 до 10^4. | |
Вывод: подмножество чисел исходного массива, ктр образуют множество с максмимальным модулем суммы. Если есть несколько множеств с одинаковым модулем суммы, то выводите любое. | |
Пример: [-1, 2, -1, 3, -4] | |
Answer: { -1, -1, -4 } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Задача: дано натуральное число N. Необходимо найти наименьшее натуральное число, в ктр произведение его цифр было бы равно N. Если такого числа не существует, вывести -1. | |
Входные данные: N - натуральное число от 1 до 10^9. | |
Вывод: наименьшее натуральное число, произведение цифр ктр было бы равно N. -1 - если такого числа нет. | |
Пример: | |
N = 11; Answer = -1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Задача: даны два числа K, N. Необходимо вычислить арифметическое выражение вида: | |
K * 2^N, используя только битовые операции. | |
Входные данные: K, N - натуральные числа, где K от 1 до 10^3, N от 1 до 20 | |
Вывод: результат выражения K * 2^N | |
Пример: K = 3, N = 4 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Задача: даны два натуральных числа a, b. Необходимо найти сумму чисел на интервале [a, b] (включая концы интервала). | |
Входные данные: a, b, где a <= b. a, b от 1 до 10^9. | |
Вывод: sum - сумма чисел на интервале [a, b]. | |
Пример: a = 1, b = 3 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def reverse_array(array: list, start, stop): | |
tmp = array[start:stop] | |
array[start:stop] = reversed(tmp) | |
return array | |
def circular_array_shift(array: list, shift: int): | |
if array and shift: | |
length = len(array) | |
shift %= length | |
array = reverse_array(array, 0, length) |