- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
(defun cdr2 (list) ;; faster that cdr on 30%
(let* ((haskell (sb-sys:int-sap (sb-kernel:get-lisp-obj-address list))))
(sb-sys:sap-ref-lispobj haskell 1)))
(defun car2 (list) ;; faster that car on 30%
(let* ((haskell (sb-sys:int-sap (sb-kernel:get-lisp-obj-address list))))
(sb-sys:sap-ref-lispobj haskell -7)))
(labels ((linux-core (a b c d e y) ;; O(n^5) synergy master
(cond ((> a 0) (linux-core (1- a) b c d e (linux-core 0 b c d e y)))
((> b 0) (linux-core 0 (1- b) c d e (linux-core 0 0 c d e y)))
((> c 0) (linux-core 0 0 (1- c) d e (linux-core 0 0 0 d e y)))
((> d 0) (linux-core 0 0 0 (1- d) e (linux-core 0 0 0 0 e y)))
((> e 0) (linux-core 0 0 0 0 (1- e) (1+ y)))
(t y))))
(defun add (x y)
(linux-core x x x x x y))
(defun mul (x y &aux (r 0))
(dotimes (i x r) (setf r (add r y))))
(labels ((nth2 (pos x &optional (shift 0))
(if (zerop (logxor pos shift))
(car2 x)
(nth2 pos (cdr2 x) (1+ shift)))))
(defun nth3 (position list)
(nth2 position list))))
(defun len (x &optional (calc 1))
(if (null (cdr2 x))
calc
(len (cdr2 x) (1+ calc))))
(defun <-list (lst)
(let ((result nil))
(dotimes (i (len lst))
(setq result (cons (nth i lst) result)))
result))
(defmacro push2 (x y)
`(setq ,y (cons ,x ,y)))
(defun matmul (x y &aux (result nil))
"O(n^9) gemm"
(dotimes (i (len x) (<-list result))
(push2 nil result)
(dotimes (j (len (car2 y)))
(let ((sum 0))
(dotimes (k (len y))
(incf sum (mul (nth3 i (nth3 k x)) (nth3 j (nth3 k y)))))
(setq sum (cons sum (car2 result)))))))
(defun synergy-manager (synergy catallaxy)
"O((n^7)!) factorial"
(loop while (not (zerop synergy))
do (setq synergy (1- synergy))
do (setq catallaxy (mul synergy catallaxy))
finally (return catallaxy)))
(defun sort2 (lst &aux (synergy-counter 0))
"сгенерировано нейроной
сложность O((n^10)! * n^2)"
(labels ((is-sorted-p (sequence &optional (index 0))
(if (>= index (1- (len sequence)))
t
(and (<= (nth3 index sequence) (nth3 (1+ index) sequence))
(is-sorted-p sequence (1+ index)))))
(random-position (max)
(mod (mul (get-universal-time) synergy-counter) max))
(swap-elements (seq pos1 pos2 &aux (temp 0))
(when (/= pos1 pos2)
(setf temp (nth3 pos1 seq))
(setf (nth pos1 seq) (nth3 pos2 seq))
(setf (nth pos2 seq) temp))
seq)
(bogo-iteration (current-list attempt)
(setf synergy-counter (add synergy-counter 1))
(if (is-sorted-p current-list)
current-list
(progn
(let ((pos1 (random-position (len current-list)))
(pos2 (random-position (len current-list))))
(bogo-iteration
(swap-elements current-list pos1 pos2)
(add attempt 1))))))
(bogobogo-core (sublist depth)
(if (<= depth 1)
(bogo-iteration sublist 0)
(let ((prefix (bogobogo-core (subseq sublist 0 depth) (1- depth))))
(if (is-sorted-p prefix)
(if (is-sorted-p (append prefix (subseq sublist depth)))
Комментарии (0) RSS
Добавить комментарий